Files
fcs/lib/pages/rates/shipment_rates_edit.dart

443 lines
17 KiB
Dart
Raw Normal View History

2020-10-15 03:06:13 +06:30
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/custom_duty.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/domain/entities/discount.dart';
2020-10-15 03:06:13 +06:30
import 'package:fcs/domain/entities/discount_by_weight.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/domain/entities/rate.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
2020-10-07 18:49:28 +06:30
import 'package:fcs/pages/widgets/input_text.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/widgets/my_data_table.dart';
import 'package:fcs/pages/widgets/progress.dart';
2020-10-14 13:54:42 +06:30
import 'package:flutter/cupertino.dart';
2020-05-31 15:00:11 +06:30
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
import 'package:flutter/material.dart';
2020-10-07 02:33:06 +06:30
import '../main/util.dart';
import 'cargo_editor.dart';
2020-06-29 16:15:25 +06:30
import 'custom_editor.dart';
import 'discount_by_weight_editor.dart';
2020-05-31 15:00:11 +06:30
class ShipmentRatesEdit extends StatefulWidget {
2020-10-07 02:33:06 +06:30
ShipmentRatesEdit();
2020-05-31 15:00:11 +06:30
@override
_ShipmentRatesEditState createState() => _ShipmentRatesEditState();
}
class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
bool _isLoading = false;
2020-10-07 18:49:28 +06:30
TextEditingController _minWeight = new TextEditingController();
TextEditingController _deliveryFee = new TextEditingController();
TextEditingController _volumetricRatio = new TextEditingController();
2020-05-31 15:00:11 +06:30
2020-10-15 15:49:02 +06:30
bool _isNew = false;
2020-05-31 15:00:11 +06:30
@override
void initState() {
super.initState();
2020-10-07 18:49:28 +06:30
_minWeight.text = "10";
_deliveryFee.text = "5";
_volumetricRatio.text = "166.36";
2020-05-31 15:00:11 +06:30
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
var shipmentRateModel = Provider.of<ShipmentRateModel>(context);
2020-10-07 18:49:28 +06:30
final minWigBox = InputText(
labelTextKey: 'rate.min_weight',
iconData: FontAwesomeIcons.weightHanging,
controller: _minWeight);
final feeBox = InputText(
labelTextKey: 'rate.delivery_fee',
iconData: Icons.attach_money,
controller: _deliveryFee);
final ratioBox = InputText(
labelTextKey: 'rate.volumetric_ratio',
iconData: Icons.attach_money,
controller: _volumetricRatio);
2020-05-31 15:00:11 +06:30
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
icon: new Icon(
2020-10-14 13:54:42 +06:30
CupertinoIcons.back,
2020-05-31 15:00:11 +06:30
),
onPressed: () => Navigator.of(context).pop(),
),
backgroundColor: primaryColor,
title: Text(AppTranslations.of(context).text("rate.edit.title")),
),
body: Container(
padding: EdgeInsets.all(18),
2020-06-25 16:19:23 +06:30
child: Column(
2020-05-31 15:00:11 +06:30
children: <Widget>[
2020-06-25 16:19:23 +06:30
Expanded(
child: ListView(
children: <Widget>[
2020-10-07 18:49:28 +06:30
minWigBox,
feeBox,
ratioBox,
2020-06-25 16:19:23 +06:30
SizedBox(height: 10),
2020-10-15 15:49:02 +06:30
// ExpansionTile(
// title: Text(
// 'Cargo Types',
// style: TextStyle(
// color: primaryColor, fontWeight: FontWeight.bold),
// ),
// children: <Widget>[
// Container(
// child: SingleChildScrollView(
// scrollDirection: Axis.horizontal,
// child: MyDataTable(
// headingRowHeight: 40,
// columnSpacing: 50,
// columns: [
// MyDataColumn(
// label: Text("Cargo Type",
// style: TextStyle(
// fontSize: 15,
// color: Colors.grey[600]))),
// MyDataColumn(
// label: Text("Rate",
// style: TextStyle(
// fontSize: 15,
// color: Colors.grey[600]))),
// MyDataColumn(
// label: Text("Delete",
// style: TextStyle(
// fontSize: 15,
// color: Colors.grey[600]))),
// ],
// rows: getCargoRows(
// shipmentRateModel.rate.cargoTypes),
// ),
// ),
// ),
// Container(
// padding:
// EdgeInsets.only(top: 20, bottom: 15, right: 15),
// child: Align(
// alignment: Alignment.bottomRight,
// child: Container(
// width: 120,
// height: 40,
// child: FloatingActionButton.extended(
// materialTapTargetSize:
// MaterialTapTargetSize.shrinkWrap,
// icon: Icon(Icons.add),
// onPressed: () {
// Navigator.push(
// context,
// CupertinoPageRoute(
// builder: (context) => CargoEditor()),
// );
// },
// label: Text(
// 'Add Cargo',
// style: TextStyle(fontSize: 12),
// ),
// backgroundColor: primaryColor,
// ),
// ),
// ),
// )
// ],
// ),
// ExpansionTile(
// title: Text(
// 'Custom Duties',
// style: TextStyle(
// color: primaryColor, fontWeight: FontWeight.bold),
// ),
// children: <Widget>[
// Container(
// child: SingleChildScrollView(
// scrollDirection: Axis.horizontal,
// child: MyDataTable(
// headingRowHeight: 40,
// columnSpacing: 50,
// columns: [
// MyDataColumn(
// label: Text("Produt Type",
// style: TextStyle(
// fontSize: 15,
// color: Colors.grey[600]))),
// MyDataColumn(
// label: Text("Fee",
// style: TextStyle(
// fontSize: 15,
// color: Colors.grey[600]))),
// MyDataColumn(
// label: Text("Delete",
// style: TextStyle(
// fontSize: 15,
// color: Colors.grey[600]))),
// ],
// rows: getCustomsRows(
// shipmentRateModel.rate.customDuties),
// ),
// ),
// ),
// Container(
// padding:
// EdgeInsets.only(top: 20, bottom: 15, right: 15),
// child: Align(
// alignment: Alignment.bottomRight,
// child: Container(
// width: 120,
// height: 40,
// child: FloatingActionButton.extended(
// materialTapTargetSize:
// MaterialTapTargetSize.shrinkWrap,
// icon: Icon(Icons.add),
// onPressed: () {
// Navigator.push(
// context,
// CupertinoPageRoute(
// builder: (context) => CustomEditor()),
// );
// },
// label: Text(
// 'Add Custom\nDuty',
// style: TextStyle(fontSize: 12),
// ),
// backgroundColor: primaryColor,
// ),
// ),
// ),
// )
// ],
// ),
// ExpansionTile(
// title: Text(
// 'Discounts by weight',
// style: TextStyle(
// color: primaryColor, fontWeight: FontWeight.bold),
// ),
// children: <Widget>[
// Container(
// child: SingleChildScrollView(
// scrollDirection: Axis.horizontal,
// child: MyDataTable(
// headingRowHeight: 40,
// columnSpacing: 30,
// columns: [
// MyDataColumn(
// label: Text("Weight",
// style: TextStyle(
// fontSize: 15,
// color: Colors.grey[600]))),
// MyDataColumn(
// label: Text("Discount Rate",
// style: TextStyle(
// fontSize: 15,
// color: Colors.grey[600]))),
// MyDataColumn(
// label: Text("Delete",
// style: TextStyle(
// fontSize: 15,
// color: Colors.grey[600]))),
// ],
// rows: getDiscounts(
// shipmentRateModel.rate.discountByWeights),
// ),
// ),
// ),
// 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,
// icon: Icon(Icons.add),
// onPressed: () {
// Navigator.push(
// context,
// CupertinoPageRoute(
// builder: (context) =>
// DiscountByWeightEditor()),
// );
// },
// label: Text(
// 'Add Discount',
// style: TextStyle(fontSize: 12),
// ),
// backgroundColor: primaryColor,
// ),
// ),
// ),
// )
// ],
// ),
2020-06-25 16:19:23 +06:30
],
),
2020-05-31 15:00:11 +06:30
),
2020-10-15 15:49:02 +06:30
fcsButton(context, getLocalString(context, "btn.save"),
callack: _save),
2020-05-31 15:00:11 +06:30
SizedBox(height: 10)
],
),
),
),
);
}
2020-10-15 15:49:02 +06:30
_save() async {
setState(() {
_isLoading = true;
});
try {
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
2020-10-16 13:46:02 +06:30
Rate _rate = new Rate(
2020-10-15 15:49:02 +06:30
deliveryFee: double.parse(_deliveryFee.text),
freeDeliveryWeight: double.parse(_minWeight.text),
volumetricRatio: double.parse(_volumetricRatio.text));
2020-10-16 13:46:02 +06:30
Rate r = new Rate();
print('_rate =>$r');
2020-10-15 15:49:02 +06:30
await shipmentRateModel.updateRate(_rate);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
2020-10-15 03:06:13 +06:30
List<MyDataRow> getCargoRows(List<CargoType> cargos) {
return cargos.map((r) {
2020-06-25 16:19:23 +06:30
return MyDataRow(
onSelectChanged: (selected) {
Navigator.push(
context,
2020-10-15 03:06:13 +06:30
CupertinoPageRoute(builder: (context) => CargoEditor(cargo: r)),
2020-06-25 16:19:23 +06:30
);
},
cells: [
MyDataCell(
new Text(
2020-10-15 03:06:13 +06:30
r.name,
2020-06-25 16:19:23 +06:30
style: textStyle,
),
),
MyDataCell(
new Text(
2020-10-15 03:06:13 +06:30
r.rate.toString(),
2020-06-25 16:19:23 +06:30
style: textStyle,
),
),
2020-06-29 16:15:25 +06:30
MyDataCell(IconButton(icon: Icon(Icons.delete), onPressed: null)),
],
);
}).toList();
}
2020-10-15 03:06:13 +06:30
List<MyDataRow> getCustomsRows(List<CustomDuty> customs) {
2020-06-29 16:15:25 +06:30
return customs.map((c) {
return MyDataRow(
onSelectChanged: (selected) {
Navigator.push(
context,
2020-10-14 13:54:42 +06:30
CupertinoPageRoute(builder: (context) => CustomEditor(custom: c)),
2020-06-29 16:15:25 +06:30
);
},
cells: [
MyDataCell(
new Text(
c.productType,
style: textStyle,
),
),
MyDataCell(
new Text(
c.fee.toString(),
style: textStyle,
),
),
MyDataCell(IconButton(icon: Icon(Icons.delete), onPressed: null)),
],
);
}).toList();
}
2020-10-15 03:06:13 +06:30
List<MyDataRow> getDiscounts(List<DiscountByWeight> discounts) {
2020-06-29 16:15:25 +06:30
return discounts.map((d) {
return MyDataRow(
onSelectChanged: (selected) {
// Navigator.push(
// context,
2020-10-14 13:54:42 +06:30
// CupertinoPageRoute(builder: (context) => CargoEditor(rate: r)),
2020-06-29 16:15:25 +06:30
// );
},
cells: [
MyDataCell(
new Text(
"${d.weight} lb",
style: textStyle,
),
),
MyDataCell(
Center(
child: new Text(
2020-10-15 03:06:13 +06:30
d.discount.toString(),
2020-06-29 16:15:25 +06:30
style: textStyle,
),
),
),
2020-06-25 16:19:23 +06:30
MyDataCell(IconButton(icon: Icon(Icons.delete), onPressed: null)),
],
);
}).toList();
}
2020-05-31 15:00:11 +06:30
_row(String desc, String price, String unit) {
return Container(
padding: EdgeInsets.only(left: 25, top: 5, bottom: 5),
child: Row(
children: <Widget>[
Text('$desc ', style: TextStyle(fontSize: 15)),
Spacer(),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 3.0),
child: Text(
'$price',
style: TextStyle(color: primaryColor, fontSize: 14),
),
),
Text(
'$unit',
style: TextStyle(color: Colors.grey, fontSize: 14),
),
],
),
SizedBox(
width: 50,
),
],
));
}
}