update processing

This commit is contained in:
Thinzar Win
2020-12-02 20:55:00 +06:30
parent 8e73ba2d8b
commit 42bb217c2c
26 changed files with 589 additions and 250 deletions

View File

@@ -0,0 +1,116 @@
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/rates/model/shipment_rate_model.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';
import 'package:provider/provider.dart';
class CargoTypeAddition extends StatefulWidget {
@override
_CargoTypeAdditionState createState() => _CargoTypeAdditionState();
}
class _CargoTypeAdditionState extends State<CargoTypeAddition> {
bool _isLoading = false;
List<CargoType> cargos = [];
@override
void initState() {
super.initState();
cargos =
Provider.of<ShipmentRateModel>(context, listen: false).rate.cargoTypes;
cargos.forEach((p) => p.isChecked = false);
}
@override
void dispose() {
super.dispose();
}
List<Widget> showcargoTypeList(BuildContext context) {
return this.cargos.map((c) {
return new ListTile(
contentPadding: EdgeInsets.all(0),
title: InkWell(
onTap: () {
setState(() {
c.isChecked = c.isChecked == null ? true : !c.isChecked;
});
},
child: new Row(
children: <Widget>[
new Checkbox(
value: c.isChecked == null ? false : c.isChecked,
activeColor: primaryColor,
onChanged: (bool value) {
setState(() {
c.isChecked = value;
});
}),
new Text(
c.name,
style: TextStyle(fontSize: 15.0, color: primaryColor),
),
],
),
));
}).toList();
}
@override
Widget build(BuildContext context) {
final saveBtn = fcsButton(
context,
getLocalString(context, 'box.cargo.save.btn'),
callack: () {
this.cargos.forEach((p) => p.weight = 0.00);
List<CargoType> _cargos =
this.cargos.where((c) => c.isChecked).toList();
Navigator.pop(context, _cargos);
},
);
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,
"cargo.form.title",
fontSize: 20,
color: primaryColor,
)),
body: Container(
padding: EdgeInsets.all(18),
child: ListView(
shrinkWrap: true,
children: <Widget>[
Column(
children: showcargoTypeList(context),
),
SizedBox(height: 30),
saveBtn,
SizedBox(height: 20),
],
),
),
),
);
}
// List<CargoType> cargoTypeList() {
// return this.privileges.where((p) => p.isChecked).map((p) => p.id).toList();
// }
}

View File

@@ -31,7 +31,7 @@ class _CargoTypeEditorState extends State<CargoTypeEditor> {
super.initState();
if (widget.cargo != null) {
_cargo = widget.cargo;
_weightController.text = _cargo.weight.toString();
_weightController.text = _cargo.weight.toStringAsFixed(2);
} else {
_loadDefalut();
}

View File

@@ -6,11 +6,12 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'cargo_type_editor.dart';
import 'total_weight_edit.dart';
typedef OnAdd(CargoType cargoType);
typedef OnRemove(CargoType cargoType);
class CargoTable extends StatelessWidget {
class CargoTable extends StatefulWidget {
final List<CargoType> cargoTypes;
final OnAdd onAdd;
final OnRemove onRemove;
@@ -18,6 +19,12 @@ class CargoTable extends StatelessWidget {
const CargoTable({Key key, this.cargoTypes, this.onAdd, this.onRemove})
: super(key: key);
@override
_CargoTableState createState() => _CargoTableState();
}
class _CargoTableState extends State<CargoTable> {
double totalWeight = 0;
@override
Widget build(BuildContext context) {
return MyDataTable(
@@ -43,12 +50,14 @@ class CargoTable extends StatelessWidget {
}
List<MyDataRow> getCargoRows(BuildContext context) {
if (cargoTypes == null) {
if (widget.cargoTypes == null) {
return [];
}
double total = 0;
var rows = cargoTypes.map((c) {
total += c.weight;
double _total = 0;
var rows = widget.cargoTypes.map((c) {
_total += c.weight;
return MyDataRow(
onSelectChanged: (bool selected) async {
CargoType cargo = await Navigator.push<CargoType>(
@@ -57,7 +66,7 @@ class CargoTable extends StatelessWidget {
builder: (context) => CargoTypeEditor(
cargo: c,
)));
if (onAdd != null) onAdd(cargo);
if (widget.onAdd != null) widget.onAdd(cargo);
},
cells: [
MyDataCell(new Text(
@@ -68,9 +77,8 @@ class CargoTable extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(c.weight == null ? "0" : c.weight.toString(),
style: textStyle),
onRemove == null
Text(c.weight.toStringAsFixed(2), style: textStyle),
widget.onRemove == null
? SizedBox(
width: 50,
)
@@ -80,7 +88,93 @@ class CargoTable extends StatelessWidget {
color: primaryColor,
),
onPressed: () {
if (onRemove != null) onRemove(c);
if (widget.onRemove != null) widget.onRemove(c);
})
],
),
),
],
);
}).toList();
var totalRow = MyDataRow(
onSelectChanged: (bool selected) async {
double _t = await Navigator.of(context).push<double>(CupertinoPageRoute(
builder: (context) => TotalWeightEdit(totalWeight: totalWeight)));
if (_t == null) return;
setState(() {
totalWeight = _t;
});
},
cells: [
MyDataCell(Align(
alignment: Alignment.centerRight,
child: LocalText(
context,
"shipment.cargo.total",
color: Colors.black87,
fontWeight: FontWeight.bold,
),
)),
MyDataCell(
Padding(
padding: const EdgeInsets.only(right: 48.0),
child: Align(
alignment: Alignment.centerRight,
child: Text(totalWeight.toStringAsFixed(2),
style: TextStyle(fontWeight: FontWeight.bold))),
),
),
],
);
rows.add(totalRow);
return rows;
}
double getRemainBalance(double total) {
double _r = this.totalWeight < total ? 0 : this.totalWeight - total;
return _r;
}
List<MyDataRow> _getCargoRows(BuildContext context) {
if (widget.cargoTypes == null) {
return [];
}
double total = 0;
var rows = widget.cargoTypes.map((c) {
total += c.weight;
return MyDataRow(
onSelectChanged: (bool selected) async {
CargoType cargo = await Navigator.push<CargoType>(
context,
CupertinoPageRoute(
builder: (context) => CargoTypeEditor(
cargo: c,
)));
if (widget.onAdd != null) widget.onAdd(cargo);
},
cells: [
MyDataCell(new Text(
c.name == null ? "" : c.name,
style: textStyle,
)),
MyDataCell(
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(c.weight == null ? "0" : c.weight.toStringAsFixed(2),
style: textStyle),
widget.onRemove == null
? SizedBox(
width: 50,
)
: IconButton(
icon: Icon(
Icons.remove_circle,
color: primaryColor,
),
onPressed: () {
if (widget.onRemove != null) widget.onRemove(c);
})
],
),
@@ -106,7 +200,7 @@ class CargoTable extends StatelessWidget {
padding: const EdgeInsets.only(right: 48.0),
child: Align(
alignment: Alignment.centerRight,
child: Text(total.toString(),
child: Text(total.toStringAsFixed(2),
style: TextStyle(fontWeight: FontWeight.bold))),
),
),

View File

@@ -3,31 +3,21 @@ import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/carton_size.dart';
import 'package:fcs/domain/entities/fcs_shipment.dart';
import 'package:fcs/domain/entities/market.dart';
import 'package:fcs/domain/entities/package.dart';
import 'package:fcs/domain/entities/user.dart';
import 'package:fcs/domain/vo/delivery_address.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/carton/carton_cargo_table.dart';
import 'package:fcs/pages/carton/carton_mix_table.dart';
import 'package:fcs/pages/carton/carton_package_table.dart';
import 'package:fcs/pages/carton_size/carton_size_list.dart';
import 'package:fcs/pages/delivery_address/delivery_address_list.dart';
import 'package:fcs/pages/delivery_address/delivery_address_row.dart';
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart';
import 'package:fcs/pages/main/model/language_model.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/market/model/market_model.dart';
import 'package:fcs/pages/package/model/package_model.dart';
import 'package:fcs/pages/package/tracking_id_page.dart';
import 'package:fcs/pages/rates/model/shipment_rate_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/defalut_delivery_address.dart';
import 'package:fcs/pages/widgets/delivery_address_selection.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';
@@ -36,19 +26,17 @@ import 'package:fcs/pages/widgets/local_dropdown.dart';
import 'package:fcs/pages/widgets/local_radio_buttons.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/local_title.dart';
import 'package:fcs/pages/widgets/my_data_table.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:provider/provider.dart';
import 'cargo_type_addtion.dart';
import 'cargo_type_editor.dart';
import 'model/carton_model.dart';
import '../carton_size/model/carton_size_model.dart';
import 'widgets.dart';
const MANAGE_CARTONSIZE = "Manage Carton Size";
class CartonEditor extends StatefulWidget {
final Carton box;
CartonEditor({this.box});
@@ -102,9 +90,9 @@ class _CartonEditorState extends State<CartonEditor> {
cargoTypes: [],
packages: [],
);
_lengthController.text = "12";
_widthController.text = "12";
_heightController.text = "12";
_lengthController.text = "";
_widthController.text = "";
_heightController.text = "";
_isNew = true;
_selectedCartonType = carton_from_packages;
_loadFcsShipments();
@@ -212,53 +200,60 @@ class _CartonEditorState extends State<CartonEditor> {
labelTextKey: "box.mix.carton",
iconData: MaterialCommunityIcons.package,
);
var fcsShipmentsBox = LocalDropdown<FcsShipment>(
callback: (v) {
setState(() {
_fcsShipment = v;
});
_loadMixCartons();
},
labelKey: "shipment.pack.fcs.shipment",
iconData: Ionicons.ios_airplane,
display: (u) => u.shipmentNumber,
selectedValue: _fcsShipment,
values: _fcsShipments,
);
var fcsShipmentsBox = Container(
padding: EdgeInsets.only(top: 10),
child: LocalDropdown<FcsShipment>(
callback: (v) {
setState(() {
_fcsShipment = v;
});
_loadMixCartons();
},
labelKey: "shipment.pack.fcs.shipment",
iconData: Ionicons.ios_airplane,
display: (u) => u.shipmentNumber,
selectedValue: _fcsShipment,
values: _fcsShipments,
));
var mixCartonsBox = LocalDropdown<Carton>(
callback: (v) {
setState(() {
_mixCarton = v;
});
},
labelKey: "box.mix.carton",
iconData: MaterialCommunityIcons.package,
display: (u) => u.cartonNumber,
selectedValue: _mixCarton,
values: _mixCartons,
);
var mixCartonsBox = Container(
padding: EdgeInsets.only(top: 10),
child: LocalDropdown<Carton>(
callback: (v) {
setState(() {
_mixCarton = v;
});
},
labelKey: "box.mix.carton",
iconData: MaterialCommunityIcons.package,
display: (u) => u.cartonNumber,
selectedValue: _mixCarton,
values: _mixCartons,
));
final fcsIDBox = Row(
children: <Widget>[
Expanded(
child: DisplayText(
text: _user?.fcsID ?? "",
labelTextKey: "box.fcs.id",
icon: FcsIDIcon(),
)),
_isNew
? IconButton(
icon: Icon(Icons.search, color: primaryColor),
onPressed: () => searchUser(context, callbackUserSelect: (u) {
setState(() {
this._user = u;
_loadPackages();
});
}))
: Container(),
],
);
final fcsIDBox = Container(
padding: EdgeInsets.only(top: 10),
child: Row(
children: <Widget>[
Expanded(
child: DisplayText(
text: _user?.fcsID ?? "",
labelTextKey: "box.fcs.id",
icon: FcsIDIcon(),
)),
_isNew
? IconButton(
icon: Icon(Icons.search, color: primaryColor),
onPressed: () =>
searchUser(context, callbackUserSelect: (u) {
setState(() {
this._user = u;
_loadPackages();
});
}))
: Container(),
],
));
final namebox = DisplayText(
text: _user?.name ?? "",
@@ -269,14 +264,17 @@ class _CartonEditorState extends State<CartonEditor> {
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(
@@ -293,7 +291,7 @@ class _CartonEditorState extends State<CartonEditor> {
);
final shipmentWeightBox = DisplayText(
text: shipmentWeight != null ? shipmentWeight.toStringAsFixed(0) : "",
text: shipmentWeight != null ? shipmentWeight.toStringAsFixed(2) : "",
labelTextKey: "box.shipment_weight",
iconData: MaterialCommunityIcons.weight,
);
@@ -326,9 +324,17 @@ class _CartonEditorState extends State<CartonEditor> {
color: primaryColor,
),
onPressed: () async {
CargoType cargo = await Navigator.push<CargoType>(context,
CupertinoPageRoute(builder: (context) => CargoTypeEditor()));
_addCargo(cargo);
// CargoType cargo = await Navigator.push<CargoType>(context,
// CupertinoPageRoute(builder: (context) => CargoTypeEditor()));
// _addCargo(cargo);
List<CargoType> cargos = await Navigator.push<List<CargoType>>(
context,
CupertinoPageRoute(builder: (context) => CargoTypeAddition()));
if (cargos == null) return;
setState(() {
_carton.cargoTypes.clear();
_carton.cargoTypes.addAll(cargos);
});
}),
);
@@ -414,7 +420,7 @@ class _CartonEditorState extends State<CartonEditor> {
? Container()
: LocalTitle(textKey: "box.dimension"),
isSmallBag ? Container() : cartonSizeDropdown(),
// isSmallBag ? Container() : dimBox,
isSmallBag ? Container() : dimBox,
isSmallBag ? Container() : shipmentWeightBox,
LocalTitle(textKey: "box.delivery_address"),
DefaultDeliveryAddress(
@@ -445,16 +451,13 @@ class _CartonEditorState extends State<CartonEditor> {
);
}
String selectedCatonSize;
CartonSize selectedCatonSize;
Widget cartonSizeDropdown() {
List<CartonSize> _cartonSizes =
Provider.of<CartonSizeModel>(context).cartonSizes;
List<String> cartonSizes = _cartonSizes.map((e) => e.name).toList();
cartonSizes.insert(0, MANAGE_CARTONSIZE);
Provider.of<CartonSizeModel>(context).getCartonSizes;
return Padding(
padding: const EdgeInsets.only(top: 10, bottom: 10),
padding: const EdgeInsets.only(top: 10),
child: Row(
children: [
Padding(
@@ -474,7 +477,7 @@ class _CartonEditorState extends State<CartonEditor> {
fontSize: 16,
),
),
DropdownButton<String>(
DropdownButton<CartonSize>(
isDense: true,
value: selectedCatonSize,
style: TextStyle(color: Colors.black, fontSize: 14),
@@ -482,25 +485,31 @@ class _CartonEditorState extends State<CartonEditor> {
height: 1,
color: Colors.grey,
),
onChanged: (String newValue) {
onChanged: (CartonSize newValue) {
setState(() {
if (newValue == MANAGE_CARTONSIZE) {
if (newValue.name == MANAGE_CARTONSIZE) {
selectedCatonSize = null;
_manageCartonSize();
return;
}
selectedCatonSize = newValue;
_widthController.text =
selectedCatonSize.width.toString();
_heightController.text =
selectedCatonSize.height.toString();
_lengthController.text =
selectedCatonSize.length.toString();
});
},
isExpanded: true,
items:
cartonSizes.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
items: _cartonSizes
.map<DropdownMenuItem<CartonSize>>((CartonSize value) {
return DropdownMenuItem<CartonSize>(
value: value,
child: Text(value ?? "",
child: Text(value.name ?? "",
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: value == MANAGE_CARTONSIZE
color: value.name == MANAGE_CARTONSIZE
? secondaryColor
: primaryColor)),
);

View File

@@ -177,7 +177,7 @@ class _CartonInfoState extends State<CartonInfo> {
);
final shipmentWeightBox = DisplayText(
text: shipmentWeight != null ? shipmentWeight.toStringAsFixed(0) : "",
text: shipmentWeight != null ? shipmentWeight.toStringAsFixed(2) : "",
labelTextKey: "box.shipment_weight",
iconData: MaterialCommunityIcons.weight,
);

View File

@@ -78,7 +78,7 @@ class CartonListRow extends StatelessWidget {
child: Row(
children: <Widget>[
new Text(
"${box.actualWeight?.toString() ?? ''} lb",
"${box.actualWeight?.toStringAsFixed(2) ?? ''} lb",
style:
new TextStyle(fontSize: 15.0, color: Colors.grey),
),

View File

@@ -0,0 +1,86 @@
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/widgets/input_text.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';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:fcs/pages/main/util.dart';
typedef void ProfileCallback();
class TotalWeightEdit extends StatefulWidget {
final double totalWeight;
const TotalWeightEdit({Key key, this.totalWeight}) : super(key: key);
@override
_TotalWeightEditState createState() => _TotalWeightEditState();
}
class _TotalWeightEditState extends State<TotalWeightEdit> {
final TextEditingController totalController = new TextEditingController();
bool _loading = false;
@override
void initState() {
super.initState();
totalController.text = widget.totalWeight.toStringAsFixed(2);
}
@override
Widget build(BuildContext context) {
final totalInputBox = InputText(
labelTextKey: 'shipment.cargo.total',
iconData: FontAwesomeIcons.weightHanging,
textInputType: TextInputType.number,
controller: totalController);
final saveBtn =
fcsButton(context, getLocalString(context, "btn.save"), callack: _save);
return LocalProgress(
inAsyncCall: _loading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
title: LocalText(
context,
"box.cargo_total_title",
fontSize: 20,
color: primaryColor,
),
backgroundColor: Colors.white,
shadowColor: Colors.transparent,
leading: IconButton(
icon: Icon(
CupertinoIcons.back,
size: 35,
color: primaryColor,
),
onPressed: () => Navigator.of(context).pop(),
),
),
body: ListView(
padding: EdgeInsets.all(18),
children: <Widget>[totalInputBox, SizedBox(height: 30), saveBtn],
),
),
);
}
_save() async {
setState(() {
_loading = true;
});
try {
double total = double.parse(totalController.text, (s) => 0);
Navigator.pop<double>(context, total);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_loading = false;
});
}
}
}