From 3629a8312c7ba1773d34803f81562a3c74fed19f Mon Sep 17 00:00:00 2001 From: tzw Date: Mon, 23 Sep 2024 18:36:23 +0630 Subject: [PATCH] update carton form and add recent search --- assets/local/localization_en.json | 17 ++-- assets/local/localization_mu.json | 15 ++-- lib/constants.dart | 8 +- lib/helpers/shared_pref.dart | 20 +++++ lib/pages/carton/cargo_widget.dart | 9 +- lib/pages/carton/carton_filter.dart | 48 +++++----- lib/pages/carton/carton_size_widget.dart | 87 ++++++++++++++++--- lib/pages/carton/carton_submit.dart | 41 ++++++--- lib/pages/carton/custom_duty_addition.dart | 4 - .../carton/mix_carton/mix_carton_submit.dart | 12 ++- .../carton/package_selection_widget.dart | 1 + .../delivery_address_editor.dart | 34 ++++---- .../model/fcs_shipment_model.dart | 2 +- lib/pages/package/model/package_model.dart | 7 +- lib/pages/user_search/user_search.dart | 30 +++++-- lib/pages/widgets/suggest_list.dart | 53 +++++++++++ 16 files changed, 292 insertions(+), 96 deletions(-) create mode 100644 lib/pages/widgets/suggest_list.dart diff --git a/assets/local/localization_en.json b/assets/local/localization_en.json index 26d698e..b498881 100644 --- a/assets/local/localization_en.json +++ b/assets/local/localization_en.json @@ -7,7 +7,6 @@ "Buttons Start ================================================================":"", "btn.save": "Save", "btn.approve":"Approve", - "btn.delete":"Delete", "btn.select":"Select", "btn.cancel":"Cancel", "btn.ok": "Ok", @@ -248,7 +247,7 @@ "pm.add.btn":"Add payment method", "pm.save.btn":"Save payment method", "pm.delete.confirm":"Delete this payment method?", - "pm_.title": "PAYMENT", + "pm_.title": "Payment", "pm.date": "Date", "pm.amount": "Amount", "pm.receipt":"Payment receipt amount", @@ -329,15 +328,15 @@ "box.weight":"Weight", "box.mix_carton.update.btn":"Update mix carton", "box.cargo.select.btn":"Select", - "box.select.carton_type":"Select carton type", - "box.select.sender_and_consignee":"Select sender and consignee", + "box.select.carton_type":"Carton type", + "box.select.sender_and_consignee":"Sender and Consignee", "box.cartion.count":"Cartons ({0})", "box.sender.title":"Sender", "box.consignee.title":"Consignee", "box.bill_to_sender":"Bill to sender", "box.bill_to.consignee":"Bill to consignee", "box.done.btn":"Done", - "box.select_carton_size":"Select the carton size", + "box.select_carton_size":"Carton size", "box.select_shipment":"Select the shipment", "box.shipment":"Shipment", "box.standard_carton_size":"Standard carton size", @@ -347,11 +346,11 @@ "box.no_carton":"There is no cartons in this shipment.", "box.crete.carton":"Create carton", "box.carton.type":"Carton type", - "box.select.delivery":"Select delivery type", + "box.select.delivery":"Last mile", "box.select.package":"Select packages", "box.no_package":"There is no packages.", - "box.input_cargo_weight":"Input cargo weight (lb)", - "box.input_surcharge_item":"Input surcharge items", + "box.input_cargo_weight":"Cargo type (lb)", + "box.input_surcharge_item":"Surcharge items", "box.select.cargo_type":"Select surcharge item", "box.surcharge.item":"Surcharge items", "box.package.count":"Packages ({0})", @@ -369,6 +368,8 @@ "box.invoice.confirm":"Confirm invoice?", "box.print.qr.title":"Print QRCode", "box.print.btn":"Print", + "box.delivery":"Delivery", + "box.pickup":"Pick-up", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", diff --git a/assets/local/localization_mu.json b/assets/local/localization_mu.json index f2ce5d6..03dc58f 100644 --- a/assets/local/localization_mu.json +++ b/assets/local/localization_mu.json @@ -6,7 +6,6 @@ "Buttons Start ================================================================":"", "btn.save":"သိမ်းဆည်းရန်", "btn.approve":"အတည်ပြုရန်", - "btn.delete":"ဖျက်ရန်", "btn.select":"ရွေးချယ်ပါ", "btn.cancel":"မလုပ်နဲ့", "btn.ok": "အိုကေ", @@ -329,15 +328,15 @@ "box.weight":"အလေးချိန်", "box.mix_carton.update.btn":"Update mix carton", "box.cargo.select.btn":"ရွေးချယ်မည်", - "box.select.carton_type":"Select carton type", - "box.select.sender_and_consignee":"Select sender and consignee", + "box.select.carton_type":"Carton type", + "box.select.sender_and_consignee":"Sender and Consignee", "box.cartion.count":"Cartons ({0})", "box.sender.title":"ပေးပို့သူ", "box.consignee.title":"လက်ခံသူ", "box.bill_to_sender":"ပေးပို့သူထံ ငွေတောင်းခံရန်", "box.bill_to.consignee":"လက်ခံသူထံ ငွေတောင်းခံရန်", "box.done.btn":"Done", - "box.select_carton_size":"Select the carton size", + "box.select_carton_size":"Carton size", "box.select_shipment":"Select the shipment", "box.shipment":"Shipment", "box.standard_carton_size":"Standard carton size", @@ -347,11 +346,11 @@ "box.no_carton":"There is no cartons in this shipment.", "box.crete.carton":"Create carton", "box.carton.type":"ပုံး အမျိုးအစား", - "box.select.delivery":"Select delivery type", + "box.select.delivery":"Last mile", "box.select.package":"Select packages", "box.no_package":"There is no packages.", - "box.input_cargo_weight":"Input cargo weight (lb)", - "box.input_surcharge_item":"Input surcharge items", + "box.input_cargo_weight":"Cargo type (lb)", + "box.input_surcharge_item":"Surcharge items", "box.select.cargo_type":"Select surcharge item", "box.surcharge.item":"Surcharge items", "box.package.count":"Packages ({0})", @@ -369,6 +368,8 @@ "box.invoice.confirm":"ပြေစာ အတည်ပြုပါ ?", "box.print.qr.title":"QRCode ပရင့်ထုတ်ရန်", "box.print.btn":"ပရင့်ထုတ်မည်", + "box.delivery":"Delivery", + "box.pickup":"Pick-up", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", diff --git a/lib/constants.dart b/lib/constants.dart index 77acf32..276f678 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -89,8 +89,8 @@ const shipment_local_dropoff = "Local drop off"; const shipment_courier_dropoff = "Courier drop off"; //Carton types -const carton_from_packages = "Carton for packages"; -const carton_mix_carton = "Mix carton"; +const carton_from_packages = "For packages"; +const carton_mix_carton = "For cartons (Mix carton)"; const carton_from_cartons = "From cartons"; const carton_from_shipments = "From shipments"; @@ -140,8 +140,8 @@ const payment_confirmed_status = "confirmed"; const payment_canceled_status = "canceled"; //Delivery types -const delivery_caton = "Delivery carton"; -const pickup_carton = "Pick-up carton"; +const delivery_caton = "Delivery"; +const pickup_carton = "Pick-up"; // bill const billToSender = "Bill to sender"; diff --git a/lib/helpers/shared_pref.dart b/lib/helpers/shared_pref.dart index e020232..68d1921 100644 --- a/lib/helpers/shared_pref.dart +++ b/lib/helpers/shared_pref.dart @@ -88,4 +88,24 @@ class SharedPref { final prefs = await SharedPreferences.getInstance(); prefs.remove(key); } + + static Future saveRecentSearch(String key, String query) async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + //Use `Set` to avoid duplication of recentSearches + Set allSearches = prefs.getStringList(key)?.toSet() ?? {}; + + //Place it at first in the set + allSearches = {query, ...allSearches}; + prefs.setStringList(key, allSearches.toList()); + } + + static Future?> getRecentSearch(String key, String query) async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + final allSearches = prefs.getStringList(key); + return allSearches!.where((search) => search.startsWith(query)).toList(); + } + + static Future clearRecentSearch(String key) async { + return await _remove(key); + } } diff --git a/lib/pages/carton/cargo_widget.dart b/lib/pages/carton/cargo_widget.dart index decb010..dde9a67 100644 --- a/lib/pages/carton/cargo_widget.dart +++ b/lib/pages/carton/cargo_widget.dart @@ -151,6 +151,7 @@ class _CargoWidgetState extends State { ); final userRow = Row( + crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded(child: senderBox, flex: 2), Flexible(child: consigneeBox) @@ -265,7 +266,7 @@ class _CargoWidgetState extends State { _surchargeControllers.clear(); _surchareItems.asMap().entries.forEach((e) { var editor = new TextEditingController(); - editor.text = e.value.qty == 0 ? "" : e.value.qty.toString(); + editor.text = e.value.qty.toString(); _surchargeControllers.add(editor); }); @@ -314,6 +315,12 @@ class _CargoWidgetState extends State { final continueBtn = ContinueButton( onTap: () { if (widget.onContinue != null) { + + if(_surchareItems.isNotEmpty && _surchareItems.any((item)=> item.qty == 0)){ + showMsgDialog(context, "Error", "Please insert surcharge item quantity"); + return; + } + widget.onContinue!(_cargoTypes, _surchareItems); } }, diff --git a/lib/pages/carton/carton_filter.dart b/lib/pages/carton/carton_filter.dart index 20ab11a..384454b 100644 --- a/lib/pages/carton/carton_filter.dart +++ b/lib/pages/carton/carton_filter.dart @@ -167,27 +167,33 @@ class _CartonFilterState extends State { final _titleWidget = SizedBox( height: 30, - child: TabBar( - unselectedLabelColor: Colors.grey, - labelColor: primaryColor, - indicatorColor: primaryColor, - indicatorSize: TabBarIndicatorSize.tab, - labelPadding: const EdgeInsets.all(0), - indicatorPadding: const EdgeInsets.all(0), - tabs: [ - Tab( - text: AppTranslations.of(context)?.text("box.fcs_shipment_num"), - ), - Tab( - text: AppTranslations.of(context)?.text("box.consignee.title"), - ), - Tab( - text: AppTranslations.of(context)?.text("box.sender.title"), - ), - Tab( - text: AppTranslations.of(context)?.text("box.status"), - ), - ], + child: Theme( + data: ThemeData( + highlightColor: Colors.transparent, + splashColor: Colors.transparent, + ), + child: TabBar( + unselectedLabelColor: Colors.grey, + labelColor: primaryColor, + indicatorColor: primaryColor, + indicatorSize: TabBarIndicatorSize.tab, + labelPadding: const EdgeInsets.all(0), + indicatorPadding: const EdgeInsets.all(0), + tabs: [ + Tab( + text: AppTranslations.of(context)?.text("box.fcs_shipment_num"), + ), + Tab( + text: AppTranslations.of(context)?.text("box.consignee.title"), + ), + Tab( + text: AppTranslations.of(context)?.text("box.sender.title"), + ), + Tab( + text: AppTranslations.of(context)?.text("box.status"), + ), + ], + ), ), ); diff --git a/lib/pages/carton/carton_size_widget.dart b/lib/pages/carton/carton_size_widget.dart index a1fa3a6..b23a6ab 100644 --- a/lib/pages/carton/carton_size_widget.dart +++ b/lib/pages/carton/carton_size_widget.dart @@ -16,7 +16,6 @@ import '../widgets/box_size_picker.dart'; import '../widgets/continue_button.dart'; import '../widgets/display_text.dart'; import '../widgets/local_dropdown.dart'; -import '../widgets/local_radio_buttons.dart'; import '../widgets/local_text.dart'; import '../widgets/local_title.dart'; import '../widgets/previous_button.dart'; @@ -62,7 +61,7 @@ class CartonSizeWidget extends StatefulWidget { } class _CartonSizeWidgetState extends State { - List _deliveryTypes = [delivery_caton, pickup_carton]; + // List _deliveryTypes = [delivery_caton, pickup_carton]; FcsShipment? _shipment; String _cartonSizeType = standardCarton; @@ -132,7 +131,7 @@ class _CartonSizeWidgetState extends State { text: widget.sender.name, labelTextKey: "box.sender.title", iconData: MaterialCommunityIcons.account_arrow_right, - subText: Text(widget.sender.fcsID!, + subText: Text(widget.sender.fcsID ?? "", style: TextStyle(fontSize: 13, color: labelColor)), ); @@ -145,6 +144,7 @@ class _CartonSizeWidgetState extends State { ); final userRow = Row( + crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( child: senderBox, @@ -154,14 +154,71 @@ class _CartonSizeWidgetState extends State { ], ); - final deliveryTypeBox = LocalRadioButtons( - values: _deliveryTypes, - selectedValue: _selectedDeliveryType, - callback: (String? v) { - setState(() { - _selectedDeliveryType = v!; - }); - }); + final deliveryTypeBox = Container( + child: Row( + children: [ + Flexible( + child: InkWell( + onTap: () { + setState(() { + _selectedDeliveryType = delivery_caton; + }); + }, + child: Row(children: [ + LocalRadio( + value: delivery_caton, + groupValue: _selectedDeliveryType, + onChanged: (p0) { + setState(() { + _selectedDeliveryType = delivery_caton; + }); + }, + ), + Flexible( + child: Padding( + padding: const EdgeInsets.only(left: 10), + child: LocalText(context, 'box.delivery', + fontSize: 15, + color: _selectedDeliveryType == delivery_caton + ? primaryColor + : Colors.black), + ), + ) + ]), + )), + Flexible( + child: InkWell( + onTap: () { + setState(() { + _selectedDeliveryType = pickup_carton; + }); + }, + child: Row(children: [ + LocalRadio( + value: pickup_carton, + groupValue: _selectedDeliveryType, + onChanged: (p0) { + setState(() { + _selectedDeliveryType = pickup_carton; + }); + }, + ), + Flexible( + child: Padding( + padding: const EdgeInsets.only(left: 10), + child: LocalText(context, 'box.pickup', + fontSize: 15, + color: _selectedDeliveryType == pickup_carton + ? primaryColor + : Colors.black), + ), + ) + ]), + ), + ) + ], + ), + ); final billRadioBox = Container( child: Row( @@ -186,7 +243,7 @@ class _CartonSizeWidgetState extends State { Flexible( child: Padding( padding: const EdgeInsets.only(left: 10), - child: LocalText(context, 'box.bill_to_sender', + child: LocalText(context, 'box.sender.title', fontSize: 15, color: _billToValue == billToSender ? primaryColor @@ -215,7 +272,7 @@ class _CartonSizeWidgetState extends State { Flexible( child: Padding( padding: const EdgeInsets.only(left: 10), - child: LocalText(context, 'box.bill_to.consignee', + child: LocalText(context, 'box.consignee.title', fontSize: 15, color: _billToValue == billToConsignee ? primaryColor @@ -465,12 +522,14 @@ class _CartonSizeWidgetState extends State { children: [ const SizedBox(height: 8), userRow, + LocalTitle(textKey: "box.bill_to", topPadding: 8), const SizedBox(height: 5), billRadioBox, + const SizedBox(height: 8), LocalTitle(textKey: "box.select.delivery"), const SizedBox(height: 5), deliveryTypeBox, - const SizedBox(height: 5), + const SizedBox(height: 8), LocalTitle(textKey: "box.select_carton_size"), const SizedBox(height: 8), cartonSizedBox, diff --git a/lib/pages/carton/carton_submit.dart b/lib/pages/carton/carton_submit.dart index f097dce..4224821 100644 --- a/lib/pages/carton/carton_submit.dart +++ b/lib/pages/carton/carton_submit.dart @@ -71,7 +71,8 @@ class CartonSubmit extends StatelessWidget { child: SubmitTextWidget( labelKey: 'box.carton.type', text: carton_from_packages, - subText: boxDimension), + // subText: boxDimension + ), ); final shipmentBox = Padding( @@ -135,9 +136,9 @@ class CartonSubmit extends StatelessWidget { ], ), ), - billToValue == billToSender - ? billWidget(context) - : const SizedBox() + // billToValue == billToSender + // ? billWidget(context) + // : const SizedBox() ], ), ), @@ -162,9 +163,9 @@ class CartonSubmit extends StatelessWidget { ], ), ), - billToValue == billToConsignee - ? billWidget(context) - : const SizedBox() + // billToValue == billToConsignee + // ? billWidget(context) + // : const SizedBox() ], ), )) @@ -174,14 +175,30 @@ class CartonSubmit extends StatelessWidget { ]), ); + final billToBox = Padding( + padding: const EdgeInsets.only(top: 10), + child: SubmitTextWidget( + labelKey: 'box.bill_to', + text: billToValue == billToSender ? 'Sender' : 'Consignee', + ), + ); + final deliveryTypeBox = Padding( padding: const EdgeInsets.only(top: 10), child: SubmitTextWidget( - labelKey: 'box.delivery_type', + labelKey: 'box.select.delivery', text: deliveryType, ), ); + final cartonSizeBox = Padding( + padding: const EdgeInsets.only(top: 10), + child: SubmitTextWidget( + labelKey: 'box.carton_size', + text: boxDimension??'', + ), + ); + final packagesBox = Padding( padding: const EdgeInsets.only(top: 10), child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [ @@ -341,12 +358,16 @@ class CartonSubmit extends StatelessWidget { children: [ cartonType, const SizedBox(height: 10), - shipmentBox, - const SizedBox(height: 10), usersBox, const SizedBox(height: 10), + billToBox, + const SizedBox(height: 10), deliveryTypeBox, const SizedBox(height: 10), + cartonSizeBox, + const SizedBox(height: 10), + shipmentBox, + const SizedBox(height: 10), packages.isNotEmpty ? packagesBox : const SizedBox(), const SizedBox(height: 10), cargosBox, diff --git a/lib/pages/carton/custom_duty_addition.dart b/lib/pages/carton/custom_duty_addition.dart index cb07ac6..d096b60 100644 --- a/lib/pages/carton/custom_duty_addition.dart +++ b/lib/pages/carton/custom_duty_addition.dart @@ -3,7 +3,6 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/widgets/local_app_bar.dart'; -import 'package:fcs/pages/widgets/local_title.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -117,9 +116,6 @@ class _CustomDutyAdditionState extends State { child: ListView( shrinkWrap: true, children: [ - LocalTitle( - textKey: "box.select.cargo.title", - ), Column( children: getCargoRowList(customDuties), ), diff --git a/lib/pages/carton/mix_carton/mix_carton_submit.dart b/lib/pages/carton/mix_carton/mix_carton_submit.dart index 8bea898..85a8fca 100644 --- a/lib/pages/carton/mix_carton/mix_carton_submit.dart +++ b/lib/pages/carton/mix_carton/mix_carton_submit.dart @@ -112,7 +112,15 @@ class _MixCartonSubmitState extends State { child: SubmitTextWidget( labelKey: 'box.carton.type', text: carton_mix_carton, - subText: boxDimension, + // subText: boxDimension, + ), + ); + + final cartonSizeBox = Padding( + padding: const EdgeInsets.only(top: 10), + child: SubmitTextWidget( + labelKey: 'box.carton_size', + text: boxDimension ?? '', ), ); @@ -284,6 +292,8 @@ class _MixCartonSubmitState extends State { children: [ cartonType, const SizedBox(height: 10), + cartonSizeBox, + const SizedBox(height: 10), shipmentBox, const SizedBox(height: 10), widget.cartons.isNotEmpty ? cartonsBox : const SizedBox(), diff --git a/lib/pages/carton/package_selection_widget.dart b/lib/pages/carton/package_selection_widget.dart index 435ec3d..4b3a3d7 100644 --- a/lib/pages/carton/package_selection_widget.dart +++ b/lib/pages/carton/package_selection_widget.dart @@ -126,6 +126,7 @@ class _PackageSelectionWidgetState extends State { ); final userRow = Row( + crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( child: senderBox, diff --git a/lib/pages/delivery_address/delivery_address_editor.dart b/lib/pages/delivery_address/delivery_address_editor.dart index 85a6d0a..147242f 100644 --- a/lib/pages/delivery_address/delivery_address_editor.dart +++ b/lib/pages/delivery_address/delivery_address_editor.dart @@ -31,7 +31,7 @@ class _DeliveryAddressEditorState extends State { bool _isLoading = false; bool _isNew = true; - final _deliveryFormKey=GlobalKey(); + final _deliveryFormKey = GlobalKey(); @override void initState() { @@ -64,8 +64,8 @@ class _DeliveryAddressEditorState extends State { controller: _nameController, autovalidateMode: AutovalidateMode.onUserInteraction, validator: (value) { - if(value==null || value.isEmpty){ - return"Please enter full name"; + if (value == null || value.isEmpty) { + return "Please enter full name"; } return null; }); @@ -74,10 +74,10 @@ class _DeliveryAddressEditorState extends State { labelTextKey: 'delivery_address.address_line1', iconData: Icons.location_on, controller: _address1Controller, - autovalidateMode: AutovalidateMode.onUserInteraction, + autovalidateMode: AutovalidateMode.onUserInteraction, validator: (value) { - if(value==null || value.isEmpty){ - return"Please enter address"; + if (value == null || value.isEmpty) { + return "Please enter address"; } return null; }); @@ -91,10 +91,10 @@ class _DeliveryAddressEditorState extends State { labelTextKey: 'delivery_address.city', iconData: Icons.location_city, controller: _cityController, - autovalidateMode: AutovalidateMode.onUserInteraction, + autovalidateMode: AutovalidateMode.onUserInteraction, validator: (value) { - if(value==null || value.isEmpty){ - return"Please enter city"; + if (value == null || value.isEmpty) { + return "Please enter city"; } return null; }); @@ -103,10 +103,10 @@ class _DeliveryAddressEditorState extends State { labelTextKey: 'delivery_address.state_region', iconData: Entypo.location, controller: _stateController, - autovalidateMode: AutovalidateMode.onUserInteraction, + autovalidateMode: AutovalidateMode.onUserInteraction, validator: (value) { - if(value==null || value.isEmpty){ - return"Please enter state/region"; + if (value == null || value.isEmpty) { + return "Please enter state/region"; } return null; }); @@ -116,10 +116,10 @@ class _DeliveryAddressEditorState extends State { iconData: Icons.phone, textInputType: TextInputType.phone, controller: _phoneController, - autovalidateMode: AutovalidateMode.onUserInteraction, + autovalidateMode: AutovalidateMode.onUserInteraction, validator: (value) { - if(value==null || value.isEmpty){ - return"Please enter phone number"; + if (value == null || value.isEmpty) { + return "Please enter phone number"; } return null; }); @@ -207,7 +207,7 @@ class _DeliveryAddressEditorState extends State { } Future _validate(DeliveryAddress deliveryAddress) async { - if(_deliveryFormKey.currentState!.validate()){ + if (!_deliveryFormKey.currentState!.validate()) { return false; } // if (deliveryAddress.addressLine1 == "") { @@ -236,7 +236,7 @@ class _DeliveryAddressEditorState extends State { if (!valid) { return; } - + if (widget.user != null) { deliveryAddress.userID = widget.user!.id; } diff --git a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart index 14e51f2..fe0c4b7 100644 --- a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart +++ b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart @@ -87,7 +87,7 @@ class FcsShipmentModel extends BaseModel { try { var snaps = await FirebaseFirestore.instance .collection("/$fcs_shipment_collection") - .where("status", isEqualTo: fcs_shipment_processed_status) + // .where("status", isEqualTo: fcs_shipment_processed_status) .get(const GetOptions(source: Source.server)); fcsShipments = snaps.docs.map((documentSnapshot) { var fcs = diff --git a/lib/pages/package/model/package_model.dart b/lib/pages/package/model/package_model.dart index 39d4835..92cefeb 100644 --- a/lib/pages/package/model/package_model.dart +++ b/lib/pages/package/model/package_model.dart @@ -13,6 +13,8 @@ import 'package:fcs/pagination/paginator_listener.dart'; import 'package:logging/logging.dart'; import 'package:path/path.dart' as Path; +import '../../../helpers/shared_pref.dart'; + class PackageModel extends BaseModel { final log = Logger('PackageModel'); @@ -214,7 +216,10 @@ class PackageModel extends BaseModel { return packages; } - Future> searchUser(String term) { + Future> searchUser(String term) async { + if (term != '') { + await SharedPref.saveRecentSearch('account_search', term); + } return Services.instance.userService.searchUser(term); } diff --git a/lib/pages/user_search/user_search.dart b/lib/pages/user_search/user_search.dart index df94112..76dff2b 100644 --- a/lib/pages/user_search/user_search.dart +++ b/lib/pages/user_search/user_search.dart @@ -7,6 +7,8 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../../data/services/services.dart'; +import '../../helpers/shared_pref.dart'; +import '../widgets/suggest_list.dart'; typedef OnUserSelect(User suer); typedef OnUserRowSelect(User suer); @@ -79,7 +81,7 @@ class UserSearchDelegate extends SearchDelegate { child: Text( "No result found", textAlign: TextAlign.center, - style: TextStyle(color:Colors.black), + style: TextStyle(color: Colors.black), ), ), ); @@ -118,12 +120,26 @@ class UserSearchDelegate extends SearchDelegate { @override Widget buildSuggestions(BuildContext context) { - return Container( - child: Center( - child: Opacity( - opacity: 0.2, - child: Icon(Icons.perm_identity, size: 200, color: primaryColor)), - ), + return FutureBuilder?>( + future: SharedPref.getRecentSearch('account_search', query), + builder: (context, snapshot) { + List _oldFilters = snapshot.data ?? []; + if (_oldFilters.isEmpty) { + return const Center( + child: Opacity( + opacity: 0.2, + child: Icon(Icons.perm_identity, color: primaryColor, size: 200), + ), + ); + } + return SuggestList( + recentSearchList: _oldFilters, + onTap: (String s) { + query = s; + showResults(context); + }, + prefKey: 'account_search'); + }, ); } diff --git a/lib/pages/widgets/suggest_list.dart b/lib/pages/widgets/suggest_list.dart new file mode 100644 index 0000000..421a19e --- /dev/null +++ b/lib/pages/widgets/suggest_list.dart @@ -0,0 +1,53 @@ +import 'package:flutter/material.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +import '../../helpers/theme.dart'; + +typedef OnTap = Function(String query); + +class SuggestList extends StatefulWidget { + final List? recentSearchList; + final String prefKey; + final OnTap? onTap; + const SuggestList( + {Key? key, this.recentSearchList, this.onTap, required this.prefKey}) + : super(key: key); + + @override + _SuggestListState createState() => _SuggestListState(); +} + +class _SuggestListState extends State { + @override + Widget build(BuildContext context) { + return ListView.builder( + itemCount: widget.recentSearchList?.length, + itemBuilder: (context, index) { + return ListTile( + leading: const Icon(Icons.restore, color: labelColor), + title: Text( + widget.recentSearchList?[index] ?? '', + style: const TextStyle(color: primaryColor), + ), + onTap: () { + if (widget.onTap != null) { + widget.onTap!(widget.recentSearchList![index]); + } + }, + trailing: IconButton( + icon: const Icon(Icons.close, color: labelColor), + onPressed: () async { + setState(() { + widget.recentSearchList + ?.remove(widget.recentSearchList?[index]); + }); + final prefs = await SharedPreferences.getInstance(); + prefs.setStringList(widget.prefKey, widget.recentSearchList!); + setState(() {}); + }, + ), + ); + }, + ); + } +}