2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart';
|
2020-10-15 19:40:03 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_popup_menu_button.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_popupmenu.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
2020-10-08 03:32:52 +06:30
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-06-01 14:24:45 +06:30
|
|
|
import 'package:flutter/material.dart';
|
2020-10-15 19:40:03 +06:30
|
|
|
import 'package:provider/provider.dart';
|
2020-06-01 14:24:45 +06:30
|
|
|
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'fcs_shipment_editor.dart';
|
|
|
|
|
import 'fcs_shipment_list_row.dart';
|
2020-06-01 14:24:45 +06:30
|
|
|
|
2020-10-07 02:33:06 +06:30
|
|
|
class FcsShipmentList extends StatefulWidget {
|
2020-06-01 14:24:45 +06:30
|
|
|
@override
|
2020-10-07 02:33:06 +06:30
|
|
|
_FcsShipmentListState createState() => _FcsShipmentListState();
|
2020-06-01 14:24:45 +06:30
|
|
|
}
|
|
|
|
|
|
2020-10-07 02:33:06 +06:30
|
|
|
class _FcsShipmentListState extends State<FcsShipmentList> {
|
2020-06-01 14:24:45 +06:30
|
|
|
bool _isLoading = false;
|
2020-10-15 19:40:03 +06:30
|
|
|
var _controller = ScrollController();
|
2020-06-01 14:24:45 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
|
2020-10-15 19:40:03 +06:30
|
|
|
_controller.addListener(() async {
|
|
|
|
|
if (_controller.position.pixels == _controller.position.maxScrollExtent) {
|
|
|
|
|
Provider.of<FcsShipmentModel>(context, listen: false).loadMore();
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-10-16 11:05:38 +06:30
|
|
|
Provider.of<FcsShipmentModel>(context, listen: false).initData();
|
2020-06-01 14:24:45 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-10-07 18:19:12 +06:30
|
|
|
var shipmentModel = Provider.of<FcsShipmentModel>(context);
|
|
|
|
|
|
2020-10-15 19:40:03 +06:30
|
|
|
final popupMenu = LocalPopupMenuButton(
|
|
|
|
|
popmenus: [
|
|
|
|
|
LocalPopupMenu(
|
|
|
|
|
id: 1,
|
2020-10-19 05:13:49 +06:30
|
|
|
textKey: "FCSshipment.popupmenu.active",
|
2020-10-15 19:40:03 +06:30
|
|
|
selected: shipmentModel.selectedIndex == 1),
|
|
|
|
|
LocalPopupMenu(
|
|
|
|
|
id: 2,
|
2020-10-19 05:13:49 +06:30
|
|
|
textKey: "FCSshipment.popupmenu.delivered",
|
2020-10-15 19:40:03 +06:30
|
|
|
selected: shipmentModel.selectedIndex == 2)
|
|
|
|
|
],
|
|
|
|
|
popupMenuCallback: (p) => this.setState(() {
|
|
|
|
|
shipmentModel.selectedIndex = p.id;
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
2020-06-01 14:24:45 +06:30
|
|
|
return LocalProgress(
|
2020-10-07 18:19:12 +06:30
|
|
|
inAsyncCall: _isLoading,
|
2020-06-01 14:24:45 +06:30
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
leading: new IconButton(
|
2020-10-08 03:32:52 +06:30
|
|
|
icon: new Icon(CupertinoIcons.back),
|
2020-06-01 14:24:45 +06:30
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
|
),
|
|
|
|
|
backgroundColor: primaryColor,
|
2020-10-07 18:19:12 +06:30
|
|
|
title: LocalText(context, 'FCSshipment.list.title',
|
2020-06-01 14:24:45 +06:30
|
|
|
color: Colors.white, fontSize: 20),
|
2020-10-15 19:40:03 +06:30
|
|
|
actions: [popupMenu],
|
2020-06-01 14:24:45 +06:30
|
|
|
),
|
|
|
|
|
floatingActionButton: FloatingActionButton.extended(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
_newShipment();
|
|
|
|
|
},
|
|
|
|
|
icon: Icon(Icons.add),
|
2020-10-07 18:19:12 +06:30
|
|
|
label: LocalText(context, "FCSshipment.add", color: Colors.white),
|
2020-06-01 14:24:45 +06:30
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
),
|
2020-10-07 18:19:12 +06:30
|
|
|
body: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Expanded(
|
2020-10-15 19:40:03 +06:30
|
|
|
child: RefreshIndicator(
|
|
|
|
|
child: ListView.separated(
|
|
|
|
|
physics: AlwaysScrollableScrollPhysics(),
|
|
|
|
|
controller: _controller,
|
|
|
|
|
separatorBuilder: (context, index) => Divider(
|
|
|
|
|
color: Colors.black,
|
2020-10-19 05:13:49 +06:30
|
|
|
height: 1,
|
2020-10-15 19:40:03 +06:30
|
|
|
),
|
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemCount: shipmentModel.fcsShipments.length,
|
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
|
return FcsShipmentListRow(
|
|
|
|
|
key: ValueKey(
|
|
|
|
|
shipmentModel.fcsShipments[index].id),
|
|
|
|
|
shipment: shipmentModel.fcsShipments[index]);
|
|
|
|
|
}),
|
|
|
|
|
onRefresh: () => shipmentModel.refresh(),
|
|
|
|
|
),
|
2020-10-07 18:19:12 +06:30
|
|
|
),
|
2020-10-15 19:40:03 +06:30
|
|
|
shipmentModel.isLoading
|
|
|
|
|
? Container(
|
|
|
|
|
padding: EdgeInsets.all(8),
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Text("Loading...",
|
|
|
|
|
style: TextStyle(color: Colors.white)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Container(),
|
2020-10-07 18:19:12 +06:30
|
|
|
],
|
|
|
|
|
)));
|
2020-06-01 14:24:45 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_newShipment() {
|
2020-10-14 13:54:42 +06:30
|
|
|
Navigator.of(context)
|
|
|
|
|
.push(CupertinoPageRoute(builder: (context) => FcsShipmentEditor()));
|
2020-06-01 14:24:45 +06:30
|
|
|
}
|
|
|
|
|
}
|