454 lines
15 KiB
Dart
454 lines
15 KiB
Dart
import 'package:fcs/domain/constants.dart';
|
|
import 'package:fcs/domain/entities/cargo_type.dart';
|
|
import 'package:fcs/domain/entities/carton.dart';
|
|
import 'package:fcs/domain/entities/package.dart';
|
|
import 'package:fcs/helpers/theme.dart';
|
|
import 'package:fcs/pages/carton/carton_image_upload.dart';
|
|
import 'package:fcs/pages/main/util.dart';
|
|
import 'package:fcs/pages/package/model/package_model.dart';
|
|
import 'package:fcs/pages/widgets/display_text.dart';
|
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
import 'package:fcs/pages/widgets/multi_img_controller.dart';
|
|
import 'package:fcs/pages/widgets/multi_img_file.dart';
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../widgets/local_button.dart';
|
|
import 'mix_carton/mix_carton_editor.dart';
|
|
import 'model/carton_model.dart';
|
|
|
|
class CartonInfo extends StatefulWidget {
|
|
final Carton carton;
|
|
CartonInfo({required this.carton});
|
|
|
|
@override
|
|
_CartonInfoState createState() => _CartonInfoState();
|
|
}
|
|
|
|
class _CartonInfoState extends State<CartonInfo> {
|
|
final DateFormat dateFormat = DateFormat("d MMM yyyy");
|
|
final NumberFormat numberFormatter = NumberFormat("#,###");
|
|
MultiImgController multiImgController = MultiImgController();
|
|
|
|
bool _isLoading = false;
|
|
late Carton _carton;
|
|
|
|
List<CargoType> _cargoTypes = [];
|
|
List<CargoType> _surchareItems = [];
|
|
List<Carton> _mixCartons = [];
|
|
List<Package> _packages = [];
|
|
|
|
@override
|
|
void initState() {
|
|
_carton = widget.carton;
|
|
_init();
|
|
super.initState();
|
|
}
|
|
|
|
_init() async {
|
|
_carton.billTo = billToSender;
|
|
_carton.cartonType = carton_from_packages;
|
|
multiImgController.setImageUrls = _carton.photos;
|
|
_cargoTypes = _carton.cargoTypes.where((e) => !e.isCutomDuty).toList();
|
|
_surchareItems = _carton.cargoTypes.where((e) => e.isCutomDuty).toList();
|
|
if (_carton.cartonType == carton_from_packages) {
|
|
_packages = await context
|
|
.read<PackageModel>()
|
|
.getPackagesByIds(_carton.packageIDs);
|
|
}
|
|
|
|
if (_carton.cartonType == carton_mix_carton) {
|
|
_mixCartons = await context
|
|
.read<CartonModel>()
|
|
.getCartonsByIds(_carton.mixCartonIDs);
|
|
}
|
|
|
|
if (mounted) {
|
|
setState(() {});
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
double totalWeight =
|
|
_carton.cargoTypes.fold(0, (sum, value) => sum + value.weight);
|
|
double totalSurchargeCount =
|
|
_surchareItems.fold(0, (sum, value) => sum + value.qty);
|
|
|
|
final cartonTypeBox = DisplayText(
|
|
text: _carton.cartonNumber,
|
|
labelTextKey: "box.number",
|
|
);
|
|
|
|
final cartonQrBox = DisplayText(iconData: AntDesign.qrcode);
|
|
|
|
final shipmentBox = DisplayText(
|
|
text: _carton.fcsShipmentNumber,
|
|
labelTextKey: "box.fcs_shipment_num",
|
|
);
|
|
|
|
final deliveryBox = DisplayText(
|
|
text: "Delivery Carton",
|
|
labelTextKey: "box.delivery_type",
|
|
);
|
|
|
|
final senderBox = DisplayText(
|
|
text: _carton.userName == null ? "" : _carton.userName,
|
|
subText: Text(_carton.fcsID ?? "", style: textStyle),
|
|
labelTextKey: "box.name",
|
|
);
|
|
|
|
final consigneeNameBox = DisplayText(
|
|
text: _carton.senderName != null ? _carton.senderName : "",
|
|
subText: Text(_carton.senderFCSID ?? "", style: textStyle),
|
|
labelTextKey: "processing.consignee.name",
|
|
);
|
|
|
|
final billWidget = Expanded(
|
|
child: Padding(
|
|
padding: EdgeInsets.only(left: 0, top: 15),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Icon(Ionicons.document_text_outline,
|
|
color: primaryColor, size: 20),
|
|
Text("Bill to",
|
|
style: TextStyle(color: primaryColor, fontSize: 15))
|
|
],
|
|
)));
|
|
|
|
final userRowBox = Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
senderBox,
|
|
],
|
|
),
|
|
),
|
|
_carton.billTo == billToSender ? billWidget : const SizedBox()
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
consigneeNameBox,
|
|
],
|
|
),
|
|
),
|
|
_carton.billTo == billToConsignee ? billWidget : const SizedBox()
|
|
],
|
|
))
|
|
],
|
|
);
|
|
|
|
final cargosBox = Padding(
|
|
padding: const EdgeInsets.only(top: 15),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
LocalText(context, 'box.cargo.type',
|
|
color: Colors.black54,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.normal),
|
|
Padding(
|
|
padding: EdgeInsets.only(right: 100),
|
|
child: Text("${removeTrailingZeros(totalWeight)} lb",
|
|
style: TextStyle(color: Colors.black54, fontSize: 15)))
|
|
],
|
|
),
|
|
//),
|
|
Container(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(right: 100),
|
|
child: Column(
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: _cargoTypes.map((e) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 3),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
e.name ?? "",
|
|
style:
|
|
TextStyle(color: Colors.black, fontSize: 15),
|
|
),
|
|
Text("${removeTrailingZeros(e.weight)} lb",
|
|
style: TextStyle(
|
|
color: Colors.black, fontSize: 15))
|
|
],
|
|
),
|
|
);
|
|
}).toList()),
|
|
const SizedBox(height: 10),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
]),
|
|
);
|
|
final surchargeItemBox = Padding(
|
|
padding: const EdgeInsets.only(top: 15),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
LocalText(context, 'box.surcharge.item',
|
|
color: Colors.black54,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.normal),
|
|
Padding(
|
|
padding: EdgeInsets.only(right: 100),
|
|
child: Text("${removeTrailingZeros(totalSurchargeCount)} pcs",
|
|
style: TextStyle(color: Colors.black54, fontSize: 15)))
|
|
],
|
|
),
|
|
//),
|
|
Container(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(right: 100),
|
|
child: Column(
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: _surchareItems.map((e) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 3),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
e.name ?? "",
|
|
style:
|
|
TextStyle(color: Colors.black, fontSize: 15),
|
|
),
|
|
Text(
|
|
"${removeTrailingZeros((e.qty).toDouble())} pc",
|
|
style: TextStyle(
|
|
color: Colors.black, fontSize: 15))
|
|
],
|
|
),
|
|
);
|
|
}).toList()),
|
|
const SizedBox(height: 10),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: _surchareItems.map((e) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 3),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
e.name ?? "",
|
|
style: TextStyle(color: labelColor, fontSize: 15),
|
|
),
|
|
Text("${numberFormatter.format(e.qty)} pc",
|
|
style:
|
|
TextStyle(color: labelColor, fontSize: 15))
|
|
],
|
|
),
|
|
);
|
|
}).toList()),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
]),
|
|
);
|
|
|
|
final img = MultiImageFile(
|
|
enabled: false,
|
|
controller: multiImgController,
|
|
title: "Receipt File",
|
|
);
|
|
|
|
final uploadImageBtn = Padding(
|
|
padding: EdgeInsets.only(left: 200.0, right: 8.0),
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Color(0xff272262),
|
|
elevation: 3,
|
|
shape:
|
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
|
|
minimumSize: Size(10, 35),
|
|
),
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => CartonImageUpload(box: _carton)),
|
|
);
|
|
},
|
|
child: const Text('Upload Images'),
|
|
),
|
|
);
|
|
|
|
final deleteBtn = Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 30),
|
|
child: LocalButton(
|
|
color: dangerColor,
|
|
textKey: "box.delete.btn",
|
|
callBack: () {
|
|
_delete();
|
|
},
|
|
),
|
|
);
|
|
|
|
return LocalProgress(
|
|
inAsyncCall: _isLoading,
|
|
child: Scaffold(
|
|
appBar: LocalAppBar(
|
|
labelKey: "box.info.title",
|
|
backgroundColor: Colors.white,
|
|
labelColor: primaryColor,
|
|
arrowColor: primaryColor,
|
|
actions: <Widget>[
|
|
IconButton(
|
|
icon: Icon(Icons.edit, color: primaryColor),
|
|
onPressed: _gotoEditor),
|
|
]),
|
|
body: Container(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: ListView(children: <Widget>[
|
|
Row(children: [
|
|
Flexible(child: cartonTypeBox),
|
|
Flexible(
|
|
child: cartonQrBox,
|
|
),
|
|
]),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Flexible(child: shipmentBox),
|
|
Flexible(child: deliveryBox),
|
|
],
|
|
),
|
|
userRowBox,
|
|
_packages.isEmpty
|
|
? const SizedBox()
|
|
: Padding(
|
|
padding: const EdgeInsets.only(top: 15),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
LocalText(context, "box.package",
|
|
color: Colors.black54, fontSize: 15),
|
|
const SizedBox(height: 5),
|
|
Column(
|
|
children: getPackageList(_packages),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
_mixCartons.isEmpty
|
|
? const SizedBox()
|
|
: Padding(
|
|
padding: const EdgeInsets.only(top: 15),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
LocalText(context, "box.shipment.boxes",
|
|
color: Colors.black54, fontSize: 15),
|
|
const SizedBox(height: 5),
|
|
Column(children: getCartonList(_mixCartons)),
|
|
],
|
|
),
|
|
),
|
|
_cargoTypes.isEmpty ? const SizedBox() : cargosBox,
|
|
_surchareItems.isEmpty ? const SizedBox() : surchargeItemBox,
|
|
uploadImageBtn,
|
|
img,
|
|
deleteBtn
|
|
]))));
|
|
}
|
|
|
|
List<Widget> getPackageList(List<Package> list) {
|
|
return list.map((p) {
|
|
return Container(
|
|
padding: EdgeInsets.only(top: 0),
|
|
child: Container(
|
|
child: Row(children: <Widget>[new Text(p.trackingID ?? "")]),
|
|
));
|
|
}).toList();
|
|
}
|
|
|
|
List<Widget> getCartonList(List<Carton> list) {
|
|
return list.map((c) {
|
|
return Container(
|
|
padding: EdgeInsets.only(top: 0),
|
|
child: Container(
|
|
child: Row(children: <Widget>[new Text(c.cartonNumber ?? '')]),
|
|
));
|
|
}).toList();
|
|
}
|
|
|
|
_gotoEditor() async {
|
|
if (_carton.cartonType == carton_mix_carton) {
|
|
bool? updated = await Navigator.push<bool>(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => MixCartonEditor(carton: _carton)),
|
|
);
|
|
}
|
|
// bool? updated = await Navigator.push<bool>(
|
|
// context,
|
|
// CupertinoPageRoute(
|
|
// builder: (context) => MixCartonEditor(carton: _carton)),
|
|
// );
|
|
// if (updated ?? false) {
|
|
// // var cartonModel = Provider.of<CartonModel>(context, listen: false);
|
|
// // var c = await cartonModel.getCarton(widget.box.id ?? "");
|
|
// // setState(() {
|
|
// // _box = c;
|
|
// // _loadPackages();
|
|
// // _loadMixCartons();
|
|
// // _updateBoxData();
|
|
// // });
|
|
// }
|
|
}
|
|
|
|
_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.carton);
|
|
// Navigator.pop(context, true);
|
|
} catch (e) {
|
|
showMsgDialog(context, "Error", e.toString());
|
|
} finally {
|
|
setState(() {
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
}
|
|
}
|