This commit is contained in:
Phaung Phaung
2021-09-10 12:02:08 +06:30
parent a144c945b6
commit c06ae00b68
35 changed files with 190 additions and 223 deletions

View File

@@ -1,24 +1,21 @@
import 'package:fcs/domain/entities/discount.dart';
import 'package:fcs/domain/entities/user.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/user_search/user_serach.dart';
import 'package:fcs/pages/widgets/display_text.dart';
import 'package:fcs/pages/widgets/input_text.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:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
class DiscountEditor extends StatefulWidget {
final Discount discount;
final Discount? discount;
const DiscountEditor({Key key, this.discount}) : super(key: key);
const DiscountEditor({Key? key, this.discount}) : super(key: key);
@override
_DiscountEditorState createState() => _DiscountEditorState();
}
@@ -38,12 +35,12 @@ class _DiscountEditorState extends State<DiscountEditor> {
void initState() {
super.initState();
if (widget.discount != null) {
_discount = widget.discount;
_discount = widget.discount!;
_codeController.text = _discount.code;
_amountController.text = _discount.amount.toStringAsFixed(2);
_statusController.text = _discount.status;
customerName = widget.discount.customerName;
customerId = widget.discount.customerId;
customerName = _discount.customerName;
customerId = _discount.customerId;
} else {
_isNew = true;
}
@@ -71,7 +68,7 @@ class _DiscountEditorState extends State<DiscountEditor> {
children: <Widget>[
Expanded(
child: DisplayText(
text: customerName != null ? customerName : "",
text: customerName,
labelTextKey: "discount.name",
iconData: Feather.user,
)),
@@ -93,7 +90,7 @@ class _DiscountEditorState extends State<DiscountEditor> {
appBar: AppBar(
centerTitle: true,
title: Text(
AppTranslations.of(context).text("discount.form"),
AppTranslations.of(context)!.text("discount.form"),
),
leading: new IconButton(
icon: new Icon(CupertinoIcons.back),
@@ -162,7 +159,7 @@ class _DiscountEditorState extends State<DiscountEditor> {
if (_isNew) {
await discountModel.addDiscount(_discount);
} else {
_discount.id = widget.discount.id;
_discount.id = this._discount.id;
await discountModel.updateDiscount(_discount);
}
Navigator.pop(context);
@@ -186,7 +183,7 @@ class _DiscountEditorState extends State<DiscountEditor> {
});
try {
var discountModel = Provider.of<DiscountModel>(context, listen: false);
await discountModel.deleteDiscount(widget.discount);
await discountModel.deleteDiscount(_discount);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
@@ -208,7 +205,7 @@ class _DiscountEditorState extends State<DiscountEditor> {
customerName: customerName,
customerId: customerId,
amount: double.parse(_amountController.text));
return widget.discount.isChangedForEdit(_discount);
return widget.discount!.isChangedForEdit(_discount);
}
}
}