Files
fcs/lib/pages/carton/carton_info.dart
2020-10-19 05:13:49 +06:30

561 lines
18 KiB
Dart

import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/cargo_type.dart';
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';
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
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';
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';
import 'package:timeline_list/timeline.dart';
import 'package:timeline_list/timeline_model.dart';
import 'carton_editor.dart';
import 'model/carton_model.dart';
final DateFormat dateFormat = DateFormat("d MMM yyyy");
class CartonInfo extends StatefulWidget {
final Carton box;
CartonInfo({this.box});
@override
_CartonInfoState createState() => _CartonInfoState();
}
class _CartonInfoState extends State<CartonInfo> {
bool _isLoading = false;
Carton _box;
String _selectedCartonType;
String _shipmentNumber;
List<Package> _packages = [];
List<Carton> _mixBoxes = [];
Carton _selectedShipmentBox = new Carton();
List<CargoType> _cargoTypes = [];
DeliveryAddress _deliveryAddress = new DeliveryAddress();
TextEditingController _widthController = new TextEditingController();
TextEditingController _heightController = new TextEditingController();
TextEditingController _lengthController = new TextEditingController();
double volumetricRatio = 0;
double shipmentWeight = 0;
@override
void initState() {
super.initState();
_box = widget.box;
_shipmentNumber = _box.shipmentNumber;
_selectedCartonType = _box.cartonType;
// for packages
var packageModel = Provider.of<PackageModel>(context, listen: false);
_packages = [
// packageModel.packages[0],
// packageModel.packages[1],
];
_packages.forEach((p) {
p.isChecked = false;
});
//for shipment boxes
var boxModel = Provider.of<CartonModel>(context, listen: false);
_selectedShipmentBox = boxModel.boxeList[0];
//for mix boxes
_mixBoxes = [
boxModel.boxeList[0],
boxModel.boxeList[1],
boxModel.boxeList[2]
];
_mixBoxes.forEach((b) {
b.isChecked = false;
});
//for shipment weight
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
.rate
.volumetricRatio;
_lengthController.addListener(_calShipmentWeight);
_widthController.addListener(_calShipmentWeight);
_heightController.addListener(_calShipmentWeight);
_widthController.text = _box.width.toString();
_heightController.text = _box.height.toString();
_lengthController.text = _box.length.toString();
_cargoTypes = _box.cargoTypes;
_deliveryAddress = _box.deliveryAddress;
}
_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");
List<TimelineModel> _models() {
if (_box.shipmentHistory == null) return [];
// return [];
return _box.shipmentHistory
.map((e) => TimelineModel(
Padding(
padding: const EdgeInsets.all(18.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(e.status,
style: TextStyle(
color: e.done ? primaryColor : Colors.grey,
fontSize: 16,
fontWeight: FontWeight.bold)),
e.status == "Processed"
? Text("(Waiting for payment)",
style: TextStyle(
color: e.done ? primaryColor : Colors.grey,
fontSize: 14,
fontWeight: FontWeight.bold))
: Container(),
Text(dateFormat.format(e.date)),
],
),
),
iconBackground: e.done ? primaryColor : Colors.grey,
icon: Icon(
e.status == "Shipped"
? Ionicons.ios_airplane
: e.status == "Delivered"
? MaterialCommunityIcons.truck_fast
: e.status == "Processed"
? MaterialIcons.check
: Octicons.package,
color: Colors.white,
)))
.toList();
}
@override
Widget build(BuildContext context) {
final cargoType = Container(
height: 30,
padding: EdgeInsets.only(left: 15),
child: Row(
children: [
Icon(Icons.check_circle, color: primaryColor),
SizedBox(
width: 10,
),
Text(_selectedCartonType ?? ""),
],
),
);
final shipmentBox = DisplayText(
text: _shipmentNumber == null ? "" : _shipmentNumber,
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 packageTitle = Container(
padding: EdgeInsets.only(left: 15, right: 10.0, top: 20),
child: Row(
children: <Widget>[
Expanded(
child: LocalText(context, 'box.tracking.id', color: Colors.grey),
),
LocalText(context, 'box.package.desc', color: Colors.grey),
],
),
);
List<Widget> getPackageRowList() {
return _packages.asMap().entries.map((p) {
return Container(
color: Colors.grey[50].withOpacity(0.2),
child: Container(
padding:
EdgeInsets.only(left: 15.0, right: 10.0, top: 5.0, bottom: 5.0),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: p.key == _packages.length - 1
? Colors.white
: Colors.grey[350],
width: 1),
),
),
child: Row(
children: <Widget>[
Expanded(
child: new Text(
p.value.trackingID,
style: textStyle,
)),
new Column(
children: [
new Text(
p.value.desc == null ? "" : p.value.desc,
style: textStyle,
),
new Text(
"(${p.value.market == null ? "" : p.value.market})",
style: textStyle,
)
],
)
],
),
),
);
}).toList();
}
final shipmentBoxTitle = Container(
padding: EdgeInsets.only(left: 15, right: 10.0, top: 20),
child: Row(
children: <Widget>[
Expanded(
child:
LocalText(context, 'box.shipment_number', color: Colors.grey),
),
LocalText(context, 'box.shipment.desc', color: Colors.grey),
],
),
);
final shipmentBoxRow = Container(
padding: EdgeInsets.only(left: 15.0, right: 10.0, top: 5.0, bottom: 5.0),
child: Row(
children: <Widget>[
Expanded(
child: new Text(
_selectedShipmentBox.shipmentNumber == null
? ""
: _selectedShipmentBox.shipmentNumber,
style: textStyle,
)),
new Text(
_selectedShipmentBox.desc == null ? "" : _selectedShipmentBox.desc,
style: textStyle,
),
],
),
);
final mixBoxTitle = Container(
padding: EdgeInsets.only(left: 15, right: 10.0, top: 20),
child: Row(
children: <Widget>[
Expanded(
child: LocalText(context, 'box.mix.number', color: Colors.grey),
),
LocalText(context, 'box.mix.desc', color: Colors.grey),
],
),
);
List<Widget> getMixBoxRowList() {
return _mixBoxes.asMap().entries.map((b) {
return Container(
color: Colors.grey[50].withOpacity(0.2),
child: Container(
padding: EdgeInsets.only(
left: 15.0, right: 10.0, top: 13.0, bottom: 13.0),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: b.key == _mixBoxes.length - 1
? Colors.white
: Colors.grey[350],
width: 1),
),
),
child: Row(
children: <Widget>[
Expanded(
child: new Text(
b.value.packageNumber,
style: textStyle,
)),
new Text(
b.value.desc == null ? "" : b.value.desc,
style: textStyle,
),
],
),
),
);
}).toList();
}
final cargoTitle = Container(
padding: EdgeInsets.only(left: 15, right: 0.0, top: 20),
child: Row(
children: <Widget>[
Expanded(
child: LocalText(context, 'cargo.type', color: Colors.grey),
),
Container(
padding: EdgeInsets.only(right: 10),
child: LocalText(context, 'cargo.weight', color: Colors.grey)),
],
),
);
List<Widget> getCargoRowList() {
if (_cargoTypes == null) {
return [];
}
double total = 0;
var rows = _cargoTypes.asMap().entries.map((c) {
total += c.value.weight;
return InkWell(
onTap: () {},
child: Container(
color: Colors.grey[50].withOpacity(0.2),
child: Container(
padding: EdgeInsets.only(
left: 15.0, right: 10.0, top: 13.0, bottom: 13.0),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.grey[350], width: 1),
),
),
child: Row(
children: <Widget>[
Expanded(
child: new Text(
c.value.name,
style: textStyle,
)),
Container(
padding: EdgeInsets.only(right: 10),
child: new Text(
c.value.weight == null ? "0" : c.value.weight.toString(),
style: textStyle,
),
)
],
),
),
),
);
}).toList();
var totalRow = InkWell(
child: Container(
color: Colors.grey[50].withOpacity(0.2),
child: Container(
padding:
EdgeInsets.only(left: 15.0, right: 10.0, top: 15.0, bottom: 15.0),
child: Row(
children: <Widget>[
Expanded(
child: new Text(
"Total Weight",
style: TextStyle(fontWeight: FontWeight.bold),
)),
Padding(
padding: const EdgeInsets.only(right: 10.0),
child: Align(
alignment: Alignment.centerRight,
child: new Text(
total.toString(),
style: TextStyle(fontWeight: FontWeight.bold),
),
),
)
],
),
),
));
rows.add(totalRow);
return rows;
}
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(
text: shipmentWeight != null ? shipmentWeight.toStringAsFixed(0) : "",
labelTextKey: "box.shipment_weight",
iconData: MaterialCommunityIcons.weight,
);
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,
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: _gotoEditor,
),
],
),
body: Card(
child: Column(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: ListView(children: <Widget>[
// Center(child: nameWidget(_box.packageNumber)),
SizedBox(
height: 10,
),
LocalTitle(textKey: "box.type.title"),
cargoType,
LocalTitle(textKey: "box.shipment_info"),
shipmentBox,
fcsIDBox,
customerNameBox,
_selectedCartonType == "From packages"
? Column(
children: [
LocalTitle(textKey: "box.packages"),
packageTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: getPackageRowList(),
),
],
)
: _selectedCartonType == "From shipments"
? Column(
children: [
LocalTitle(textKey: "box.shipment.boxes"),
shipmentBoxTitle,
Divider(
color: Colors.grey[400],
),
shipmentBoxRow
],
)
: _selectedCartonType == "Mix carton"
? Column(
children: [
LocalTitle(textKey: "box.shipment.boxes"),
mixBoxTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: getMixBoxRowList(),
)
],
)
: Container(),
LocalTitle(textKey: "box.cargo_type"),
cargoTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: getCargoRowList(),
),
LocalTitle(textKey: "box.dimension"),
dimBox,
shipmentWeightBox,
LocalTitle(textKey: "box.delivery_address"),
DefaultDeliveryAddress(
deliveryAddress: _deliveryAddress,
labelKey: "box.delivery_address",
),
LocalTitle(textKey: "box.status"),
Container(
height: 230,
child: Timeline(
children: _models(), position: TimelinePosition.Left),
),
SizedBox(
height: 20,
)
]),
)),
],
),
),
),
);
}
_gotoEditor() async {
Navigator.push(
context,
CupertinoPageRoute(builder: (context) => CartonEditor(box: widget.box)),
);
}
}