add paginator
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
import 'package:fcs/domain/entities/box.dart';
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
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/display_text.dart';
|
||||
import 'package:fcs/pages/widgets/input_text.dart';
|
||||
import 'package:fcs/pages/widgets/length_picker.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_title.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 'package:flutter/material.dart';
|
||||
|
||||
class ShipmentRatesCal extends StatefulWidget {
|
||||
ShipmentRatesCal();
|
||||
|
||||
@@ -21,27 +22,52 @@ class ShipmentRatesCal extends StatefulWidget {
|
||||
|
||||
class _ShipmentRatesCalState extends State<ShipmentRatesCal> {
|
||||
bool _isLoading = false;
|
||||
String cargoType;
|
||||
CargoType _cargoType;
|
||||
TextEditingController _widthController = new TextEditingController();
|
||||
TextEditingController _heightController = new TextEditingController();
|
||||
TextEditingController _lengthController = new TextEditingController();
|
||||
double shipmentWeight = 0;
|
||||
double volumetricRatio = 0;
|
||||
TextEditingController _actualWeightCtl = new TextEditingController();
|
||||
double _shipmentWeight = 0;
|
||||
double _amount = 0;
|
||||
double _deliveryFee = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
//for shipment weight
|
||||
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
|
||||
.rate
|
||||
.volumetricRatio;
|
||||
// _lengthController.addListener(_calShipmentWeight);
|
||||
// _widthController.addListener(_calShipmentWeight);
|
||||
// _heightController.addListener(_calShipmentWeight);
|
||||
_lengthController.text = '10';
|
||||
_widthController.text = '10';
|
||||
_heightController.text = '10';
|
||||
Rate rate = Provider.of<ShipmentRateModel>(context, listen: false).rate;
|
||||
_lengthController.addListener(_calShipmentWeight);
|
||||
_widthController.addListener(_calShipmentWeight);
|
||||
_heightController.addListener(_calShipmentWeight);
|
||||
_actualWeightCtl.addListener(_calShipmentWeight);
|
||||
_cargoType = rate.defaultCargoType;
|
||||
_lengthController.text = '12';
|
||||
_widthController.text = '12';
|
||||
_heightController.text = '12';
|
||||
_actualWeightCtl.text = "10";
|
||||
_calShipmentWeight();
|
||||
}
|
||||
|
||||
_calShipmentWeight() {
|
||||
Rate rate = Provider.of<ShipmentRateModel>(context, listen: false).rate;
|
||||
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
double w = double.parse(_widthController.text, (s) => 0);
|
||||
double h = double.parse(_heightController.text, (s) => 0);
|
||||
_cargoType.weight = double.tryParse(_actualWeightCtl.text) ?? 0;
|
||||
Box box = Box(cargoTypes: [_cargoType], length: l, width: w, height: h);
|
||||
var amount = box.calAmount(rate);
|
||||
var shipmentWeight = box.getShipmentWeight(rate.volumetricRatio);
|
||||
var effectiveWeight =
|
||||
_cargoType.weight > shipmentWeight ? _cargoType.weight : shipmentWeight;
|
||||
|
||||
setState(() {
|
||||
_deliveryFee =
|
||||
effectiveWeight > rate.freeDeliveryWeight ? 0 : rate.deliveryFee;
|
||||
_amount = amount == null ? 0 : amount + _deliveryFee;
|
||||
_shipmentWeight = shipmentWeight;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -80,15 +106,16 @@ class _ShipmentRatesCalState extends State<ShipmentRatesCal> {
|
||||
);
|
||||
|
||||
final shipmentWeightBox = DisplayText(
|
||||
text: shipmentWeight != null ? shipmentWeight.toStringAsFixed(0) : "6",
|
||||
text: _shipmentWeight != null ? _shipmentWeight.toStringAsFixed(2) : "0",
|
||||
labelTextKey: "box.shipment_weight",
|
||||
iconData: MaterialCommunityIcons.weight,
|
||||
);
|
||||
|
||||
final actualWeightBox = DisplayText(
|
||||
text: shipmentWeight != null ? shipmentWeight.toStringAsFixed(0) : "",
|
||||
final actualWeightBox = InputText(
|
||||
controller: _actualWeightCtl,
|
||||
labelTextKey: "box.actual_weight",
|
||||
iconData: MaterialCommunityIcons.weight,
|
||||
textInputType: TextInputType.number,
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
@@ -119,17 +146,19 @@ class _ShipmentRatesCalState extends State<ShipmentRatesCal> {
|
||||
Container(
|
||||
width: 150.0,
|
||||
child: DropdownButtonFormField(
|
||||
value: _cargoType,
|
||||
decoration: InputDecoration(
|
||||
fillColor: Colors.white,
|
||||
hintText: shipmentRateModel.rate.cargoTypes[0].name,
|
||||
hintStyle: TextStyle(color: Colors.black87)),
|
||||
items: shipmentRateModel.rate.cargoTypes
|
||||
.map((e) => DropdownMenuItem(
|
||||
child: Text(e.name), value: e.name))
|
||||
.map((e) =>
|
||||
DropdownMenuItem(child: Text(e.name), value: e))
|
||||
.toList(),
|
||||
onChanged: (selected) => {
|
||||
setState(() {
|
||||
cargoType = selected;
|
||||
_cargoType = selected;
|
||||
_calShipmentWeight();
|
||||
})
|
||||
},
|
||||
),
|
||||
@@ -137,51 +166,40 @@ class _ShipmentRatesCalState extends State<ShipmentRatesCal> {
|
||||
],
|
||||
),
|
||||
),
|
||||
actualWeightBox,
|
||||
// LocalTitle(textKey: "box.dimension"),
|
||||
dimBox,
|
||||
shipmentWeightBox,
|
||||
actualWeightBox,
|
||||
|
||||
SizedBox(height: 50),
|
||||
Center(
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
width: 150,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
LocalText(context, "rate.delivery_fee",
|
||||
color: primaryColor, fontSize: 16),
|
||||
Text(
|
||||
':\$ 5',
|
||||
style: TextStyle(
|
||||
color: primaryColor,
|
||||
fontSize: 16,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
)),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
LocalText(context, "rate.delivery_fee",
|
||||
color: primaryColor, fontSize: 16),
|
||||
Text(
|
||||
':\$ $_deliveryFee',
|
||||
style: TextStyle(
|
||||
color: primaryColor,
|
||||
fontSize: 16,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
Center(
|
||||
child: Container(
|
||||
width: 220,
|
||||
alignment: Alignment.center,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
LocalText(context, "rate.total_estimated_amount",
|
||||
color: primaryColor, fontSize: 16),
|
||||
Text(
|
||||
':\$ 41',
|
||||
style: TextStyle(
|
||||
color: primaryColor,
|
||||
fontSize: 16,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
))
|
||||
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,
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user