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

305 lines
9.3 KiB
Dart
Raw Normal View History

2020-10-20 06:19:10 +06:30
import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/carton.dart';
2020-10-14 16:53:16 +06:30
import 'package:fcs/domain/entities/package.dart';
import 'package:fcs/domain/vo/delivery_address.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/package/model/package_model.dart';
2020-10-15 03:06:13 +06:30
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
2020-10-14 16:53:16 +06:30
import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
import 'package:fcs/pages/widgets/display_text.dart';
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
import 'package:fcs/pages/widgets/length_picker.dart';
2020-10-20 06:19:10 +06:30
import 'package:fcs/pages/widgets/local_radio_buttons.dart';
2020-10-14 16:53:16 +06:30
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';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
2020-10-20 06:19:10 +06:30
import 'carton_cargo_table.dart';
2020-10-19 05:13:49 +06:30
import 'carton_editor.dart';
2020-10-20 06:19:10 +06:30
import 'carton_package_table.dart';
2020-10-18 02:38:46 +06:30
import 'model/carton_model.dart';
2020-10-20 06:19:10 +06:30
import 'widgets.dart';
2020-10-14 16:53:16 +06:30
final DateFormat dateFormat = DateFormat("d MMM yyyy");
2020-10-19 05:13:49 +06:30
class CartonInfo extends StatefulWidget {
2020-10-18 02:38:46 +06:30
final Carton box;
2020-10-19 05:13:49 +06:30
CartonInfo({this.box});
2020-10-14 16:53:16 +06:30
@override
2020-10-19 05:13:49 +06:30
_CartonInfoState createState() => _CartonInfoState();
2020-10-14 16:53:16 +06:30
}
2020-10-19 05:13:49 +06:30
class _CartonInfoState extends State<CartonInfo> {
2020-10-14 16:53:16 +06:30
bool _isLoading = false;
2020-10-18 02:38:46 +06:30
Carton _box;
2020-10-14 16:53:16 +06:30
DeliveryAddress _deliveryAddress = new DeliveryAddress();
TextEditingController _widthController = new TextEditingController();
TextEditingController _heightController = new TextEditingController();
TextEditingController _lengthController = new TextEditingController();
double volumetricRatio = 0;
double shipmentWeight = 0;
2020-10-20 06:19:10 +06:30
bool isMixBox;
bool isFromShipments;
2020-10-21 02:59:10 +06:30
bool isFromPackages;
bool isSmallBag;
2020-10-20 06:19:10 +06:30
bool isEdiable;
2020-10-14 16:53:16 +06:30
@override
void initState() {
super.initState();
_box = widget.box;
//for shipment weight
2020-10-15 03:06:13 +06:30
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
.rate
.volumetricRatio;
2020-10-14 16:53:16 +06:30
_lengthController.addListener(_calShipmentWeight);
_widthController.addListener(_calShipmentWeight);
_heightController.addListener(_calShipmentWeight);
2020-10-21 02:59:10 +06:30
_updateBoxData();
_loadPackages();
}
_updateBoxData() {
2020-10-14 16:53:16 +06:30
_widthController.text = _box.width.toString();
_heightController.text = _box.height.toString();
_lengthController.text = _box.length.toString();
2020-10-16 10:58:31 +06:30
_deliveryAddress = _box.deliveryAddress;
2020-10-20 06:19:10 +06:30
isMixBox = _box.cartonType == carton_mix_box;
isFromShipments = _box.cartonType == carton_from_shipments;
2020-10-21 02:59:10 +06:30
isFromPackages = _box.cartonType == carton_from_packages;
isSmallBag = _box.cartonType == carton_small_bag;
isEdiable = !isMixBox &&
(isFromPackages || isSmallBag) &&
_box.status == carton_packed_status;
2020-10-20 06:19:10 +06:30
}
_loadPackages() async {
2020-10-21 02:59:10 +06:30
if (!isFromPackages && !isSmallBag) return;
2020-10-20 06:19:10 +06:30
if (_box.cartonType == carton_from_packages && _box.userID == null) return;
PackageModel packageModel =
Provider.of<PackageModel>(context, listen: false);
2020-10-21 02:59:10 +06:30
List<Package> packages = await packageModel.getPackages(_box.userID, [
package_processed_status,
package_packed_status,
2020-10-23 01:27:23 +06:30
package_shipped_status,
package_delivered_status
2020-10-21 02:59:10 +06:30
]);
packages = packages.where((p) => _box.packageIDs.contains(p.id)).toList();
2020-10-20 06:19:10 +06:30
packages.forEach((p) {
2020-10-21 02:59:10 +06:30
p.isChecked = true;
2020-10-20 06:19:10 +06:30
});
setState(() {
_box.packages = packages;
});
2020-10-14 16:53:16 +06:30
}
_calShipmentWeight() {
double l = double.parse(_lengthController.text, (s) => 0);
double w = double.parse(_widthController.text, (s) => 0);
double h = double.parse(_heightController.text, (s) => 0);
setState(() {
shipmentWeight = l * w * h / volumetricRatio;
});
}
@override
void dispose() {
super.dispose();
}
final DateFormat dateFormat = DateFormat("d MMM yyyy");
@override
Widget build(BuildContext context) {
2020-10-20 06:19:10 +06:30
var cartonModel = Provider.of<CartonModel>(context);
2020-10-14 16:53:16 +06:30
2020-10-20 06:19:10 +06:30
final cartonTypeBox = LocalRadioButtons(
readOnly: true,
values: cartonModel.cartonTypesInfo,
selectedValue:
_box.isShipmentCarton ? carton_from_shipments : _box.cartonType);
2020-10-14 16:53:16 +06:30
final shipmentBox = DisplayText(
2020-10-20 06:19:10 +06:30
text: _box.fcsShipmentNumber,
2020-10-14 16:53:16 +06:30
labelTextKey: "box.fcs_shipment_num",
iconData: Ionicons.ios_airplane,
);
final fcsIDBox = DisplayText(
text: _box.fcsID == null ? "" : _box.fcsID,
labelTextKey: "box.fcs.id",
icon: FcsIDIcon(),
);
final customerNameBox = DisplayText(
text: _box.userName == null ? "" : _box.userName,
labelTextKey: "box.name",
iconData: Icons.person,
);
final lengthBox = LengthPicker(
controller: _lengthController,
lableKey: "box.length",
isReadOnly: true,
);
final widthBox = LengthPicker(
controller: _widthController,
lableKey: "box.width",
isReadOnly: true,
);
final heightBox = LengthPicker(
controller: _heightController,
lableKey: "box.height",
isReadOnly: true,
);
final dimBox = Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Icon(FontAwesome.arrow_circle_right, color: primaryColor),
),
SizedBox(child: lengthBox, width: 80),
SizedBox(child: widthBox, width: 80),
SizedBox(child: heightBox, width: 80),
],
);
final shipmentWeightBox = DisplayText(
2020-12-02 20:55:00 +06:30
text: shipmentWeight != null ? shipmentWeight.toStringAsFixed(2) : "",
2020-10-14 16:53:16 +06:30
labelTextKey: "box.shipment_weight",
iconData: MaterialCommunityIcons.weight,
);
2020-10-20 06:19:10 +06:30
final cargoTableBox = CargoTable(
cargoTypes: _box.cargoTypes,
);
2020-10-21 02:59:10 +06:30
final mixCartonNumberBox = DisplayText(
text: _box.mixCartonNumber,
labelTextKey: "box.mix.carton",
iconData: MaterialCommunityIcons.package,
);
2020-10-14 16:53:16 +06:30
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
icon: new Icon(CupertinoIcons.back, color: primaryColor, size: 30),
onPressed: () => Navigator.of(context).pop(),
),
shadowColor: Colors.transparent,
backgroundColor: Colors.white,
title: LocalText(
context,
"box.info.title",
fontSize: 20,
color: primaryColor,
),
2020-10-20 06:19:10 +06:30
actions: isEdiable
? <Widget>[
IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: _gotoEditor,
),
IconButton(
icon: Icon(Icons.delete, color: primaryColor),
onPressed: _delete,
),
]
: [],
2020-10-14 16:53:16 +06:30
),
2020-10-21 02:59:10 +06:30
body: Padding(
padding: const EdgeInsets.all(10.0),
child: ListView(children: <Widget>[
Center(child: getCartonNumberStatus(context, _box)),
LocalTitle(textKey: "box.type.title"),
cartonTypeBox,
LocalTitle(textKey: "box.shipment_info"),
shipmentBox,
isSmallBag ? mixCartonNumberBox : Container(),
isMixBox ? Container() : fcsIDBox,
isMixBox ? Container() : customerNameBox,
isFromPackages || isSmallBag
? CartonPackageTable(
packages: _box.packages,
)
: Container(),
isMixBox ? Container() : LocalTitle(textKey: "box.cargo.type"),
isMixBox ? Container() : cargoTableBox,
...(isFromPackages
? [
LocalTitle(textKey: "box.dimension"),
dimBox,
shipmentWeightBox,
]
: []),
isMixBox
? Container()
: LocalTitle(textKey: "box.delivery_address"),
isMixBox
? Container()
: DefaultDeliveryAddress(
2020-10-14 16:53:16 +06:30
deliveryAddress: _deliveryAddress,
labelKey: "box.delivery_address",
),
2020-10-21 02:59:10 +06:30
SizedBox(
height: 20,
)
]),
2020-10-14 16:53:16 +06:30
),
),
);
}
_gotoEditor() async {
2020-10-20 06:19:10 +06:30
bool updated = await Navigator.push<bool>(
2020-10-14 16:53:16 +06:30
context,
2020-10-19 05:13:49 +06:30
CupertinoPageRoute(builder: (context) => CartonEditor(box: widget.box)),
2020-10-14 16:53:16 +06:30
);
2020-10-20 06:19:10 +06:30
if (updated ?? false) {
var cartonModel = Provider.of<CartonModel>(context, listen: false);
var c = await cartonModel.getCarton(widget.box.id);
setState(() {
_box = c;
2020-10-21 02:59:10 +06:30
_updateBoxData();
2020-10-20 06:19:10 +06:30
});
_loadPackages();
}
}
_delete() {
showConfirmDialog(context, "box.delete.confirm", () {
_deleteCarton();
});
}
_deleteCarton() async {
setState(() {
_isLoading = true;
});
try {
var cartonModel = Provider.of<CartonModel>(context, listen: false);
await cartonModel.deleteCarton(widget.box);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
2020-10-14 16:53:16 +06:30
}
}