2020-10-18 02:38:46 +06:30
|
|
|
import 'package:fcs/domain/entities/carton.dart';
|
2020-10-16 10:58:31 +06:30
|
|
|
import 'package:fcs/domain/entities/cargo_type.dart';
|
|
|
|
|
import 'package:fcs/domain/entities/rate.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
|
2020-10-15 18:48:32 +06:30
|
|
|
import 'package:fcs/pages/widgets/display_text.dart';
|
2020-10-16 10:58:31 +06:30
|
|
|
import 'package:fcs/pages/widgets/input_text.dart';
|
2020-10-15 18:48:32 +06:30
|
|
|
import 'package:fcs/pages/widgets/length_picker.dart';
|
2024-01-25 17:40:35 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
2020-10-20 18:45:18 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_dropdown.dart';
|
2020-10-15 03:06:13 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
2020-10-16 10:58:31 +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:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
class ShipmentRatesCal extends StatefulWidget {
|
2025-03-12 17:49:27 +06:30
|
|
|
const ShipmentRatesCal({super.key});
|
2020-05-31 15:00:11 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_ShipmentRatesCalState createState() => _ShipmentRatesCalState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _ShipmentRatesCalState extends State<ShipmentRatesCal> {
|
2025-03-12 17:49:27 +06:30
|
|
|
bool isLoading = false;
|
2021-09-10 12:02:08 +06:30
|
|
|
late CargoType _cargoType;
|
2025-03-12 17:49:27 +06:30
|
|
|
TextEditingController widthController = TextEditingController();
|
|
|
|
|
TextEditingController heightController = TextEditingController();
|
|
|
|
|
TextEditingController lengthController = TextEditingController();
|
|
|
|
|
TextEditingController actualWeightCtl = TextEditingController();
|
2020-10-16 10:58:31 +06:30
|
|
|
double _shipmentWeight = 0;
|
|
|
|
|
double _amount = 0;
|
|
|
|
|
double _deliveryFee = 0;
|
2020-05-31 15:00:11 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2020-10-15 18:48:32 +06:30
|
|
|
|
|
|
|
|
//for shipment weight
|
2020-10-16 10:58:31 +06:30
|
|
|
Rate rate = Provider.of<ShipmentRateModel>(context, listen: false).rate;
|
2025-03-12 17:49:27 +06:30
|
|
|
lengthController.addListener(_calShipmentWeight);
|
|
|
|
|
widthController.addListener(_calShipmentWeight);
|
|
|
|
|
heightController.addListener(_calShipmentWeight);
|
|
|
|
|
actualWeightCtl.addListener(_calShipmentWeight);
|
2020-10-16 10:58:31 +06:30
|
|
|
_cargoType = rate.defaultCargoType;
|
2025-03-12 17:49:27 +06:30
|
|
|
lengthController.text = '12';
|
|
|
|
|
widthController.text = '12';
|
|
|
|
|
heightController.text = '12';
|
|
|
|
|
actualWeightCtl.text = "10.00";
|
2020-10-16 10:58:31 +06:30
|
|
|
_calShipmentWeight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_calShipmentWeight() {
|
|
|
|
|
Rate rate = Provider.of<ShipmentRateModel>(context, listen: false).rate;
|
|
|
|
|
|
2025-03-12 17:49:27 +06:30
|
|
|
double l = double.tryParse(lengthController.text) ?? 0;
|
|
|
|
|
double w = double.tryParse(widthController.text) ?? 0;
|
|
|
|
|
double h = double.tryParse(heightController.text) ?? 0;
|
|
|
|
|
_cargoType.weight = double.tryParse(actualWeightCtl.text) ?? 0;
|
2020-10-18 02:38:46 +06:30
|
|
|
Carton box =
|
|
|
|
|
Carton(cargoTypes: [_cargoType], length: l, width: w, height: h);
|
2020-10-16 10:58:31 +06:30
|
|
|
var amount = box.calAmount(rate);
|
|
|
|
|
var shipmentWeight = box.getShipmentWeight(rate.volumetricRatio);
|
|
|
|
|
var effectiveWeight =
|
2021-09-10 17:14:59 +06:30
|
|
|
_cargoType.weight > shipmentWeight ? _cargoType.weight : shipmentWeight;
|
2020-10-16 10:58:31 +06:30
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
_deliveryFee =
|
2021-09-10 17:14:59 +06:30
|
|
|
effectiveWeight > rate.freeDeliveryWeight ? 0 : rate.deliveryFee;
|
2024-01-23 16:28:08 +06:30
|
|
|
_amount = amount + _deliveryFee;
|
2021-01-04 17:19:01 +06:30
|
|
|
_shipmentWeight = shipmentWeight.toDouble();
|
2020-10-16 10:58:31 +06:30
|
|
|
});
|
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-20 18:45:18 +06:30
|
|
|
List<CargoType> cargos = shipmentRateModel.rate.cargoTypes;
|
2020-06-25 16:19:23 +06:30
|
|
|
|
2020-10-15 18:48:32 +06:30
|
|
|
final lengthBox = LengthPicker(
|
2025-03-12 17:49:27 +06:30
|
|
|
controller: lengthController,
|
2020-10-15 18:48:32 +06:30
|
|
|
lableKey: "box.length",
|
|
|
|
|
);
|
|
|
|
|
final widthBox = LengthPicker(
|
2025-03-12 17:49:27 +06:30
|
|
|
controller: widthController,
|
2020-10-15 18:48:32 +06:30
|
|
|
lableKey: "box.width",
|
|
|
|
|
);
|
|
|
|
|
final heightBox = LengthPicker(
|
2025-03-12 17:49:27 +06:30
|
|
|
controller: heightController,
|
2020-10-15 18:48:32 +06:30
|
|
|
lableKey: "box.height",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final dimBox = Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
|
|
|
child: Icon(FontAwesome.arrow_circle_right, color: primaryColor),
|
|
|
|
|
),
|
2025-03-12 17:49:27 +06:30
|
|
|
SizedBox(width: 80, child: lengthBox),
|
|
|
|
|
SizedBox(width: 80, child: widthBox),
|
|
|
|
|
SizedBox(width: 80, child: heightBox),
|
2020-10-15 18:48:32 +06:30
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final shipmentWeightBox = DisplayText(
|
2024-01-23 16:28:08 +06:30
|
|
|
text: _shipmentWeight.toStringAsFixed(2),
|
2020-10-15 18:48:32 +06:30
|
|
|
labelTextKey: "box.shipment_weight",
|
|
|
|
|
iconData: MaterialCommunityIcons.weight,
|
|
|
|
|
);
|
|
|
|
|
|
2020-10-16 10:58:31 +06:30
|
|
|
final actualWeightBox = InputText(
|
2025-03-12 17:49:27 +06:30
|
|
|
controller: actualWeightCtl,
|
2020-10-15 18:48:32 +06:30
|
|
|
labelTextKey: "box.actual_weight",
|
|
|
|
|
iconData: MaterialCommunityIcons.weight,
|
2021-01-25 23:45:09 +06:30
|
|
|
textInputType: TextInputType.numberWithOptions(decimal: true),
|
2020-10-15 18:48:32 +06:30
|
|
|
);
|
|
|
|
|
|
2020-10-20 18:45:18 +06:30
|
|
|
var cargoTypeBox = LocalDropdown<CargoType>(
|
|
|
|
|
callback: (v) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_cargoType = v;
|
2020-10-28 06:01:36 +06:30
|
|
|
_calShipmentWeight();
|
2020-10-20 18:45:18 +06:30
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
labelKey: "cargo.type",
|
2025-03-12 17:49:27 +06:30
|
|
|
iconData: Ionicons.text,
|
2020-10-20 18:45:18 +06:30
|
|
|
selectedValue: _cargoType,
|
|
|
|
|
values: cargos,
|
|
|
|
|
);
|
|
|
|
|
|
2020-05-31 15:00:11 +06:30
|
|
|
return LocalProgress(
|
2025-03-12 17:49:27 +06:30
|
|
|
inAsyncCall: isLoading,
|
2020-05-31 15:00:11 +06:30
|
|
|
child: Scaffold(
|
2024-01-25 17:40:35 +06:30
|
|
|
appBar: LocalAppBar(
|
|
|
|
|
labelKey: "rate.cal.title",
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
labelColor: primaryColor,
|
|
|
|
|
arrowColor: primaryColor),
|
2020-05-31 15:00:11 +06:30
|
|
|
body: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
child: ListView(
|
|
|
|
|
children: <Widget>[
|
2020-10-20 18:45:18 +06:30
|
|
|
cargoTypeBox,
|
2020-10-16 10:58:31 +06:30
|
|
|
actualWeightBox,
|
2020-10-15 18:48:32 +06:30
|
|
|
dimBox,
|
|
|
|
|
shipmentWeightBox,
|
2020-05-31 15:00:11 +06:30
|
|
|
SizedBox(height: 50),
|
2020-10-16 10:58:31 +06:30
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
LocalText(context, "rate.delivery_fee",
|
|
|
|
|
color: primaryColor, fontSize: 16),
|
|
|
|
|
Text(
|
2020-12-04 17:28:21 +06:30
|
|
|
':\$ ${_deliveryFee.toStringAsFixed(2)}',
|
2020-10-16 10:58:31 +06:30
|
|
|
style: TextStyle(
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
2020-05-31 15:00:11 +06:30
|
|
|
SizedBox(height: 20),
|
2020-10-16 10:58:31 +06:30
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
LocalText(context, "rate.total_estimated_amount",
|
|
|
|
|
color: primaryColor, fontSize: 16),
|
|
|
|
|
Text(
|
|
|
|
|
':\$${_amount.toStringAsFixed(2)}',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
)
|
2020-05-31 15:00:11 +06:30
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|