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);
}
}
}

View File

@@ -16,7 +16,7 @@ import 'discount_editor.dart';
class DiscountList extends StatefulWidget {
final bool selectionMode;
const DiscountList({Key key, this.selectionMode = false}) : super(key: key);
const DiscountList({Key? key, this.selectionMode = false}) : super(key: key);
@override
_DiscountListState createState() => _DiscountListState();
}
@@ -62,7 +62,7 @@ class _DiscountListState extends State<DiscountList> {
appBar: AppBar(
centerTitle: true,
title: Text(
AppTranslations.of(context).text("discount.title"),
AppTranslations.of(context)!.text("discount.title"),
),
leading: new IconButton(
icon: new Icon(CupertinoIcons.back),

View File

@@ -5,15 +5,14 @@ import 'package:fcs/pages/discount/discount_editor.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:intl/intl.dart';
typedef OnSelect(Discount discount);
class DiscountListRow extends StatelessWidget {
final OnSelect onSelect;
final Discount discount;
DiscountListRow({Key key, this.discount, this.onSelect}) : super(key: key);
final OnSelect? onSelect;
final Discount? discount;
DiscountListRow({Key? key, this.discount, this.onSelect}) : super(key: key);
final DateFormat dateFormat = new DateFormat("dd MMM yyyy");
@@ -21,8 +20,8 @@ class DiscountListRow extends StatelessWidget {
Widget build(BuildContext context) {
return InkWell(
onTap: () {
if (onSelect != null) {
onSelect(discount);
if (onSelect != null && discount != null) {
onSelect!(discount!);
}
},
child: Container(
@@ -49,7 +48,7 @@ class DiscountListRow extends StatelessWidget {
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
discount.code ?? "",
discount?.code ?? "",
style: new TextStyle(
fontSize: 15.0, color: Colors.black),
),
@@ -57,7 +56,7 @@ class DiscountListRow extends StatelessWidget {
Padding(
padding: const EdgeInsets.only(left: 10.0, top: 10),
child: new Text(
discount.customerName ?? "",
discount?.customerName ?? "",
style: new TextStyle(
fontSize: 15.0, color: Colors.grey),
),
@@ -73,14 +72,14 @@ class DiscountListRow extends StatelessWidget {
children: <Widget>[
Padding(
padding: const EdgeInsets.all(0),
child: Text(discount.status),
child: Text(discount?.status ?? ''),
),
Padding(
padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5),
child: Row(
children: <Widget>[
new Text(
"${discount.amount.toStringAsFixed(2) ?? ''}",
"${discount?.amount.toStringAsFixed(2) ?? ''}",
style:
new TextStyle(fontSize: 15.0, color: Colors.grey),
),

View File

@@ -11,13 +11,13 @@ import 'package:logging/logging.dart';
class DiscountModel extends BaseModel {
final log = Logger('DiscountModel');
StreamSubscription<QuerySnapshot> listener;
StreamSubscription<QuerySnapshot>? listener;
List<Discount> _discounts = [];
List<Discount> get discounts =>
_selectedIndex == 1 ? _discounts : List<Discount>.from(_used.values);
Paginator _used;
late Paginator _used;
bool isLoading = false;
int _selectedIndex = 1;
set selectedIndex(int index) {
@@ -25,14 +25,14 @@ class DiscountModel extends BaseModel {
notifyListeners();
}
get selectedIndex => _selectedIndex;
int get selectedIndex => _selectedIndex;
initData() {
_selectedIndex = 1;
_load();
if (_used != null) _used.close();
_used = _getUsed();
if (_getUsed() != null) _used = _getUsed()!;
_used.load();
}
@@ -42,7 +42,7 @@ class DiscountModel extends BaseModel {
}
_load() {
if (listener != null) listener.cancel();
if (listener != null) listener!.cancel();
try {
listener = Firestore.instance
.collection("/$discounts_collection")
@@ -60,7 +60,7 @@ class DiscountModel extends BaseModel {
}
}
Paginator _getUsed() {
Paginator? _getUsed() {
if (user == null || !user.hasFcsShipments()) return null;
var pageQuery = Firestore.instance
@@ -73,7 +73,7 @@ class DiscountModel extends BaseModel {
return paginator;
}
Future<List<Discount>> getDiscount(String userID) async {
Future<List<Discount>?> getDiscount(String userID) async {
String path = "/$discounts_collection";
try {
var q = Firestore.instance
@@ -113,7 +113,7 @@ class DiscountModel extends BaseModel {
@override
logout() async {
if (listener != null) await listener.cancel();
if (listener != null) await listener!.cancel();
if (_used != null) _used.close();
_discounts = [];