Files
fcs/lib/pages/shipment/shipment_pack.dart

141 lines
3.9 KiB
Dart
Raw Normal View History

2020-10-19 05:13:49 +06:30
import 'package:fcs/domain/entities/fcs_shipment.dart';
import 'package:fcs/domain/entities/shipment.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/shipment/model/shipment_model.dart';
import 'package:fcs/pages/widgets/local_button.dart';
import 'package:fcs/pages/widgets/local_dropdown.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/local_title.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
2021-09-10 16:48:21 +06:30
import 'package:flutter_icons_null_safety/flutter_icons_null_safety.dart';
2020-10-19 05:13:49 +06:30
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'widgets.dart';
class ShipmentPack extends StatefulWidget {
2021-09-10 16:48:21 +06:30
final Shipment? shipment;
2020-10-19 05:13:49 +06:30
ShipmentPack({this.shipment});
@override
_ShipmentPackState createState() => _ShipmentPackState();
}
class _ShipmentPackState extends State<ShipmentPack> {
var dateFormatter = new DateFormat('dd MMM yyyy');
var timeFormatter = new DateFormat('jm');
2021-09-10 16:48:21 +06:30
Shipment? _shipment;
2020-10-19 05:13:49 +06:30
bool _isLoading = false;
var now = new DateTime.now();
2021-09-10 16:48:21 +06:30
FcsShipment? _fcsShipment;
List<FcsShipment>? _fcsShipments;
2020-10-19 05:13:49 +06:30
@override
void initState() {
super.initState();
_shipment = widget.shipment;
_loadFcsShipments();
}
_loadFcsShipments() async {
FcsShipmentModel fcsShipmentModel =
Provider.of<FcsShipmentModel>(context, listen: false);
var fcsShipments = await fcsShipmentModel.getActiveFcsShipments();
2021-09-10 16:48:21 +06:30
var fcsShipment =
fcsShipments.firstWhere((e) => e.id == _shipment?.fcsShipmentID);
2020-10-19 05:13:49 +06:30
setState(() {
_fcsShipments = fcsShipments;
_fcsShipment = fcsShipment;
});
}
@override
Widget build(BuildContext context) {
2021-09-10 16:48:21 +06:30
final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!);
2020-10-19 05:13:49 +06:30
var fcsShipmentsBox = LocalDropdown<FcsShipment>(
callback: (v) {
setState(() {
_fcsShipment = v;
});
},
labelKey: "shipment.pack.fcs.shipment",
iconData: MaterialCommunityIcons.worker,
display: (u) => u.shipmentNumber,
selectedValue: _fcsShipment,
values: _fcsShipments,
);
final packbtn = LocalButton(
textKey: "shipment.pack.btn",
callBack: _save,
);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
icon: new Icon(
CupertinoIcons.back,
color: primaryColor,
),
onPressed: () => Navigator.of(context).pop(),
),
shadowColor: Colors.transparent,
backgroundColor: Colors.white,
title: LocalText(
context,
"shipment.pack.menuitem",
fontSize: 20,
color: primaryColor,
),
),
body: Padding(
padding: const EdgeInsets.all(10.0),
child: ListView(
children: <Widget>[
Center(child: shipmentNumberBox),
SizedBox(
height: 10,
),
LocalTitle(textKey: "shipment.pack.fcs.shipment"),
fcsShipmentsBox,
SizedBox(
height: 10,
),
packbtn,
],
),
),
),
);
}
_save() async {
2021-09-10 16:48:21 +06:30
_shipment!.fcsShipmentID = this._fcsShipment!.id;
2020-10-19 05:13:49 +06:30
setState(() {
_isLoading = true;
});
try {
ShipmentModel shipmentModel =
Provider.of<ShipmentModel>(context, listen: false);
2021-09-10 16:48:21 +06:30
await shipmentModel.packShipment(_shipment!);
2020-10-19 05:13:49 +06:30
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
}