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

160 lines
5.1 KiB
Dart
Raw Normal View History

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';
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/progress.dart';
2020-10-14 13:54:42 +06:30
import 'package:flutter/cupertino.dart';
2020-10-21 02:59:10 +06:30
import 'package:flutter/material.dart';
2020-05-31 15:00:11 +06:30
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
2020-10-07 02:33:06 +06:30
import '../main/util.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();
2021-01-04 17:19:01 +06:30
TextEditingController _diffDiscountWeight = new TextEditingController();
TextEditingController _diffWeightRate = new TextEditingController();
2021-09-10 12:02:08 +06:30
late Rate rate;
2020-05-31 15:00:11 +06:30
@override
void initState() {
super.initState();
2020-10-21 02:59:10 +06:30
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
rate = shipmentRateModel.rate;
2020-10-21 02:59:10 +06:30
2021-09-10 16:33:52 +06:30
_minWeight.text = rate.freeDeliveryWeight.toStringAsFixed(2);
_deliveryFee.text = rate.deliveryFee.toStringAsFixed(2);
_volumetricRatio.text = rate.volumetricRatio.toStringAsFixed(2);
_diffDiscountWeight.text = rate.diffDiscountWeight.toStringAsFixed(2);
_diffWeightRate.text = rate.diffWeightRate.toStringAsFixed(2);
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',
2021-01-04 17:19:01 +06:30
iconData: FontAwesomeIcons.weightHanging,
2020-10-07 18:49:28 +06:30
controller: _volumetricRatio);
2021-01-04 17:19:01 +06:30
final diffDiscountWeightBox = InputText(
labelTextKey: 'rate.diff_discount_weight',
iconData: FontAwesomeIcons.weightHanging,
controller: _diffDiscountWeight);
final diffWeightRateBox = InputText(
labelTextKey: 'rate.diff_weight_rate',
iconData: Icons.attach_money,
controller: _diffWeightRate);
2020-10-07 18:49:28 +06:30
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: () {
if (isDataChanged()) {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
});
} else {
Navigator.of(context).pop();
}
},
2020-05-31 15:00:11 +06:30
),
backgroundColor: primaryColor,
2021-09-10 12:02:08 +06:30
title: Text(AppTranslations.of(context)!.text("rate.edit.title")),
2020-05-31 15:00:11 +06:30
),
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,
2021-01-04 17:19:01 +06:30
diffDiscountWeightBox,
diffWeightRateBox,
2020-06-25 16:19:23 +06:30
SizedBox(height: 10),
],
),
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),
2021-01-04 17:19:01 +06:30
volumetricRatio: double.parse(_volumetricRatio.text),
diffDiscountWeight: double.parse(_diffDiscountWeight.text),
diffWeightRate: double.parse(_diffWeightRate.text));
2020-10-21 02:59:10 +06:30
Rate r = new Rate();
2020-10-16 13:46:02 +06:30
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;
});
}
}
isDataChanged() {
Rate _rate = new Rate(
2021-01-04 17:19:01 +06:30
deliveryFee: double.parse(_deliveryFee.text),
freeDeliveryWeight: double.parse(_minWeight.text),
volumetricRatio: double.parse(_volumetricRatio.text),
diffDiscountWeight: double.parse(_diffDiscountWeight.text),
diffWeightRate: double.parse(_diffWeightRate.text),
);
return rate.isChangedForEdit(_rate);
}
2020-05-31 15:00:11 +06:30
}