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

238 lines
7.9 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';
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';
2020-10-15 03:06:13 +06:30
import 'package:fcs/pages/main/model/main_model.dart';
2020-10-15 15:49:02 +06:30
import 'package:fcs/pages/rates/cargo_type_list.dart';
import 'package:fcs/pages/rates/custom_list.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
2020-10-07 14:42:07 +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-14 13:54:42 +06:30
import 'package:flutter/cupertino.dart';
2020-05-29 15:54:26 +06:30
import 'package:flutter/material.dart';
2020-10-07 02:33:06 +06:30
import 'package:provider/provider.dart';
2020-05-29 15:54:26 +06:30
2020-10-07 02:33:06 +06:30
import '../main/util.dart';
2020-10-15 15:49:02 +06:30
import 'discount_by weight_list.dart';
2020-10-07 02:33:06 +06:30
import 'shipment_rates_calculate.dart';
import 'shipment_rates_edit.dart';
2020-05-29 15:54:26 +06:30
class ShipmentRates extends StatefulWidget {
2020-10-07 02:33:06 +06:30
ShipmentRates();
2020-05-29 15:54:26 +06:30
@override
_ShipmentRatesState createState() => _ShipmentRatesState();
}
class _ShipmentRatesState extends State<ShipmentRates> {
bool _isLoading = false;
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
var shipmentRateModel = Provider.of<ShipmentRateModel>(context);
2020-10-15 03:06:13 +06:30
Rate rate = shipmentRateModel.rate;
bool isEditable = context.select((MainModel m) => m.rateEditable());
2020-05-29 15:54:26 +06:30
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
2020-05-31 15:00:11 +06:30
centerTitle: true,
leading: new IconButton(
2020-10-15 03:06:13 +06:30
icon: new Icon(CupertinoIcons.back, color: primaryColor),
2020-05-31 15:00:11 +06:30
onPressed: () => Navigator.of(context).pop(),
),
2020-10-15 03:06:13 +06:30
backgroundColor: Colors.white,
shadowColor: Colors.transparent,
title: LocalText(context, 'rate.title',
color: primaryColor, fontSize: 20),
actions: isEditable
? [
IconButton(
onPressed: () => Navigator.of(context).push(
CupertinoPageRoute(
builder: (context) => ShipmentRatesEdit())),
icon: Icon(
CupertinoIcons.pen,
color: primaryColor,
))
]
: [],
2020-05-29 15:54:26 +06:30
),
2020-05-31 15:00:11 +06:30
body: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
// crossAxisAlignment: CrossAxisAlignment.center,
2020-05-29 15:54:26 +06:30
children: <Widget>[
2020-10-15 03:06:13 +06:30
fcsButton(context, "Calculate shipping cost", callack: () {
Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => ShipmentRatesCal()));
}),
Divider(
color: Colors.grey,
),
2020-06-29 16:15:25 +06:30
Container(
2020-10-15 15:49:02 +06:30
padding: EdgeInsets.only(left: 25, top: 10, right: 25),
child: Row(
children: [
Text(
"Cargo Types",
style: TextStyle(
color: primaryColor,
fontWeight: FontWeight.bold,
fontSize: 15),
),
Spacer(),
IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: () {
Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => CargoTypeList()));
})
],
2020-06-29 16:15:25 +06:30
),
),
2020-10-15 03:06:13 +06:30
Column(
children: getCargoWidget(shipmentRateModel.rate.cargoTypes),
2020-06-29 16:15:25 +06:30
),
Divider(
color: Colors.grey,
),
Container(
2020-10-15 15:49:02 +06:30
padding: EdgeInsets.only(left: 25, top: 10, right: 25),
child: Row(
children: [
Text(
"Discounts by weight",
style: TextStyle(
color: primaryColor,
fontWeight: FontWeight.bold,
fontSize: 15),
),
Spacer(),
IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: () {
Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => DiscountByWeightList()));
})
],
2020-06-29 16:15:25 +06:30
),
),
2020-10-15 03:06:13 +06:30
Column(
children:
getDiscountWidget(shipmentRateModel.rate.discountByWeights),
2020-06-29 16:15:25 +06:30
),
Divider(
color: Colors.grey,
),
2020-10-15 03:06:13 +06:30
_row("Free delivery within Yangon \nfor shipments over",
"${rate.freeDeliveryWeight}", "pounds"),
_row("Delivery fees", "\$ ${rate.deliveryFee}",
"below ${rate.freeDeliveryWeight} pounds"),
_row("Volumetric Ratio", "${rate.volumetricRatio}",
"in3 per pound"),
Divider(
color: Colors.grey,
),
2020-06-29 16:15:25 +06:30
Container(
2020-10-15 15:49:02 +06:30
padding: EdgeInsets.only(left: 25, top: 10, right: 25),
child: Row(
children: [
Text(
"Custom Duties",
style: TextStyle(
color: primaryColor,
fontWeight: FontWeight.bold,
fontSize: 15),
),
Spacer(),
IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: () {
Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => CustomList()));
})
],
2020-06-29 16:15:25 +06:30
),
),
2020-10-15 03:06:13 +06:30
Column(
children: getCustonWidget(shipmentRateModel.rate.customDuties),
2020-05-29 15:54:26 +06:30
),
],
),
),
),
);
}
2020-05-31 15:00:11 +06:30
2020-10-15 03:06:13 +06:30
List<Widget> getCargoWidget(List<CargoType> cargos) {
return cargos.map((cargo) {
2020-06-29 16:15:25 +06:30
return Container(
2020-10-15 03:06:13 +06:30
child: _row(cargo.name, "\$ " + cargo.rate.toString(), 'per pound'),
2020-06-29 16:15:25 +06:30
);
}).toList();
}
2020-10-15 03:06:13 +06:30
List<Widget> getCustonWidget(List<CustomDuty> customs) {
2020-06-29 16:15:25 +06:30
return customs.map((c) {
return Container(
child: _row(c.productType, "\$ " + c.fee.toString(), ''),
);
}).toList();
}
2020-10-15 03:06:13 +06:30
List<Widget> getDiscountWidget(List<DiscountByWeight> discounts) {
if (discounts == null) return [];
2020-06-29 16:15:25 +06:30
return discounts.map((d) {
return Container(
child: _row(
2020-10-15 03:06:13 +06:30
"${d.weight.toString()} lb", "\$ " + d.discount.toString(), ''),
2020-06-29 16:15:25 +06:30
);
}).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>[
2020-06-02 15:30:11 +06:30
Padding(
2020-05-31 15:00:11 +06:30
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,
),
],
));
}
2020-05-29 15:54:26 +06:30
}