2020-10-19 05:13:49 +06:30
|
|
|
import 'package:fcs/domain/entities/shipment.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/pages/main/util.dart';
|
|
|
|
|
import 'package:fcs/pages/shipment/model/shipment_model.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/input_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_button.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';
|
2021-09-10 16:48:21 +06:30
|
|
|
import 'package:flutter_icons_null_safety/flutter_icons_null_safety.dart';
|
|
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
2020-10-19 05:13:49 +06:30
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
import 'widgets.dart';
|
|
|
|
|
|
|
|
|
|
class ShipmentConfirm extends StatefulWidget {
|
2021-09-10 16:48:21 +06:30
|
|
|
final Shipment? shipment;
|
2020-10-19 05:13:49 +06:30
|
|
|
ShipmentConfirm({this.shipment});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_ShipmentConfirmState createState() => _ShipmentConfirmState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _ShipmentConfirmState extends State<ShipmentConfirm> {
|
|
|
|
|
var dateFormatter = new DateFormat('dd MMM yyyy');
|
|
|
|
|
var timeFormatter = new DateFormat('jm');
|
|
|
|
|
TextEditingController _handlingFee = new TextEditingController();
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
_shipment = widget.shipment;
|
2021-09-10 17:14:59 +06:30
|
|
|
_handlingFee.text = _shipment!.handlingFee.toString();
|
2020-10-19 05:13:49 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
|
final handlingFeeBox = InputText(
|
|
|
|
|
labelTextKey: "shipment.handling.fee",
|
|
|
|
|
controller: _handlingFee,
|
2021-09-10 16:48:21 +06:30
|
|
|
iconData: FontAwesomeIcons.truck,
|
2020-10-19 05:13:49 +06:30
|
|
|
);
|
|
|
|
|
final confirmbtn = LocalButton(
|
|
|
|
|
textKey: "shipment.confirm.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.confirm.menuitem",
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
body: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(10.0),
|
|
|
|
|
child: ListView(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Center(child: shipmentNumberBox),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 10,
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 10,
|
|
|
|
|
),
|
|
|
|
|
handlingFeeBox,
|
|
|
|
|
confirmbtn,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_save() async {
|
2021-09-10 16:48:21 +06:30
|
|
|
_shipment!.handlingFee = double.tryParse(_handlingFee.text) ?? 0;
|
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.confirmShipment(_shipment!);
|
2020-10-19 05:13:49 +06:30
|
|
|
Navigator.pop(context, true);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|