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

159 lines
4.9 KiB
Dart
Raw Permalink Normal View History

2025-03-12 17:49:27 +06:30
// ignore_for_file: use_build_context_synchronously
2020-10-07 02:33:06 +06:30
import 'package:fcs/domain/entities/rate.dart';
import 'package:fcs/helpers/theme.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';
2024-01-25 17:40:35 +06:30
import 'package:fcs/pages/widgets/local_app_bar.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/widgets/progress.dart';
2020-10-21 02:59:10 +06:30
import 'package:flutter/material.dart';
2025-03-12 17:49:27 +06:30
import 'package:flutter_vector_icons/flutter_vector_icons.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 {
2025-03-12 17:49:27 +06:30
const ShipmentRatesEdit({super.key});
2020-05-31 15:00:11 +06:30
@override
_ShipmentRatesEditState createState() => _ShipmentRatesEditState();
}
class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
bool _isLoading = false;
2025-03-12 17:49:27 +06:30
TextEditingController minWeight = TextEditingController();
TextEditingController deliveryFee = TextEditingController();
TextEditingController volumetricRatio = TextEditingController();
TextEditingController diffDiscountWeight = TextEditingController();
TextEditingController diffWeightRate = TextEditingController();
2021-01-04 17:19:01 +06:30
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
2025-03-12 17:49:27 +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) {
2020-10-07 18:49:28 +06:30
final minWigBox = InputText(
labelTextKey: 'rate.min_weight',
iconData: FontAwesomeIcons.weightHanging,
2025-03-12 17:49:27 +06:30
controller: minWeight);
2020-10-07 18:49:28 +06:30
final feeBox = InputText(
labelTextKey: 'rate.delivery_fee',
2025-03-12 17:49:27 +06:30
iconData: Fontisto.dollar,
controller: deliveryFee);
2020-10-07 18:49:28 +06:30
final ratioBox = InputText(
labelTextKey: 'rate.volumetric_ratio',
2021-01-04 17:19:01 +06:30
iconData: FontAwesomeIcons.weightHanging,
2025-03-12 17:49:27 +06:30
controller: volumetricRatio);
2021-01-04 17:19:01 +06:30
final diffDiscountWeightBox = InputText(
labelTextKey: 'rate.diff_discount_weight',
iconData: FontAwesomeIcons.weightHanging,
2025-03-12 17:49:27 +06:30
controller: diffDiscountWeight);
2021-01-04 17:19:01 +06:30
final diffWeightRateBox = InputText(
labelTextKey: 'rate.diff_weight_rate',
2025-03-12 17:49:27 +06:30
iconData: Fontisto.dollar,
controller: diffWeightRate);
2020-10-07 18:49:28 +06:30
2020-05-31 15:00:11 +06:30
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
2024-01-25 17:40:35 +06:30
appBar: LocalAppBar(
labelKey: "rate.edit.title",
backgroundColor: Colors.white,
labelColor: primaryColor,
arrowColor: primaryColor,
onBack: () {
if (isDataChanged()) {
showConfirmDialog(context, "back.button_confirm", () {
Navigator.of(context).pop();
2024-01-25 17:40:35 +06:30
});
} else {
Navigator.of(context).pop();
}
},
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),
2025-03-12 17:49:27 +06:30
SizedBox(height: 30)
2020-05-31 15:00:11 +06:30
],
),
),
),
);
}
2020-10-15 15:49:02 +06:30
_save() async {
setState(() {
_isLoading = true;
});
try {
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
2025-03-12 17:49:27 +06:30
Rate rate = Rate(
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));
await shipmentRateModel.updateRate(rate);
2020-10-15 15:49:02 +06:30
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
isDataChanged() {
2025-03-12 17:49:27 +06:30
Rate rate = Rate(
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),
2021-01-04 17:19:01 +06:30
);
2025-03-12 17:49:27 +06:30
return rate.isChangedForEdit(rate);
}
2020-05-31 15:00:11 +06:30
}