add cartion filter and search
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
import 'package:fcs/domain/entities/fcs_shipment.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/carton/model/carton_model.dart';
|
||||
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
||||
import 'package:fcs/pages/widgets/local_popup_menu_button.dart';
|
||||
import 'package:fcs/pages/widgets/local_popupmenu.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
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';
|
||||
import '../fcs_shipment/model/fcs_shipment_model.dart';
|
||||
import 'carton_editor.dart';
|
||||
import 'carton_filter.dart';
|
||||
import 'carton_info.dart';
|
||||
import 'carton_list_row.dart';
|
||||
|
||||
class CartonList extends StatefulWidget {
|
||||
@@ -21,7 +26,8 @@ class CartonList extends StatefulWidget {
|
||||
|
||||
class _CartonListState extends State<CartonList> {
|
||||
bool _isLoading = false;
|
||||
int _selectedIndex = 1;
|
||||
List<FcsShipment> _shipments = [];
|
||||
FcsShipment? _selectedShipment;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -29,10 +35,14 @@ class _CartonListState extends State<CartonList> {
|
||||
_init();
|
||||
}
|
||||
|
||||
_init() {
|
||||
_init() async {
|
||||
var model = context.read<CartonModel>();
|
||||
_selectedIndex = model.selectedIndex;
|
||||
model.loadPaginationBoxes(_selectedIndex);
|
||||
_shipments = await context.read<FcsShipmentModel>().getAllShipments();
|
||||
_shipments.insert(0, FcsShipment(shipmentNumber: "All Shipments", id: all));
|
||||
_selectedShipment =
|
||||
model.shipment ?? FcsShipment(shipmentNumber: "All Shipments", id: all);
|
||||
model.loadPaginationCartons();
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
@@ -40,29 +50,66 @@ class _CartonListState extends State<CartonList> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var boxModel = Provider.of<CartonModel>(context);
|
||||
var cartonModel = Provider.of<CartonModel>(context);
|
||||
|
||||
final shipmentFilterBox = Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(left: 15, right: 15),
|
||||
scrollDirection: Axis.horizontal,
|
||||
physics: const BouncingScrollPhysics(),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: _shipments.map((g) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(5.0),
|
||||
child: ActionChip(
|
||||
shape: StadiumBorder(
|
||||
side: BorderSide(
|
||||
color: _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
|
||||
? primaryColor
|
||||
: labelColor,
|
||||
fontWeight: FontWeight.normal,
|
||||
fontSize: 14,
|
||||
fontFamily: "Poppins")),
|
||||
),
|
||||
);
|
||||
}).toList()),
|
||||
),
|
||||
);
|
||||
|
||||
final popupMenu = LocalPopupMenuButton(
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
id: 1,
|
||||
textKey: "box.popupmenu.active",
|
||||
selected: boxModel.selectedIndex == 1),
|
||||
LocalPopupMenu(
|
||||
id: 2,
|
||||
textKey: "box.popupmenu.delivered",
|
||||
selected: boxModel.selectedIndex == 2)
|
||||
],
|
||||
popupMenuCallback: (p) {
|
||||
setState(() {
|
||||
_selectedIndex = p.id;
|
||||
});
|
||||
context.read<CartonModel>().onChanged(_selectedIndex);
|
||||
});
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: LocalAppBar(labelKey: "boxes.name", actions: [popupMenu]),
|
||||
appBar: LocalAppBar(labelKey: "boxes.name", actions: [
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.search,
|
||||
color: Colors.white,
|
||||
),
|
||||
iconSize: 30,
|
||||
onPressed: () {
|
||||
searchCarton(context, callbackCartonSelect: (c) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => CartonInfo(box: c)),
|
||||
);
|
||||
});
|
||||
}),
|
||||
_filterWidget(context)
|
||||
]),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
_newBox();
|
||||
@@ -71,10 +118,110 @@ class _CartonListState extends State<CartonList> {
|
||||
label: LocalText(context, "boxes.new", color: Colors.white),
|
||||
backgroundColor: primaryColor,
|
||||
),
|
||||
body: PaginatorListView<Carton>(
|
||||
paginatorListener: boxModel.getBoxes!,
|
||||
rowBuilder: (p) => CartonListRow(box: p),
|
||||
color: primaryColor),
|
||||
body: Column(
|
||||
children: [
|
||||
shipmentFilterBox,
|
||||
Wrap(
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
cartonModel.filterByConsingee != null
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(left: 15),
|
||||
child: Row(
|
||||
children: [
|
||||
Wrap(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text("Consignee: ",
|
||||
style: TextStyle(
|
||||
fontSize: 12, color: Colors.grey)),
|
||||
Text(
|
||||
cartonModel.filterByConsingee!.name ??
|
||||
"",
|
||||
style: const TextStyle(
|
||||
fontSize: 12, color: Colors.black)),
|
||||
const SizedBox(width: 3),
|
||||
Text(
|
||||
cartonModel.filterByConsingee!.fcsID ??
|
||||
"",
|
||||
style: const TextStyle(
|
||||
fontSize: 12, color: labelColor)),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 5),
|
||||
child: InkResponse(
|
||||
radius: 30,
|
||||
onTap: () {
|
||||
context
|
||||
.read<CartonModel>()
|
||||
.clearFilterConsignee();
|
||||
},
|
||||
child: const Icon(AntDesign.closecircleo,
|
||||
size: 20, color: dangerColor),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
: const SizedBox(),
|
||||
cartonModel.filterBySender != null
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(left: 15),
|
||||
child: Row(
|
||||
children: [
|
||||
Wrap(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text("Sender: ",
|
||||
style: TextStyle(
|
||||
fontSize: 12, color: Colors.grey)),
|
||||
Text(cartonModel.filterBySender!.name ?? "",
|
||||
style: const TextStyle(
|
||||
fontSize: 12, color: Colors.black)),
|
||||
const SizedBox(width: 3),
|
||||
Text(
|
||||
cartonModel.filterBySender!.fcsID ?? "",
|
||||
style: const TextStyle(
|
||||
fontSize: 12, color: labelColor)),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 5),
|
||||
child: InkResponse(
|
||||
radius: 30,
|
||||
onTap: () {
|
||||
context
|
||||
.read<CartonModel>()
|
||||
.clearFilterSender();
|
||||
},
|
||||
child: const Icon(AntDesign.closecircleo,
|
||||
size: 20, color: dangerColor),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
: const SizedBox(),
|
||||
],
|
||||
),
|
||||
Divider(color: Colors.grey.shade400),
|
||||
Expanded(
|
||||
child: cartonModel.getBoxes == null
|
||||
? const SizedBox()
|
||||
: PaginatorListView<Carton>(
|
||||
paginatorListener: cartonModel.getBoxes!,
|
||||
rowBuilder: (p) => CartonListRow(box: p),
|
||||
color: primaryColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -85,4 +232,58 @@ class _CartonListState extends State<CartonList> {
|
||||
CupertinoPageRoute(builder: (context) => CartonEditor()),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _filterWidget(BuildContext context) {
|
||||
var model = Provider.of<CartonModel>(context);
|
||||
return IconButton(
|
||||
icon: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: <Widget>[
|
||||
const Icon(
|
||||
Icons.filter_list,
|
||||
color: Colors.white,
|
||||
),
|
||||
model.filterByStatus != null ||
|
||||
model.filterBySender != null ||
|
||||
model.filterByConsingee != null
|
||||
? Positioned(
|
||||
bottom: 15,
|
||||
right: 0,
|
||||
child: Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container()
|
||||
],
|
||||
),
|
||||
onPressed: () async {
|
||||
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)));
|
||||
});
|
||||
}
|
||||
|
||||
_filterShipment(FcsShipment shipment) async {
|
||||
setState(() {
|
||||
_selectedShipment = shipment;
|
||||
});
|
||||
|
||||
await context.read<CartonModel>().filterCartonByShipment(_selectedShipment);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user