Files
fcs/lib/pages/carton/carton_list.dart

365 lines
14 KiB
Dart
Raw Normal View History

2024-02-07 17:26:29 +06:30
import 'package:fcs/domain/entities/fcs_shipment.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/helpers/theme.dart';
2020-10-18 02:38:46 +06:30
import 'package:fcs/pages/carton/model/carton_model.dart';
2024-01-25 17:40:35 +06:30
import 'package:fcs/pages/widgets/local_app_bar.dart';
2020-10-09 17:28:42 +06:30
import 'package:fcs/pages/widgets/local_text.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/widgets/progress.dart';
2020-10-12 03:34:05 +06:30
import 'package:flutter/cupertino.dart';
2020-06-04 01:36:49 +06:30
import 'package:flutter/material.dart';
2024-02-07 17:26:29 +06:30
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
2020-06-04 01:36:49 +06:30
import 'package:provider/provider.dart';
2024-09-22 16:49:59 +06:30
import '../../constants.dart';
2024-01-24 16:54:08 +06:30
import '../../domain/entities/carton.dart';
import '../../pagination/paginator_listview.dart';
2024-02-07 17:26:29 +06:30
import '../carton_search/carton_search.dart';
import '../fcs_shipment/model/fcs_shipment_model.dart';
2020-10-19 05:13:49 +06:30
import 'carton_editor.dart';
2024-02-07 17:26:29 +06:30
import 'carton_filter.dart';
import 'carton_info.dart';
2024-02-09 13:49:18 +06:30
import 'widget/carton_list_row.dart';
2020-06-04 01:36:49 +06:30
2020-10-19 05:13:49 +06:30
class CartonList extends StatefulWidget {
2020-06-04 01:36:49 +06:30
@override
2020-10-19 05:13:49 +06:30
_CartonListState createState() => _CartonListState();
2020-06-04 01:36:49 +06:30
}
2020-10-19 05:13:49 +06:30
class _CartonListState extends State<CartonList> {
2020-06-04 01:36:49 +06:30
bool _isLoading = false;
2024-02-07 17:26:29 +06:30
List<FcsShipment> _shipments = [];
FcsShipment? _selectedShipment;
2024-02-15 16:41:49 +06:30
bool _down = true;
2020-06-04 01:36:49 +06:30
@override
void initState() {
super.initState();
2024-01-24 16:54:08 +06:30
_init();
2020-06-04 01:36:49 +06:30
}
2024-02-07 17:26:29 +06:30
_init() async {
2024-01-24 16:54:08 +06:30
var model = context.read<CartonModel>();
_shipments = await context.read<FcsShipmentModel>().getShipments();
_shipments.insert(0, model.defaultShipment);
2024-03-04 09:23:05 +06:30
if (_shipments.length > shipmentCountForCartonFilter) {
_shipments.insert(_shipments.length,
2024-03-04 17:09:47 +06:30
FcsShipment(shipmentNumber: "See More", id: see_more));
2024-03-04 09:23:05 +06:30
}
_selectedShipment = model.shipment ?? model.defaultShipment;
2024-02-07 17:26:29 +06:30
model.loadPaginationCartons();
2024-01-24 16:54:08 +06:30
if (mounted) {
setState(() {});
}
2020-06-04 01:36:49 +06:30
}
@override
Widget build(BuildContext context) {
2024-02-07 17:26:29 +06:30
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(
2024-03-04 17:09:47 +06:30
color: g.id == see_more
2024-03-04 09:23:05 +06:30
? Colors.transparent
: _selectedShipment?.id == g.id
? primaryColor
: Colors.grey.shade300)),
2024-02-07 17:26:29 +06:30
padding: const EdgeInsets.all(8),
onPressed: () {
_filterShipment(g);
},
label: Text(g.shipmentNumber ?? "",
style: TextStyle(
2024-03-04 17:09:47 +06:30
color: g.id == see_more
2024-02-07 17:26:29 +06:30
? primaryColor
2024-03-04 09:23:05 +06:30
: _selectedShipment?.id == g.id
? primaryColor
: labelColor,
2024-02-07 17:26:29 +06:30
fontWeight: FontWeight.normal,
fontSize: 14,
fontFamily: "Poppins")),
),
);
}).toList()),
),
);
2024-01-24 16:54:08 +06:30
2020-06-04 01:36:49 +06:30
return LocalProgress(
inAsyncCall: _isLoading,
2024-01-25 17:40:35 +06:30
child: Scaffold(
2024-02-07 17:26:29 +06:30
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(
2024-02-09 13:35:32 +06:30
builder: (context) => CartonInfo(carton: c)),
2024-02-07 17:26:29 +06:30
);
});
}),
_filterWidget(context)
]),
2024-01-25 17:40:35 +06:30
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
_newBox();
},
icon: Icon(Icons.add),
label: LocalText(context, "boxes.new", color: Colors.white),
backgroundColor: primaryColor,
2020-06-04 01:36:49 +06:30
),
2024-02-07 17:26:29 +06:30
body: Column(
children: [
2024-02-15 16:41:49 +06:30
AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
transitionBuilder: (Widget child, Animation<double> animation) =>
FadeTransition(
opacity: animation,
child: SizeTransition(
sizeFactor: animation,
axis: Axis.vertical,
2025-03-12 17:49:27 +06:30
child: child,
2024-02-15 16:41:49 +06:30
),
),
child: _down
? Column(
children: [
shipmentFilterBox,
Wrap(
runSpacing: 8,
2024-02-07 17:26:29 +06:30
children: [
2024-02-15 16:41:49 +06:30
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(),
2024-02-07 17:26:29 +06:30
],
),
2024-02-15 16:41:49 +06:30
Divider(color: Colors.grey.shade400),
],
)
: const SizedBox(),
2024-02-07 17:26:29 +06:30
),
Expanded(
child: cartonModel.getBoxes == null
? const SizedBox()
: PaginatorListView<Carton>(
paginatorListener: cartonModel.getBoxes!,
rowBuilder: (p) => CartonListRow(box: p),
2024-02-15 16:41:49 +06:30
color: primaryColor,
onScroll: ((down) {
if (_down == down) return;
setState(() {
_down = down;
});
}),
),
2024-02-07 17:26:29 +06:30
),
],
),
2020-10-15 17:33:43 +06:30
),
2020-06-04 01:36:49 +06:30
);
}
2020-10-15 17:33:43 +06:30
_newBox() {
Navigator.push(
context,
2020-10-19 05:13:49 +06:30
CupertinoPageRoute(builder: (context) => CartonEditor()),
2020-06-04 01:36:49 +06:30
);
}
2024-02-07 17:26:29 +06:30
Widget _filterWidget(BuildContext context) {
var model = Provider.of<CartonModel>(context);
2025-03-12 17:49:27 +06:30
return Padding(
padding: const EdgeInsets.only(right: 5),
child: IconButton(
icon: SizedBox(
width: 30,
height: 30,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
const Icon(
Icons.filter_list,
color: Colors.white,
),
model.filterByStatus != null ||
model.filterBySender != null ||
model.filterByConsingee != null ||
model.shipment != null
? Positioned(
bottom: 15,
right: 0,
child: Container(
width: 10,
height: 10,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.red,
),
),
)
: Container()
],
2024-02-07 17:26:29 +06:30
),
2025-03-12 17:49:27 +06:30
),
onPressed: () {
_showFilter();
}),
);
2024-02-07 17:26:29 +06:30
}
2024-03-04 09:23:05 +06:30
_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<CartonModel>();
if (updated ?? false) {
setState(() {
_selectedShipment = model.shipment ?? model.defaultShipment;
});
}
}
2024-02-07 17:26:29 +06:30
_filterShipment(FcsShipment shipment) async {
2024-03-04 17:09:47 +06:30
if (shipment.id == see_more) {
2024-03-04 09:23:05 +06:30
_showFilter();
return;
}
2024-02-07 17:26:29 +06:30
setState(() {
_selectedShipment = shipment;
});
await context.read<CartonModel>().filterCartonByShipment(_selectedShipment);
}
2020-06-04 01:36:49 +06:30
}