Files
fcs/lib/pages/box/box_editor.dart

666 lines
21 KiB
Dart
Raw Normal View History

2020-10-07 02:33:06 +06:30
import 'package:fcs/domain/entities/box.dart';
import 'package:fcs/domain/entities/cargo.dart';
import 'package:fcs/domain/entities/package.dart';
2020-10-09 17:28:42 +06:30
import 'package:fcs/domain/entities/user.dart';
2020-10-08 11:38:05 +06:30
import 'package:fcs/domain/vo/delivery_address.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart';
2020-10-09 17:28:42 +06:30
import 'package:fcs/pages/delivery_address/delivery_address_list.dart';
2020-10-08 15:54:43 +06:30
import 'package:fcs/pages/delivery_address/delivery_address_row.dart';
2020-10-09 17:28:42 +06:30
import 'package:fcs/pages/main/model/language_model.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/main/util.dart';
2020-10-09 17:28:42 +06:30
import 'package:fcs/pages/package/model/package_model.dart';
import 'package:fcs/pages/user_search/user_serach.dart';
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
import 'package:fcs/pages/widgets/display_text.dart';
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
import 'package:fcs/pages/widgets/input_text.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/my_data_table.dart';
import 'package:fcs/pages/widgets/progress.dart';
2020-06-04 01:36:49 +06:30
import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:timeline_list/timeline.dart';
import 'package:timeline_list/timeline_model.dart';
2020-10-09 17:28:42 +06:30
import 'cargo_type_editor.dart';
2020-06-04 01:36:49 +06:30
class BoxEditor extends StatefulWidget {
final Box box;
BoxEditor({this.box});
@override
_BoxEditorState createState() => _BoxEditorState();
}
class _BoxEditorState extends State<BoxEditor> {
2020-10-09 17:28:42 +06:30
TextEditingController _widthController = new TextEditingController();
TextEditingController _heightController = new TextEditingController();
TextEditingController _lengthController = new TextEditingController();
2020-06-04 01:36:49 +06:30
Box _box;
bool _isLoading = false;
bool isNew;
2020-06-25 16:19:23 +06:30
bool isMixBox = false;
2020-10-09 17:28:42 +06:30
DeliveryAddress _deliveryAddress = new DeliveryAddress();
User user;
String selectShipmentNumber;
List<Package> _packages = [];
2020-06-25 16:19:23 +06:30
2020-06-04 01:36:49 +06:30
@override
void initState() {
super.initState();
2020-10-09 17:28:42 +06:30
var packageModel = Provider.of<PackageModel>(context, listen: false);
_packages = [
packageModel.packages[0],
packageModel.packages[1],
packageModel.packages[2],
packageModel.packages[8]
];
_packages.forEach((p) {
p.isChecked = false;
});
2020-06-04 01:36:49 +06:30
if (widget.box != null) {
_box = widget.box;
2020-10-09 17:28:42 +06:30
_deliveryAddress = _box.shippingAddress;
2020-06-04 01:36:49 +06:30
isNew = false;
2020-10-09 17:28:42 +06:30
selectShipmentNumber = _box.shipmentNumber;
_widthController.text = _box.width.toString();
_heightController.text = _box.height.toString();
_lengthController.text = _box.length.toString();
2020-06-04 01:36:49 +06:30
} else {
2020-06-25 16:19:23 +06:30
List<Cargo> _cargoTypes = [
Cargo(type: 'General Cargo', weight: 25),
Cargo(type: 'Medicine', weight: 20),
Cargo(type: 'Dangerous Cargo', weight: 30)
];
2020-10-09 17:28:42 +06:30
_deliveryAddress = DeliveryAddress(
fullName: 'U Nyi Nyi',
addressLine1: '154-19 64th Ave.',
addressLine2: 'Flushing',
city: 'NY',
state: 'NY',
phoneNumber: '+1 (292)215-2247');
2020-06-26 16:17:40 +06:30
2020-06-04 01:36:49 +06:30
isNew = true;
2020-06-25 16:19:23 +06:30
_box = Box(
2020-06-29 16:15:25 +06:30
rate: 0,
weight: 75,
width: 0,
height: 0,
length: 0,
cargoTypes: _cargoTypes,
shipmentWeight: 0);
2020-06-04 01:36:49 +06:30
}
}
@override
void dispose() {
super.dispose();
}
final DateFormat dateFormat = DateFormat("d MMM yyyy");
List<TimelineModel> _models() {
// return [];
2020-10-07 02:33:06 +06:30
return _box.shipmentHistory
2020-06-04 01:36:49 +06:30
.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) {
2020-10-09 17:28:42 +06:30
var languageModel = Provider.of<LanguageModel>(context);
var shipmentBox = Container(
child: Padding(
padding: const EdgeInsets.only(left: 10.0),
child: DropdownButtonFormField(
value: selectShipmentNumber,
decoration: InputDecoration(
fillColor: Colors.white,
labelText:
AppTranslations.of(context).text("box.fcs_shipment_num"),
labelStyle: languageModel.isEng
? TextStyle(fontWeight: FontWeight.w500)
: TextStyle(
fontWeight: FontWeight.w500, fontFamily: "Myanmar3"),
icon: Icon(
Ionicons.ios_airplane,
color: primaryColor,
)),
items: ["A102", "A103", "A201", "A202"]
.map((e) => DropdownMenuItem(
child: Text(
e,
style: TextStyle(color: primaryColor),
),
value: e))
.toList(),
onChanged: (value) {
setState(() {
selectShipmentNumber = value;
});
},
)));
final mixBox = Container(
child: new Row(
children: <Widget>[
new Checkbox(
value: isMixBox,
activeColor: primaryColor,
onChanged: (bool value) {
setState(() {
isMixBox = value;
});
}),
SizedBox(
width: 5,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text(
"Mix Box",
style: TextStyle(fontSize: 15.0),
),
],
),
],
),
);
final fcsIDBox = Container(
padding: EdgeInsets.only(left: 10),
child: Row(
children: <Widget>[
Expanded(
child: DisplayText(
text: user != null ? user.fcsID : "",
labelTextKey: "box.fcs.id",
icon: FcsIDIcon(),
)),
IconButton(
icon: Icon(Icons.search, color: primaryColor),
onPressed: () => searchUser(context, callbackUserSelect: (u) {
setState(() {
this.user = u;
});
})),
],
));
final phoneNumberBox = Container(
padding: EdgeInsets.only(left: 10),
child: DisplayText(
text: user != null ? user.phoneNumber : "",
labelTextKey: "box.phone",
iconData: Icons.phone,
));
final namebox = Container(
padding: EdgeInsets.only(left: 10),
child: DisplayText(
text: user != null ? user.name : "",
labelTextKey: "box.name",
iconData: Icons.person,
));
final packageTitle = Container(
padding: EdgeInsets.only(right: 10.0, top: 20),
child: Row(
children: <Widget>[
Container(
width: 50,
),
Expanded(
child: LocalText(context, 'box.tracking.id', color: Colors.grey),
),
LocalText(context, 'box.market', color: Colors.grey),
],
),
);
List<Widget> getPackageRowList() {
return _packages.asMap().entries.map((p) {
return Container(
color: p.value.isChecked
? Colors.grey.withOpacity(0.2)
: Colors.grey[50].withOpacity(0.2),
child: Container(
padding:
EdgeInsets.only(left: 0.0, right: 10.0, top: 3.0, bottom: 3.0),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: p.key == _packages.length - 1
? Colors.white
: Colors.grey[350],
width: 1),
),
),
child: Row(
children: <Widget>[
Checkbox(
value: p.value.isChecked,
activeColor: primaryColor,
onChanged: (bool check) {
setState(() {
p.value.isChecked = check;
});
}),
Expanded(
child: new Text(
p.value.trackingID,
style: textStyle,
)),
new Text(
p.value.market == null ? "" : p.value.market,
style: textStyle,
)
],
),
),
);
}).toList();
}
final actualWeightBox = Container(
padding: EdgeInsets.only(left: 10),
child: DisplayText(
text: _box.weight != null ? _box.weight.toString() : "",
labelTextKey: "box.actual_weight",
iconData: FontAwesomeIcons.weightHanging,
));
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),
),
LocalText(context, 'cargo.weight', color: Colors.grey),
],
),
);
List<Widget> getCargoRowList() {
return _box.cargoTypes.asMap().entries.map((c) {
return InkWell(
onTap: () {
Navigator.push(
context,
BottomUpPageRoute(CargoTypeEditor(cargo: c.value)),
);
},
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),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.grey[350], width: 1),
),
),
child: Row(
children: <Widget>[
Expanded(
child: new Text(
c.value.type,
style: textStyle,
)),
new Text(
c.value.weight == null ? "0" : c.value.weight.toString(),
style: textStyle,
)
],
),
),
),
);
}).toList();
}
final shipmentWeightBox = Container(
padding: EdgeInsets.only(left: 10),
child: DisplayText(
text:
_box.shipmentWeight != null ? _box.shipmentWeight.toString() : "",
labelTextKey: "box.shipment_weight",
iconData: FontAwesomeIcons.weightHanging,
));
final widthBox = InputText(
labelTextKey: 'box.width',
iconData: FontAwesomeIcons.arrowCircleRight,
controller: _widthController);
final heightBox = InputText(
labelTextKey: 'box.height',
iconData: FontAwesomeIcons.arrowAltCircleUp,
controller: _heightController);
final lengthBox = InputText(
labelTextKey: 'box.length',
iconData: FontAwesomeIcons.arrowCircleUp,
controller: _lengthController);
final createBtn = fcsButton(
context,
getLocalString(context, 'box.create.btn'),
callack: () {},
);
final completeBtn = fcsButton(
context,
getLocalString(context, 'box.complete.btn'),
callack: () {},
);
final deliveryBtn = fcsButton(
context,
getLocalString(context, 'box.deliver.btn'),
callack: () {},
);
2020-06-04 01:36:49 +06:30
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
2020-10-09 17:28:42 +06:30
icon: new Icon(Icons.close, color: primaryColor, size: 30),
2020-06-04 01:36:49 +06:30
onPressed: () => Navigator.of(context).pop(),
),
2020-10-09 17:28:42 +06:30
shadowColor: Colors.transparent,
backgroundColor: Colors.white,
title: widget.box == null
? LocalText(
context,
"boxes.new",
fontSize: 20,
color: primaryColor,
)
: LocalText(
context,
"box.edit.title",
fontSize: 20,
color: primaryColor,
),
2020-06-04 01:36:49 +06:30
),
2020-10-09 17:28:42 +06:30
body: Padding(
padding: const EdgeInsets.only(left: 12.0, right: 12),
child: ListView(
shrinkWrap: true,
children: [
2020-06-04 01:36:49 +06:30
widget.box == null
2020-10-09 17:28:42 +06:30
? Container()
2020-06-04 01:36:49 +06:30
: Center(child: nameWidget(_box.packageNumber)),
2020-10-09 17:28:42 +06:30
Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: LocalText(
context,
"box.shipment_info",
color: primaryColor,
fontSize: 16,
fontWeight: FontWeight.w700,
),
),
),
Column(
children: [
shipmentBox,
SizedBox(
height: 10,
),
fcsIDBox,
phoneNumberBox,
namebox,
mixBox,
],
),
Divider(),
Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: LocalText(
context,
"box.packages",
color: primaryColor,
fontSize: 16,
fontWeight: FontWeight.w700,
),
),
),
Column(
children: [
packageTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: getPackageRowList(),
),
SizedBox(height: 15),
],
),
Divider(),
Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: LocalText(
context,
"box.cargo_type",
color: primaryColor,
fontSize: 16,
fontWeight: FontWeight.w700,
),
),
),
Column(
children: [
actualWeightBox,
cargoTitle,
Divider(
color: Colors.grey[400],
),
Column(
children: _box == null || _box.cargoTypes == null
? []
: getCargoRowList(),
),
Container(
padding: EdgeInsets.only(top: 25),
child: Align(
alignment: Alignment.bottomRight,
child: FloatingActionButton.extended(
icon: Icon(Icons.add),
heroTag: "add cargo",
label: LocalText(
context,
"box.add_cargo",
color: Colors.white,
2020-06-04 01:36:49 +06:30
),
2020-10-09 17:28:42 +06:30
backgroundColor: primaryColor,
onPressed: () {
Navigator.push(
context,
BottomUpPageRoute(CargoTypeEditor()),
);
},
2020-06-04 01:36:49 +06:30
),
),
2020-10-09 17:28:42 +06:30
),
SizedBox(height: 25),
],
),
Divider(),
Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: LocalText(
context,
"box.dimension",
color: primaryColor,
fontSize: 16,
fontWeight: FontWeight.w700,
),
),
),
Column(
children: [
shipmentWeightBox,
widthBox,
heightBox,
lengthBox,
SizedBox(height: 25),
],
),
Divider(),
Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: LocalText(
context,
"box.delivery_address",
color: primaryColor,
fontSize: 16,
fontWeight: FontWeight.w700,
),
),
),
Column(
children: [
2020-10-11 02:17:23 +06:30
DeliveryAddressRow(deliveryAddress: _deliveryAddress),
2020-10-09 17:28:42 +06:30
Container(
padding: EdgeInsets.only(top: 20, bottom: 15, right: 15),
child: Align(
alignment: Alignment.bottomRight,
child: Container(
width: 130,
height: 40,
child: FloatingActionButton.extended(
materialTapTargetSize:
MaterialTapTargetSize.shrinkWrap,
onPressed: () async {
DeliveryAddress deliveryAddress =
await Navigator.push(
context,
2020-10-13 07:50:25 +06:30
BottomUpPageRoute(DeliveryAddressList()),
2020-10-09 17:28:42 +06:30
);
setState(() {
_deliveryAddress = deliveryAddress;
});
},
icon: Icon(Icons.add),
label: LocalText(context, "box.change_address",
color: Colors.white),
backgroundColor: primaryColor,
),
2020-06-25 16:19:23 +06:30
),
2020-10-09 17:28:42 +06:30
),
),
SizedBox(height: 10),
],
),
Divider(),
isNew
? Container()
: Column(
2020-06-25 16:19:23 +06:30
children: [
2020-06-29 16:15:25 +06:30
Padding(
2020-10-09 17:28:42 +06:30
padding: const EdgeInsets.all(8.0),
child: LocalText(
context,
"box.status",
color: primaryColor,
fontSize: 16,
fontWeight: FontWeight.w700,
),
2020-06-25 16:19:23 +06:30
),
2020-06-26 16:17:40 +06:30
Container(
2020-10-09 17:28:42 +06:30
height: 230,
padding: EdgeInsets.only(left: 10),
child: isNew
? Container()
: Timeline(
children: _models(),
position: TimelinePosition.Left),
2020-06-26 16:17:40 +06:30
),
],
),
2020-10-09 17:28:42 +06:30
isNew ? Container() : Divider(),
SizedBox(
height: 10,
2020-06-04 01:36:49 +06:30
),
widget.box == null
2020-10-09 17:28:42 +06:30
? createBtn
2020-06-04 01:36:49 +06:30
: Container(
child: Column(
children: <Widget>[
2020-10-09 17:28:42 +06:30
completeBtn,
2020-06-26 16:17:40 +06:30
widget.box.status == 'Arrived'
2020-10-09 17:28:42 +06:30
? deliveryBtn
2020-06-26 16:17:40 +06:30
: Container(),
2020-06-04 01:36:49 +06:30
],
2020-06-26 16:17:40 +06:30
)),
2020-10-09 17:28:42 +06:30
SizedBox(
height: 20,
),
2020-06-04 01:36:49 +06:30
],
),
),
),
);
}
2020-06-26 16:17:40 +06:30
List<Widget> getAddressList(
2020-10-08 11:38:05 +06:30
BuildContext context, List<DeliveryAddress> addresses) {
2020-06-26 16:17:40 +06:30
return addresses.asMap().entries.map((s) {
return InkWell(
onTap: () {},
2020-10-11 02:17:23 +06:30
child: DeliveryAddressRow(deliveryAddress: s.value),
2020-06-26 16:17:40 +06:30
);
}).toList();
}
2020-06-04 01:36:49 +06:30
}