null safety

This commit is contained in:
phyothandar
2021-09-10 16:48:21 +06:30
parent 03c5fc5016
commit bb4f4ad7c2
40 changed files with 393 additions and 352 deletions

View File

@@ -12,21 +12,22 @@ class PaymentMethodModel extends BaseModel {
List<PaymentMethod> paymentMethods = [];
PaymentMethod getPaymentMethod(String id) {
return paymentMethods.firstWhere((e) => e.id == id, orElse: () => null);
return paymentMethods.firstWhere((e) => e.id == id);
}
StreamSubscription<QuerySnapshot> listener;
StreamSubscription<QuerySnapshot>? listener;
PaymentMethodModel() {
if (listener != null) listener.cancel();
if (listener != null) listener!.cancel();
try {
listener = Firestore.instance
listener = FirebaseFirestore.instance
.collection("/payment_methods")
.snapshots()
.listen((snaps) {
paymentMethods.clear();
snaps.documents.forEach((d) {
paymentMethods.add(PaymentMethod.fromMap(d.data, d.documentID));
snaps.docs.forEach((d) {
paymentMethods
.add(PaymentMethod.fromMap(d.data as Map<String, dynamic>, d.id));
});
notifyListeners();
});

View File

@@ -38,12 +38,12 @@ class _PaymentMethodEditorState extends State<PaymentMethodEditor> {
if (widget.paymentMethod != null) {
_paymentMethod = widget.paymentMethod;
_nameController.text = _paymentMethod!.name;
_accountNameController.text = _paymentMethod!.accountName;
_accountNumberController.text = _paymentMethod!.account;
_mailController.text = _paymentMethod!.email;
_phoneController.text = _paymentMethod!.phone;
_linkController.text = _paymentMethod!.link;
_nameController.text = _paymentMethod!.name!;
_accountNameController.text = _paymentMethod!.accountName!;
_accountNumberController.text = _paymentMethod!.account!;
_mailController.text = _paymentMethod!.email!;
_phoneController.text = _paymentMethod!.phone!;
_linkController.text = _paymentMethod!.link!;
} else {
_paymentMethod = new PaymentMethod();
_nameController.text = '';
@@ -208,7 +208,7 @@ class _PaymentMethodEditorState extends State<PaymentMethodEditor> {
});
try {
await Provider.of<PaymentMethodModel>(context, listen: false)
.deletePaymentMethod(_paymentMethod!.id);
.deletePaymentMethod(_paymentMethod!.id!);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -84,13 +84,13 @@ class _PaymentMethodPageState extends State<PaymentMethodPage> {
}
_item(PaymentMethod method, bool isEditable) {
final accountName = _itemRow(method.accountName, "pm.account.name",
final accountName = _itemRow(method.accountName!, "pm.account.name",
iconData: MaterialCommunityIcons.bank);
final accountNumber = _itemRow(method.account, "pm.account.no",
final accountNumber = _itemRow(method.account!, "pm.account.no",
iconData: MaterialCommunityIcons.checkbook);
final phone = _itemRow(method.phone, "pm.phone", iconData: Icons.phone);
final email = _itemRow(method.email, "pm.email", iconData: Icons.mail);
final link = _itemRow(method.link, "pm.link", iconData: Icons.link);
final phone = _itemRow(method.phone!, "pm.phone", iconData: Icons.phone);
final email = _itemRow(method.email!, "pm.email", iconData: Icons.mail);
final link = _itemRow(method.link!, "pm.link", iconData: Icons.link);
return InkWell(
onTap: isEditable
@@ -110,7 +110,7 @@ class _PaymentMethodPageState extends State<PaymentMethodPage> {
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
method.name,
method.name!,
style: TextStyle(
color: primaryColor,
fontWeight: FontWeight.bold,