From c66734d386c4279f40b1dd7d485c681f7f752058 Mon Sep 17 00:00:00 2001 From: tzw Date: Mon, 4 Mar 2024 09:23:05 +0630 Subject: [PATCH] update carton filter --- lib/domain/constants.dart | 1 + lib/pages/carton/carton_filter.dart | 8 ++-- lib/pages/carton/carton_list.dart | 72 ++++++++++++++++++----------- 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/lib/domain/constants.dart b/lib/domain/constants.dart index 7cbafdf..cc05bbf 100644 --- a/lib/domain/constants.dart +++ b/lib/domain/constants.dart @@ -118,6 +118,7 @@ const carton_invoiced_status = "invoiced"; const carton_canceled_status = "canceled"; const all_status = "All stauts"; const all = "All"; +const see_all ="See All"; // shipment status const shipment_pending_status = "pending"; diff --git a/lib/pages/carton/carton_filter.dart b/lib/pages/carton/carton_filter.dart index 48a0af6..8396502 100644 --- a/lib/pages/carton/carton_filter.dart +++ b/lib/pages/carton/carton_filter.dart @@ -486,11 +486,9 @@ class _CartonFilterState extends State { } _clearFilter() async { - await context.read().filterCarton( - FcsShipment(shipmentNumber: "All shipments", id: all), - User(id: all, name: "All"), - User(id: all, name: "All"), - all_status); + var model = context.read(); + await model.filterCarton(model.defaultShipment, User(id: all, name: "All"), + User(id: all, name: "All"), all_status); Navigator.pop(context, true); } diff --git a/lib/pages/carton/carton_list.dart b/lib/pages/carton/carton_list.dart index 6cd36b0..c20ce40 100644 --- a/lib/pages/carton/carton_list.dart +++ b/lib/pages/carton/carton_list.dart @@ -8,6 +8,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; +import '../../domain/constants.dart'; import '../../domain/entities/carton.dart'; import '../../pagination/paginator_listview.dart'; import '../carton_search/carton_search.dart'; @@ -38,6 +39,11 @@ class _CartonListState extends State { var model = context.read(); _shipments = await context.read().getShipments(); _shipments.insert(0, model.defaultShipment); + if (_shipments.length > shipmentCountForCartonFilter) { + _shipments.insert(_shipments.length, + FcsShipment(shipmentNumber: "See All", id: see_all)); + } + _selectedShipment = model.shipment ?? model.defaultShipment; model.loadPaginationCartons(); @@ -66,18 +72,22 @@ class _CartonListState extends State { child: ActionChip( shape: StadiumBorder( side: BorderSide( - color: _selectedShipment?.id == g.id - ? primaryColor - : Colors.grey.shade300)), + color: g.id == see_all + ? Colors.transparent + : _selectedShipment?.id == g.id + ? primaryColor + : Colors.grey.shade300)), padding: const EdgeInsets.all(8), onPressed: () { _filterShipment(g); }, label: Text(g.shipmentNumber ?? "", style: TextStyle( - color: _selectedShipment?.id == g.id + color: g.id == see_all ? primaryColor - : labelColor, + : _selectedShipment?.id == g.id + ? primaryColor + : labelColor, fontWeight: FontWeight.normal, fontSize: 14, fontFamily: "Poppins")), @@ -289,7 +299,8 @@ class _CartonListState extends State { ), model.filterByStatus != null || model.filterBySender != null || - model.filterByConsingee != null + model.filterByConsingee != null || + model.shipment != null ? Positioned( bottom: 15, right: 0, @@ -305,31 +316,38 @@ class _CartonListState extends State { : Container() ], ), - onPressed: () async { - bool? updated = await showModalBottomSheet( - context: context, - useRootNavigator: true, - isScrollControlled: true, - useSafeArea: true, - shape: const RoundedRectangleBorder( - borderRadius: - BorderRadius.vertical(top: Radius.circular(10))), - builder: (ctx) => DraggableScrollableSheet( - initialChildSize: 0.6, - minChildSize: 0.6, - expand: false, - builder: (_, controller) => - CartonFilter(controller: controller))); - var model = context.read(); - if (updated ?? false) { - setState(() { - _selectedShipment = model.shipment ?? model.defaultShipment; - }); - } + onPressed: () { + _showFilter(); }); } + _showFilter() async { + bool? updated = await showModalBottomSheet( + context: context, + useRootNavigator: true, + isScrollControlled: true, + useSafeArea: true, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.vertical(top: Radius.circular(10))), + builder: (ctx) => DraggableScrollableSheet( + initialChildSize: 0.6, + minChildSize: 0.6, + expand: false, + builder: (_, controller) => CartonFilter(controller: controller))); + var model = context.read(); + if (updated ?? false) { + setState(() { + _selectedShipment = model.shipment ?? model.defaultShipment; + }); + } + } + _filterShipment(FcsShipment shipment) async { + if (shipment.id == see_all) { + _showFilter(); + return; + } + setState(() { _selectedShipment = shipment; });