add rate service
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import 'package:fcs/domain/entities/rate.dart';
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/app_translations.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
@@ -8,8 +8,8 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CargoEditor extends StatefulWidget {
|
||||
final Rate rate;
|
||||
CargoEditor({this.rate});
|
||||
final CargoType cargo;
|
||||
CargoEditor({this.cargo});
|
||||
|
||||
@override
|
||||
_CargoEditorState createState() => _CargoEditorState();
|
||||
@@ -20,15 +20,14 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
TextEditingController _rateController = new TextEditingController();
|
||||
|
||||
bool _isLoading = false;
|
||||
Rate _rate = new Rate();
|
||||
|
||||
CargoType _cargo;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.rate != null) {
|
||||
_rate = widget.rate;
|
||||
_descController.text = _rate.description;
|
||||
_rateController.text = _rate.price.toString();
|
||||
if (widget.cargo != null) {
|
||||
_cargo = widget.cargo;
|
||||
_descController.text = _cargo.name;
|
||||
_rateController.text = _cargo.rate.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +71,7 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
],
|
||||
),
|
||||
),
|
||||
widget.rate == null
|
||||
widget.cargo == null
|
||||
? fcsButton(context, "Create", callack: () {})
|
||||
: fcsButton(context, "Save", callack: () {}),
|
||||
SizedBox(height: 10)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:fcs/domain/entities/custom.dart';
|
||||
import 'package:fcs/domain/entities/custom_duty.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/app_translations.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
@@ -9,7 +9,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
|
||||
class CustomEditor extends StatefulWidget {
|
||||
final Custom custom;
|
||||
final CustomDuty custom;
|
||||
CustomEditor({this.custom});
|
||||
|
||||
@override
|
||||
@@ -21,7 +21,7 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
TextEditingController _feeController = new TextEditingController();
|
||||
|
||||
bool _isLoading = false;
|
||||
Custom _custom = new Custom();
|
||||
CustomDuty _custom = new CustomDuty();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:fcs/domain/entities/custom.dart';
|
||||
import 'package:fcs/domain/entities/custom_duty.dart';
|
||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/delivery_address/delivery_address_editor.dart';
|
||||
@@ -60,17 +60,18 @@ class _CustomListState extends State<CustomList> {
|
||||
separatorBuilder: (c, i) => Divider(
|
||||
color: primaryColor,
|
||||
),
|
||||
itemCount: shipmentRateModel.customs.length,
|
||||
itemCount: shipmentRateModel.rate.customDuties.length,
|
||||
itemBuilder: (context, index) {
|
||||
return _row(context, shipmentRateModel.customs[index]);
|
||||
return _row(
|
||||
context, shipmentRateModel.rate.customDuties[index]);
|
||||
}),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
_row(BuildContext context, Custom custom) {
|
||||
_row(BuildContext context, CustomDuty custom) {
|
||||
return InkWell(
|
||||
onTap: () => Navigator.pop<Custom>(context, custom),
|
||||
onTap: () => Navigator.pop<CustomDuty>(context, custom),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:fcs/domain/entities/custom.dart';
|
||||
import 'package:fcs/domain/entities/custom_duty.dart';
|
||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
@@ -6,13 +6,12 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
|
||||
typedef SelectionCallback(Custom custom);
|
||||
typedef SelectionCallback(CustomDuty custom);
|
||||
|
||||
class CustomRow extends StatelessWidget {
|
||||
final Custom custom;
|
||||
final CustomDuty custom;
|
||||
final SelectionCallback selectionCallback;
|
||||
const CustomRow(
|
||||
{Key key, this.custom, this.selectionCallback})
|
||||
const CustomRow({Key key, this.custom, this.selectionCallback})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
@@ -33,7 +32,6 @@ class CustomRow extends StatelessWidget {
|
||||
fontSize: 16),
|
||||
line(context, custom.fee.toString(),
|
||||
iconData: Icons.phone, color: primaryColor, fontSize: 16),
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/domain/entities/custom.dart';
|
||||
import 'package:fcs/domain/entities/discount_rate.dart';
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/domain/entities/rate.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
@@ -10,38 +8,20 @@ import 'package:logging/logging.dart';
|
||||
class ShipmentRateModel extends BaseModel {
|
||||
final log = Logger('ShipmentRateModel');
|
||||
|
||||
StreamSubscription<QuerySnapshot> listener;
|
||||
|
||||
List<Rate> rates = [
|
||||
Rate(
|
||||
id: '1', name: 'general_cargo', description: 'General Cargo', price: 6),
|
||||
Rate(id: '2', name: 'medicine', description: 'Medicine', price: 7),
|
||||
Rate(
|
||||
id: '3',
|
||||
name: 'dangerous_cargo',
|
||||
description: 'Dangerous Cargo',
|
||||
price: 8),
|
||||
];
|
||||
|
||||
List<Custom> customs = [
|
||||
Custom(productType: 'Phone', fee: 40),
|
||||
Custom(productType: 'Max Book', fee: 40)
|
||||
];
|
||||
|
||||
List<DiscountRate> discountsByWeight = [
|
||||
DiscountRate(weight: 50, discountRate: 0.25),
|
||||
DiscountRate(weight: 100, discountRate: 0.50)
|
||||
];
|
||||
|
||||
int freeDeliveryWeight = 10;
|
||||
StreamSubscription<Rate> listener;
|
||||
Rate rate;
|
||||
|
||||
void initUser(user) {
|
||||
super.initUser(user);
|
||||
if (listener != null) listener.cancel();
|
||||
listener = Services.instance.rateService.getRateStream().listen((rate) {
|
||||
this.rate = rate;
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
if (listener != null) await listener.cancel();
|
||||
rates = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'package:fcs/domain/entities/custom.dart';
|
||||
import 'package:fcs/domain/entities/discount_rate.dart';
|
||||
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';
|
||||
import 'package:fcs/domain/entities/rate.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/app_translations.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
|
||||
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
@@ -38,6 +40,8 @@ class _ShipmentRatesState extends State<ShipmentRates> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var shipmentRateModel = Provider.of<ShipmentRateModel>(context);
|
||||
Rate rate = shipmentRateModel.rate;
|
||||
bool isEditable = context.select((MainModel m) => m.rateEditable());
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
@@ -45,22 +49,38 @@ class _ShipmentRatesState extends State<ShipmentRates> {
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back),
|
||||
icon: new Icon(CupertinoIcons.back, color: primaryColor),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(
|
||||
context,
|
||||
"rate.title",
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
),
|
||||
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,
|
||||
))
|
||||
]
|
||||
: [],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ListView(
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
fcsButton(context, "Calculate shipping cost", callack: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => ShipmentRatesCal()));
|
||||
}),
|
||||
Divider(
|
||||
color: Colors.grey,
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 25, top: 10),
|
||||
child: Text(
|
||||
@@ -71,30 +91,8 @@ class _ShipmentRatesState extends State<ShipmentRates> {
|
||||
fontSize: 15),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
height: 135,
|
||||
child: Column(
|
||||
children: getCargoWidget(shipmentRateModel.rates),
|
||||
),
|
||||
),
|
||||
Divider(
|
||||
color: Colors.grey,
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 25, top: 10),
|
||||
child: Text(
|
||||
"Custom Duties",
|
||||
style: TextStyle(
|
||||
color: primaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
height: 100,
|
||||
child: Column(
|
||||
children: getCustonWidget(shipmentRateModel.customs),
|
||||
),
|
||||
Column(
|
||||
children: getCargoWidget(shipmentRateModel.rate.cargoTypes),
|
||||
),
|
||||
Divider(
|
||||
color: Colors.grey,
|
||||
@@ -109,33 +107,35 @@ class _ShipmentRatesState extends State<ShipmentRates> {
|
||||
fontSize: 15),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
height: 100,
|
||||
child: Column(
|
||||
children:
|
||||
getDiscountWidget(shipmentRateModel.discountsByWeight),
|
||||
),
|
||||
Column(
|
||||
children:
|
||||
getDiscountWidget(shipmentRateModel.rate.discountByWeights),
|
||||
),
|
||||
Divider(
|
||||
color: Colors.grey,
|
||||
),
|
||||
_row("Free delivery within Yangon \nfor shipments over", "10",
|
||||
"pounds"),
|
||||
_row("Delivery fees", "\$ 5", "below 10 pounds"),
|
||||
_row("Volumetric Ratio", "166.36", "in3 per pound"),
|
||||
// fcsButton(context, "Terms & Conditions", callack: () {
|
||||
// Navigator.of(context)
|
||||
// .push(MaterialPageRoute(builder: (_) => Term()));
|
||||
// }),
|
||||
fcsButton(context, "Estimate shipping cost", callack: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => ShipmentRatesCal()));
|
||||
}),
|
||||
fcsButton(context, "Edit", callack: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => ShipmentRatesEdit()));
|
||||
}),
|
||||
SizedBox(height: 10)
|
||||
_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,
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 25, top: 10),
|
||||
child: Text(
|
||||
"Custom Duties",
|
||||
style: TextStyle(
|
||||
color: primaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15),
|
||||
),
|
||||
),
|
||||
Column(
|
||||
children: getCustonWidget(shipmentRateModel.rate.customDuties),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -143,16 +143,15 @@ class _ShipmentRatesState extends State<ShipmentRates> {
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> getCargoWidget(List<Rate> rates) {
|
||||
return rates.map((cargo) {
|
||||
List<Widget> getCargoWidget(List<CargoType> cargos) {
|
||||
return cargos.map((cargo) {
|
||||
return Container(
|
||||
child: _row(
|
||||
cargo.description, "\$ " + cargo.price.toString(), 'per pound'),
|
||||
child: _row(cargo.name, "\$ " + cargo.rate.toString(), 'per pound'),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<Widget> getCustonWidget(List<Custom> customs) {
|
||||
List<Widget> getCustonWidget(List<CustomDuty> customs) {
|
||||
return customs.map((c) {
|
||||
return Container(
|
||||
child: _row(c.productType, "\$ " + c.fee.toString(), ''),
|
||||
@@ -160,11 +159,12 @@ class _ShipmentRatesState extends State<ShipmentRates> {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<Widget> getDiscountWidget(List<DiscountRate> discounts) {
|
||||
List<Widget> getDiscountWidget(List<DiscountByWeight> discounts) {
|
||||
if (discounts == null) return [];
|
||||
return discounts.map((d) {
|
||||
return Container(
|
||||
child: _row(
|
||||
"${d.weight.toString()} lb", "\$ " + d.discountRate.toString(), ''),
|
||||
"${d.weight.toString()} lb", "\$ " + d.discount.toString(), ''),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -38,11 +39,13 @@ class _ShipmentRatesCalState extends State<ShipmentRatesCal> {
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back),
|
||||
icon: new Icon(CupertinoIcons.back, color: primaryColor),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
title: Text(AppTranslations.of(context).text("rate.cal.title")),
|
||||
backgroundColor: Colors.white,
|
||||
shadowColor: Colors.transparent,
|
||||
title: LocalText(context, 'rate.cal.title',
|
||||
color: primaryColor, fontSize: 20),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
@@ -60,12 +63,11 @@ class _ShipmentRatesCalState extends State<ShipmentRatesCal> {
|
||||
child: DropdownButtonFormField(
|
||||
decoration: InputDecoration(
|
||||
fillColor: Colors.white,
|
||||
hintText: shipmentRateModel.rates[0].description,
|
||||
hintText: shipmentRateModel.rate.cargoTypes[0].name,
|
||||
hintStyle: TextStyle(color: Colors.black87)),
|
||||
items: shipmentRateModel.rates
|
||||
items: shipmentRateModel.rate.cargoTypes
|
||||
.map((e) => DropdownMenuItem(
|
||||
child: Text(e.description),
|
||||
value: e.description))
|
||||
child: Text(e.name), value: e.name))
|
||||
.toList(),
|
||||
onChanged: (selected) => {
|
||||
setState(() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:fcs/domain/entities/custom.dart';
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/domain/entities/custom_duty.dart';
|
||||
import 'package:fcs/domain/entities/discount.dart';
|
||||
import 'package:fcs/domain/entities/discount_rate.dart';
|
||||
import 'package:fcs/domain/entities/discount_by_weight.dart';
|
||||
import 'package:fcs/domain/entities/rate.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/app_translations.dart';
|
||||
@@ -118,7 +119,8 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
|
||||
fontSize: 15,
|
||||
color: Colors.grey[600]))),
|
||||
],
|
||||
rows: getCargoRows(shipmentRateModel.rates),
|
||||
rows: getCargoRows(
|
||||
shipmentRateModel.rate.cargoTypes),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -182,7 +184,8 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
|
||||
fontSize: 15,
|
||||
color: Colors.grey[600]))),
|
||||
],
|
||||
rows: getCustomsRows(shipmentRateModel.customs),
|
||||
rows: getCustomsRows(
|
||||
shipmentRateModel.rate.customDuties),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -247,7 +250,7 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
|
||||
color: Colors.grey[600]))),
|
||||
],
|
||||
rows: getDiscounts(
|
||||
shipmentRateModel.discountsByWeight),
|
||||
shipmentRateModel.rate.discountByWeights),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -296,25 +299,25 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
|
||||
);
|
||||
}
|
||||
|
||||
List<MyDataRow> getCargoRows(List<Rate> rates) {
|
||||
return rates.map((r) {
|
||||
List<MyDataRow> getCargoRows(List<CargoType> cargos) {
|
||||
return cargos.map((r) {
|
||||
return MyDataRow(
|
||||
onSelectChanged: (selected) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => CargoEditor(rate: r)),
|
||||
CupertinoPageRoute(builder: (context) => CargoEditor(cargo: r)),
|
||||
);
|
||||
},
|
||||
cells: [
|
||||
MyDataCell(
|
||||
new Text(
|
||||
r.description,
|
||||
r.name,
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
MyDataCell(
|
||||
new Text(
|
||||
r.price.toString(),
|
||||
r.rate.toString(),
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
@@ -324,7 +327,7 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<MyDataRow> getCustomsRows(List<Custom> customs) {
|
||||
List<MyDataRow> getCustomsRows(List<CustomDuty> customs) {
|
||||
return customs.map((c) {
|
||||
return MyDataRow(
|
||||
onSelectChanged: (selected) {
|
||||
@@ -352,7 +355,7 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<MyDataRow> getDiscounts(List<DiscountRate> discounts) {
|
||||
List<MyDataRow> getDiscounts(List<DiscountByWeight> discounts) {
|
||||
return discounts.map((d) {
|
||||
return MyDataRow(
|
||||
onSelectChanged: (selected) {
|
||||
@@ -371,7 +374,7 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
|
||||
MyDataCell(
|
||||
Center(
|
||||
child: new Text(
|
||||
d.discountRate.toString(),
|
||||
d.discount.toString(),
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user