From 8a06e69630ab835f5420245a1e6b670fa9b2ab0f Mon Sep 17 00:00:00 2001 From: Fransolet Thomas Date: Fri, 9 Sep 2022 17:29:24 +0200 Subject: [PATCH] Search article --- .flutter-plugins-dependencies | 2 +- lib/Components/LanguageSelection.dart | 6 +- lib/Components/SearchBox.dart | 33 ++++++++--- lib/Screens/Visit/components/body.dart | 57 ++++++++++++------- .../Visit/components/section_card.dart | 27 ++++----- lib/Screens/Visit/visit.dart | 2 +- lib/constants.dart | 4 ++ 7 files changed, 83 insertions(+), 48 deletions(-) diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index a25e17c..efca82f 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"qr_code_scanner","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\qr_code_scanner-1.0.0\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.3+1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"qr_code_scanner","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\qr_code_scanner-1.0.0\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.3+1\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.3+1\\\\","native_build":true,"dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"qr_code_scanner","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2022-09-08 17:31:19.765627","version":"3.0.3"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"qr_code_scanner","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\qr_code_scanner-1.0.0\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.3+1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"qr_code_scanner","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\qr_code_scanner-1.0.0\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.3+1\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.3+1\\\\","native_build":true,"dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"qr_code_scanner","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2022-09-09 17:24:19.203221","version":"3.0.3"} \ No newline at end of file diff --git a/lib/Components/LanguageSelection.dart b/lib/Components/LanguageSelection.dart index a711fde..4ed5217 100644 --- a/lib/Components/LanguageSelection.dart +++ b/lib/Components/LanguageSelection.dart @@ -25,15 +25,15 @@ class _LanguageSelection extends State with TickerProviderSta final appContext = Provider.of(context); Size size = MediaQuery.of(context).size; var configurationLanguages = (appContext.getContext() as VisitAppContext).configuration?.languages; - print(configurationLanguages); + //print(configurationLanguages); languagesEnable = configurationLanguages ?? languages; selectedLanguage = (appContext.getContext() as VisitAppContext).language; if(!languagesEnable!.any((lg) => lg == selectedLanguage)) { - print("selectedLanguage not supported"); + //print("selectedLanguage not supported"); selectedLanguage = defaultLanguage; } - print(selectedLanguage); + //print(selectedLanguage); return PopupMenuButton( icon: Container( diff --git a/lib/Components/SearchBox.dart b/lib/Components/SearchBox.dart index 8632ddd..e5ce61e 100644 --- a/lib/Components/SearchBox.dart +++ b/lib/Components/SearchBox.dart @@ -1,9 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:flutter_svg/flutter_svg.dart'; - import '../constants.dart'; -class SearchBox extends StatelessWidget { +class SearchBox extends StatefulWidget { const SearchBox({ Key? key, this.onChanged, @@ -11,11 +9,18 @@ class SearchBox extends StatelessWidget { final ValueChanged? onChanged; + @override + State createState() => _SearchBoxState(); +} + +class _SearchBoxState extends State { + TextEditingController _controller = new TextEditingController(); + @override Widget build(BuildContext context) { return Container( - margin: EdgeInsets.all(kDefaultPadding), - padding: EdgeInsets.symmetric( + margin: const EdgeInsets.all(kDefaultPadding), + padding: const EdgeInsets.symmetric( horizontal: kDefaultPadding, vertical: kDefaultPadding / 4, // 5 top and bottom ), @@ -23,15 +28,25 @@ class SearchBox extends StatelessWidget { color: Colors.white.withOpacity(0.4), borderRadius: BorderRadius.circular(12), ), - child: TextField( - onChanged: onChanged, - style: TextStyle(color: Colors.white), + child: TextFormField( + controller: _controller, + onChanged: widget.onChanged, + style: const TextStyle(color: Colors.white), decoration: InputDecoration( enabledBorder: InputBorder.none, focusedBorder: InputBorder.none, icon: const Icon(Icons.search, color: Colors.white), hintText: 'Search', - hintStyle: TextStyle(color: Colors.white), + hintStyle: const TextStyle(color: Colors.white), + suffixIcon: _controller.value.text.isNotEmpty ? InkWell( + onTap: () { + if(_controller.value.text.isNotEmpty) { + _controller.clear(); + widget.onChanged!(""); + } + }, + child: const Icon(Icons.close, color: Colors.white) + ): const Text(''), ), ), ); diff --git a/lib/Screens/Visit/components/body.dart b/lib/Screens/Visit/components/body.dart index 05c1e01..bdc9b5e 100644 --- a/lib/Screens/Visit/components/body.dart +++ b/lib/Screens/Visit/components/body.dart @@ -3,7 +3,7 @@ import 'package:manager_api/api.dart'; import 'package:mymuseum_visitapp/Components/Loading.dart'; import 'package:mymuseum_visitapp/Components/SearchBox.dart'; import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart'; -import 'package:mymuseum_visitapp/Models/visitContext.dart'; +import 'package:mymuseum_visitapp/Helpers/translationHelper.dart'; import 'package:mymuseum_visitapp/Screens/Visit/details/details_screen.dart'; import 'package:mymuseum_visitapp/Screens/Visit/product.dart'; import 'package:mymuseum_visitapp/app_context.dart'; @@ -23,6 +23,8 @@ class Body extends StatefulWidget { class _BodyState extends State { List sections = []; + List sectionsToDisplay = []; + String? searchValue; @override Widget build(BuildContext context) { @@ -33,14 +35,18 @@ class _BodyState extends State { bottom: false, child: Column( children: [ - SearchBox(onChanged: (value) {}), - const SizedBox(height: kDefaultPadding / 2), + SearchBox(onChanged: (value) { + setState(() { + searchValue = value; + }); + }), + //const SizedBox(height: kDefaultPadding / 2), Expanded( child: Stack( children: [ // Our background Container( - margin: const EdgeInsets.only(top: 70), + margin: const EdgeInsets.only(top: 0), decoration: const BoxDecoration( color: kBackgroundColor, borderRadius: BorderRadius.only( @@ -50,24 +56,27 @@ class _BodyState extends State { ), ), FutureBuilder( - future: getSections(), + future: getSections(appContext), builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { - return ListView.builder( - itemCount: sections.length, - itemBuilder: (context, index) => SectionCard( - itemIndex: index, - sectionDTO: sections[index], - press: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => DetailsScreen( - product: products[index], + return Padding( + padding: const EdgeInsets.only(top: 15), + child: ListView.builder( + itemCount: sectionsToDisplay.length, + itemBuilder: (context, index) => SectionCard( + itemIndex: index, + sectionDTO: sectionsToDisplay[index], + press: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => DetailsScreen( + product: products[index], + ), ), - ), - ); - }, + ); + }, + ), ), ); } else if (snapshot.connectionState == ConnectionState.none) { @@ -90,10 +99,16 @@ class _BodyState extends State { ); } - getSections() async { + getSections(AppContext appContext) async { sections = List.from(await DatabaseHelper.instance.getData(DatabaseTableType.sections)); sections = sections.where((s) => s.configurationId == widget.configurationId).toList(); sections.sort((a,b) => a.order!.compareTo(b.order!)); - print(sections); + sectionsToDisplay = sections; + + if(searchValue != '' && searchValue != null) { + sectionsToDisplay = sections.where((s) => TranslationHelper.get(s!.title, appContext).toLowerCase().contains(searchValue.toString().toLowerCase())).toList(); + } else { + sectionsToDisplay = sections; + } } } diff --git a/lib/Screens/Visit/components/section_card.dart b/lib/Screens/Visit/components/section_card.dart index a8add2d..807f7ba 100644 --- a/lib/Screens/Visit/components/section_card.dart +++ b/lib/Screens/Visit/components/section_card.dart @@ -52,11 +52,11 @@ class SectionCard extends StatelessWidget { height: 136, decoration: BoxDecoration( borderRadius: BorderRadius.circular(22), - color: itemIndex.isEven ? kTestSecondColor : kSecondRed, - boxShadow: [kDefaultShadow], + color: itemIndex.isEven ? kBlue0 : kBlue1, + boxShadow: const [kDefaultShadow], ), child: Container( - margin: EdgeInsets.only(right: 10), + margin: const EdgeInsets.only(right: 10), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(22), @@ -81,14 +81,14 @@ class SectionCard extends StatelessWidget { return resourceModel != null ? Image.memory( base64Decode(resourceModel!.data!), fit: BoxFit.cover - ) : Text(""); + ) : const Text(""); } else if (snapshot.connectionState == ConnectionState.none) { - return Text("No data"); + return const Text("No data"); } else { return Center( - child: Container( + child: SizedBox( height: size.height * 0.15, - child: Loading() + child: const Loading() ) ); } @@ -111,7 +111,7 @@ class SectionCard extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Spacer(), + const Spacer(), Padding( padding: const EdgeInsets.symmetric( horizontal: kDefaultPadding), @@ -121,14 +121,14 @@ class SectionCard extends StatelessWidget { ), ), // it use the available space - Spacer(), + const Spacer(), Container( - padding: EdgeInsets.symmetric( + padding: const EdgeInsets.symmetric( horizontal: kDefaultPadding * 1.5, // 30 padding vertical: kDefaultPadding / 4, // 5 top and bottom ), - decoration: BoxDecoration( - color: kSecondRed, + decoration: const BoxDecoration( + color: kBlue2, borderRadius: BorderRadius.only( bottomLeft: Radius.circular(22), topRight: Radius.circular(22), @@ -136,7 +136,8 @@ class SectionCard extends StatelessWidget { ), child: Text( "${sectionDTO.order!+1}", - style: Theme.of(context).textTheme.button, + //style: Theme.of(context).textTheme.button, + style: TextStyle(color: Colors.white) ), ), ], diff --git a/lib/Screens/Visit/visit.dart b/lib/Screens/Visit/visit.dart index 80d2c39..1a7b204 100644 --- a/lib/Screens/Visit/visit.dart +++ b/lib/Screens/Visit/visit.dart @@ -32,7 +32,7 @@ class _VisitPageState extends State { title: configuration?.label ?? "", isHomeButton: true, ), - backgroundColor: kMainGrey, + backgroundColor: kBackgroundGrey, body: Body(configurationId: configuration!.id), // TODO handle error.. floatingActionButton: const ScannerBouton(isReplacement: false), ); diff --git a/lib/constants.dart b/lib/constants.dart index 6a4fd2a..6412583 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -30,6 +30,10 @@ const kTextRed = Color(0xFFba0505); const kBackgroundGrey = Color(0xFFb5b7b9); const kBackgroundSecondGrey = Color(0xFF5b5b63); +const kBlue0 = Color(0xFF306bac); +const kBlue1 = Color(0xFF308aae); +const kBlue2 = Color(0xFF309cb0); + const kBackgroundLight = Color(0xfff3f3f3); const kTitleSize = 40.0;