update rate
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import 'package:fcs/domain/entities/discount.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/app_translations.dart';
|
||||
import 'package:fcs/pages/discount/model/discount_model.dart';
|
||||
import 'package:fcs/pages/main/util.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/progress.dart';
|
||||
@@ -9,6 +11,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class DiscountEditor extends StatefulWidget {
|
||||
final Discount discount;
|
||||
@@ -26,7 +29,7 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
||||
TextEditingController _statusController = new TextEditingController();
|
||||
TextEditingController _customerController = new TextEditingController();
|
||||
|
||||
bool isNew = false;
|
||||
bool _isNew = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -38,7 +41,7 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
||||
_statusController.text = _discount.status;
|
||||
_customerController.text = 'Ko Nyi';
|
||||
} else {
|
||||
isNew = true;
|
||||
_isNew = true;
|
||||
_customerController.text = '';
|
||||
}
|
||||
}
|
||||
@@ -49,17 +52,20 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
||||
labelTextKey: 'discount.code',
|
||||
iconData: FontAwesomeIcons.algolia,
|
||||
controller: _codeController);
|
||||
|
||||
final nameBox = InputText(
|
||||
labelTextKey: 'discount.name',
|
||||
iconData: Feather.user,
|
||||
controller: _customerController);
|
||||
|
||||
final amountBox = InputText(
|
||||
labelTextKey: 'discount.amount',
|
||||
iconData: FontAwesomeIcons.moneyBill,
|
||||
controller: _amountController);
|
||||
|
||||
final statusBox = DisplayText(
|
||||
text: _statusController.text,
|
||||
labelTextKey: getLocalString(context, "discount.status"),
|
||||
labelTextKey: "discount.status",
|
||||
iconData: Icons.av_timer,
|
||||
);
|
||||
|
||||
@@ -77,10 +83,15 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
actions: <Widget>[],
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: _delete,
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.only(left: 20.0),
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
@@ -98,35 +109,8 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
||||
],
|
||||
),
|
||||
),
|
||||
widget.discount == null
|
||||
? Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 250,
|
||||
child: FlatButton(
|
||||
child: Text('Add Discount'),
|
||||
color: primaryColor,
|
||||
textColor: Colors.white,
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
)))
|
||||
: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 250,
|
||||
child: FlatButton(
|
||||
child: Text('Save box'),
|
||||
color: primaryColor,
|
||||
textColor: Colors.white,
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
))),
|
||||
fcsButton(context, getLocalString(context, "btn.save"),
|
||||
callack: _save),
|
||||
SizedBox(
|
||||
height: 30,
|
||||
)
|
||||
@@ -135,4 +119,53 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
_save() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
DiscountModel discountModel =
|
||||
Provider.of<DiscountModel>(context, listen: false);
|
||||
Discount _discount = Discount(
|
||||
code: _codeController.text,
|
||||
customer: _customerController.text,
|
||||
amount: double.parse(_amountController.text));
|
||||
if (_isNew) {
|
||||
await discountModel.addDiscount(_discount);
|
||||
} else {
|
||||
_discount.id = widget.discount.id;
|
||||
await discountModel.updateDiscount(_discount);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_delete() {
|
||||
showConfirmDialog(
|
||||
context, "cargo_type.edit.delete.confirm", _deleteCargoType);
|
||||
}
|
||||
|
||||
_deleteCargoType() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
var discountModel = Provider.of<DiscountModel>(context, listen: false);
|
||||
await discountModel.deleteCargoType(widget.discount.id);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,16 @@ class DiscountList extends StatefulWidget {
|
||||
|
||||
class _DiscountListState extends State<DiscountList> {
|
||||
bool _isLoading = false;
|
||||
bool _selected = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.selected != null) {
|
||||
_selected = widget.selected;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var discountModel = Provider.of<DiscountModel>(context);
|
||||
@@ -53,7 +63,7 @@ class _DiscountListState extends State<DiscountList> {
|
||||
var discount = discountModel.discounts[index];
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
widget.selected
|
||||
_selected
|
||||
? Navigator.pop(context, discount)
|
||||
: Navigator.push(
|
||||
context,
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/domain/entities/discount.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
|
||||
@@ -38,13 +41,6 @@ class DiscountModel extends BaseModel {
|
||||
return discountList;
|
||||
}
|
||||
|
||||
// List<Discount> get discountByCustomer {
|
||||
// return invoices.where((e) => e.status == "Avaliable").toList()
|
||||
// ..sort((e1, e2) {
|
||||
// return e2.invoiceNumber.compareTo(e1.invoiceNumber);
|
||||
// });
|
||||
// }
|
||||
|
||||
void initUser(user) {
|
||||
super.initUser(user);
|
||||
}
|
||||
@@ -53,4 +49,10 @@ class DiscountModel extends BaseModel {
|
||||
logout() async {
|
||||
// discounts = [];
|
||||
}
|
||||
|
||||
Future<void> addDiscount(Discount discount) {}
|
||||
|
||||
Future<void> updateDiscount(Discount discount) {}
|
||||
|
||||
Future<void> deleteCargoType(String id) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user