From d862049b457ca6af9384d722ab23cab8ef7bd96e Mon Sep 17 00:00:00 2001 From: Phaung Phaung Date: Fri, 10 Sep 2021 14:29:55 +0630 Subject: [PATCH 1/3] null safety --- lib/pages/delivery/delivery_info.dart | 3 +- lib/pages/delivery/delivery_list_row.dart | 1 + .../delivery_address_editor.dart | 1 + .../delivery_address_row.dart | 1 + lib/pages/discount/discount_editor.dart | 1 + lib/pages/discount/discount_list_row.dart | 1 + lib/pages/faq/faq_edit_page.dart | 1 + lib/pages/faq/widgets.dart | 8 +++--- .../fcs_shipment/fcs_shipment_editor.dart | 2 +- lib/pages/profile/profile_currency_edit.dart | 4 +-- lib/pages/rates/cargo_editor.dart | 7 +++-- lib/pages/rates/cargo_type_list.dart | 4 +-- lib/pages/rates/custom_editor.dart | 9 +++--- lib/pages/rates/custom_list.dart | 10 +++++-- lib/pages/rates/custom_row.dart | 1 + lib/pages/rates/shipment_rates.dart | 5 ++-- lib/pages/rates/shipment_rates_calculate.dart | 5 ++-- lib/pages/staff/staff_editor.dart | 19 +++++++------ lib/pages/staff/staff_list.dart | 3 +- lib/pages/user_search/user_list_row.dart | 8 +++--- lib/pages/user_search/user_serach.dart | 22 +++++++-------- pubspec.lock | 28 +++++++++++++++++++ 22 files changed, 93 insertions(+), 51 deletions(-) diff --git a/lib/pages/delivery/delivery_info.dart b/lib/pages/delivery/delivery_info.dart index 0f3e423..ff3a4d2 100644 --- a/lib/pages/delivery/delivery_info.dart +++ b/lib/pages/delivery/delivery_info.dart @@ -22,6 +22,7 @@ import 'package:fcs/pages/widgets/local_title.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -214,7 +215,7 @@ class _DeliveryInfoState extends State { ); final shipmentWeightBox = DisplayText( - text: shipmentWeight.toStringAsFixed(0) : "", + text: shipmentWeight.toStringAsFixed(0), labelTextKey: "box.shipment_weight", iconData: MaterialCommunityIcons.weight, ); diff --git a/lib/pages/delivery/delivery_list_row.dart b/lib/pages/delivery/delivery_list_row.dart index d688e2a..c77f115 100644 --- a/lib/pages/delivery/delivery_list_row.dart +++ b/lib/pages/delivery/delivery_list_row.dart @@ -3,6 +3,7 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'delivery_info.dart'; diff --git a/lib/pages/delivery_address/delivery_address_editor.dart b/lib/pages/delivery_address/delivery_address_editor.dart index 336adeb..6bb5be1 100644 --- a/lib/pages/delivery_address/delivery_address_editor.dart +++ b/lib/pages/delivery_address/delivery_address_editor.dart @@ -8,6 +8,7 @@ import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; class DeliveryAddressEditor extends StatefulWidget { diff --git a/lib/pages/delivery_address/delivery_address_row.dart b/lib/pages/delivery_address/delivery_address_row.dart index fd8f576..c6e248c 100644 --- a/lib/pages/delivery_address/delivery_address_row.dart +++ b/lib/pages/delivery_address/delivery_address_row.dart @@ -3,6 +3,7 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; typedef SelectionCallback(DeliveryAddress deliveryAddress); diff --git a/lib/pages/discount/discount_editor.dart b/lib/pages/discount/discount_editor.dart index 742e9c0..1422dee 100644 --- a/lib/pages/discount/discount_editor.dart +++ b/lib/pages/discount/discount_editor.dart @@ -9,6 +9,7 @@ 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_vector_icons/flutter_vector_icons.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; diff --git a/lib/pages/discount/discount_list_row.dart b/lib/pages/discount/discount_list_row.dart index 473b5b3..b2702b2 100644 --- a/lib/pages/discount/discount_list_row.dart +++ b/lib/pages/discount/discount_list_row.dart @@ -5,6 +5,7 @@ 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_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; typedef OnSelect(Discount discount); diff --git a/lib/pages/faq/faq_edit_page.dart b/lib/pages/faq/faq_edit_page.dart index a3c8ad4..885741c 100644 --- a/lib/pages/faq/faq_edit_page.dart +++ b/lib/pages/faq/faq_edit_page.dart @@ -10,6 +10,7 @@ import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; const info = "Select additional page"; diff --git a/lib/pages/faq/widgets.dart b/lib/pages/faq/widgets.dart index ba1c60a..a954882 100644 --- a/lib/pages/faq/widgets.dart +++ b/lib/pages/faq/widgets.dart @@ -7,14 +7,14 @@ Widget itemTitle(BuildContext context, String textKey) { return Padding( padding: const EdgeInsets.only(left: 18.0, top: 15, bottom: 0), child: Text( - AppTranslations.of(context).text(textKey), + AppTranslations.of(context)!.text(textKey), style: TextStyle( fontWeight: FontWeight.bold, fontSize: 18, color: Colors.black), ), ); } -Widget subItemTitle(BuildContext context, String textKey, {IconData iconData}) { +Widget subItemTitle(BuildContext context, String textKey, {IconData? iconData}) { return Padding( padding: const EdgeInsets.only(left: 0, top: 0, bottom: 0), child: Row( @@ -25,7 +25,7 @@ Widget subItemTitle(BuildContext context, String textKey, {IconData iconData}) { ), SizedBox(width: 10), Text( - AppTranslations.of(context).text(textKey), + AppTranslations.of(context)!.text(textKey), style: TextStyle( fontWeight: FontWeight.w700, fontSize: 15, color: primaryColor), ), @@ -35,7 +35,7 @@ Widget subItemTitle(BuildContext context, String textKey, {IconData iconData}) { } Widget contactItem(BuildContext context, String text, IconData iconData, - {Function() onTap, String labelKey}) { + {Function()? onTap, String? labelKey}) { return Material( child: Padding( padding: const EdgeInsets.only(left: 18.0, bottom: 10, right: 18), diff --git a/lib/pages/fcs_shipment/fcs_shipment_editor.dart b/lib/pages/fcs_shipment/fcs_shipment_editor.dart index 05bbc72..006ad94 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_editor.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_editor.dart @@ -143,7 +143,7 @@ class _FcsShipmentEditorState extends State { labelStyle: languageModel.isEng ? newLabelStyle(color: Colors.black54, fontSize: 20) : newLabelStyleMM(color: Colors.black54, fontSize: 20), - labelText: AppTranslations.of(context) + labelText: AppTranslations.of(context)! .text('FCSshipment.shipment_type'), icon: Icon(Ionicons.ios_airplane, color: primaryColor)), items: mainModel.setting.shipmentTypes diff --git a/lib/pages/profile/profile_currency_edit.dart b/lib/pages/profile/profile_currency_edit.dart index f1d3b71..603bfaf 100644 --- a/lib/pages/profile/profile_currency_edit.dart +++ b/lib/pages/profile/profile_currency_edit.dart @@ -77,7 +77,7 @@ class _ProfileCurrencyEditState extends State { onChanged: (Currency? value) { if(value != null) setState(() { - _currency = value!; + _currency = value; }); }, ), @@ -96,7 +96,7 @@ class _ProfileCurrencyEditState extends State { onChanged: (Currency? value) { if(value != null) setState(() { - _currency = value!; + _currency = value; }); }, ), diff --git a/lib/pages/rates/cargo_editor.dart b/lib/pages/rates/cargo_editor.dart index 30224bf..147889f 100644 --- a/lib/pages/rates/cargo_editor.dart +++ b/lib/pages/rates/cargo_editor.dart @@ -31,8 +31,8 @@ class _CargoEditorState extends State { super.initState(); if (widget.cargo != null) { _cargo = widget.cargo!; - _descController.text = _cargo.name; - _rateController.text = _cargo.rate.toStringAsFixed(2); + _descController.text = _cargo.name ?? ''; + _rateController.text = _cargo.rate?.toStringAsFixed(2) ?? ''; } else { _isNew = true; } @@ -138,7 +138,8 @@ class _CargoEditorState extends State { try { var shipmentRateModel = Provider.of(context, listen: false); - await shipmentRateModel.deleteCargoType(this._cargo.id); + if(this._cargo.id != null) + await shipmentRateModel.deleteCargoType(this._cargo.id!); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/rates/cargo_type_list.dart b/lib/pages/rates/cargo_type_list.dart index aa5ac42..8e4776e 100644 --- a/lib/pages/rates/cargo_type_list.dart +++ b/lib/pages/rates/cargo_type_list.dart @@ -75,8 +75,8 @@ class _CargoTypeListState extends State { ))); }, child: Container( - child: _row(cargo.name, - "\$ " + cargo.rate.toStringAsFixed(2), 'per pound'), + child: _row(cargo.name?? '', + "\$ " + cargo.rate!.toStringAsFixed(2), 'per pound'), ), ); }), diff --git a/lib/pages/rates/custom_editor.dart b/lib/pages/rates/custom_editor.dart index 17444e2..b6c6b2f 100644 --- a/lib/pages/rates/custom_editor.dart +++ b/lib/pages/rates/custom_editor.dart @@ -33,10 +33,10 @@ class _CustomEditorState extends State { super.initState(); if (widget.custom != null) { _custom = widget.custom!; - _productController.text = _custom.name; - _feeController.text = _custom.customDutyFee.toStringAsFixed(2); + _productController.text = _custom.name ?? ''; + _feeController.text = _custom.customDutyFee?.toStringAsFixed(2) ?? ''; _shipmentRateController.text = - _custom.rate == null ? "" : _custom.rate.toStringAsFixed(2); + _custom.rate == null ? "" : _custom.rate?.toStringAsFixed(2) ?? ''; } else { _isNew = true; } @@ -154,7 +154,8 @@ class _CustomEditorState extends State { try { var shipmentRateModel = Provider.of(context, listen: false); - await shipmentRateModel.deleteCustomDuty(this._custom.id); + if(this._custom.id != null) + await shipmentRateModel.deleteCustomDuty(this._custom.id!); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/rates/custom_list.dart b/lib/pages/rates/custom_list.dart index 8512b4a..abf9188 100644 --- a/lib/pages/rates/custom_list.dart +++ b/lib/pages/rates/custom_list.dart @@ -81,11 +81,15 @@ class _CustomListState extends State { }, child: Container( child: _row( - custom.name, - "Custom Fee \$ " + custom.customDutyFee.toStringAsFixed(2), + custom.name ?? '', + custom.customDutyFee == null + ? "" + : "Custom Fee \$ " + + custom.customDutyFee!.toStringAsFixed(2), custom.rate == null ? "" - : "Shipment rate \$ " + custom.rate.toStringAsFixed(2)), + : "Shipment rate \$ " + + custom.rate!.toStringAsFixed(2)), ), ); }), diff --git a/lib/pages/rates/custom_row.dart b/lib/pages/rates/custom_row.dart index ae14714..937d6df 100644 --- a/lib/pages/rates/custom_row.dart +++ b/lib/pages/rates/custom_row.dart @@ -4,6 +4,7 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; typedef SelectionCallback(CustomDuty custom); diff --git a/lib/pages/rates/shipment_rates.dart b/lib/pages/rates/shipment_rates.dart index ff4d865..c7ecef8 100644 --- a/lib/pages/rates/shipment_rates.dart +++ b/lib/pages/rates/shipment_rates.dart @@ -1,5 +1,4 @@ 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'; @@ -186,7 +185,7 @@ class _ShipmentRatesState extends State { return cargos.map((cargo) { return Container( child: _row( - cargo.name, "\$ " + cargo.rate.toStringAsFixed(2), 'per pound'), + cargo.name ?? '', "\$ " + cargo.rate!.toStringAsFixed(2), 'per pound'), ); }).toList(); } @@ -194,7 +193,7 @@ class _ShipmentRatesState extends State { List getCustonWidget(List customs) { return customs.map((c) { return Container( - child: _row(c.name, "\$ " + c.customDutyFee.toStringAsFixed(2), ''), + child: _row(c.name ?? '', "\$ " + c.customDutyFee!.toStringAsFixed(2), ''), ); }).toList(); } diff --git a/lib/pages/rates/shipment_rates_calculate.dart b/lib/pages/rates/shipment_rates_calculate.dart index e0526fd..c01111a 100644 --- a/lib/pages/rates/shipment_rates_calculate.dart +++ b/lib/pages/rates/shipment_rates_calculate.dart @@ -11,6 +11,7 @@ import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; class ShipmentRatesCal extends StatefulWidget { @@ -61,11 +62,11 @@ class _ShipmentRatesCalState extends State { var amount = box.calAmount(rate); var shipmentWeight = box.getShipmentWeight(rate.volumetricRatio); var effectiveWeight = - _cargoType.weight > shipmentWeight ? _cargoType.weight : shipmentWeight; + _cargoType.weight! > shipmentWeight ? _cargoType.weight : shipmentWeight; setState(() { _deliveryFee = - effectiveWeight > rate.freeDeliveryWeight ? 0 : rate.deliveryFee; + effectiveWeight! > rate.freeDeliveryWeight ? 0 : rate.deliveryFee; _amount = amount == null ? 0 : amount + _deliveryFee; _shipmentWeight = shipmentWeight.toDouble(); }); diff --git a/lib/pages/staff/staff_editor.dart b/lib/pages/staff/staff_editor.dart index 4812c32..6cf876c 100644 --- a/lib/pages/staff/staff_editor.dart +++ b/lib/pages/staff/staff_editor.dart @@ -15,7 +15,7 @@ import 'package:provider/provider.dart'; typedef void FindCallBack(); class StaffEditor extends StatefulWidget { - final User staff; + final User? staff; const StaffEditor({this.staff}); @override _StaffEditorState createState() => _StaffEditorState(); @@ -25,8 +25,8 @@ class _StaffEditorState extends State { TextEditingController _phoneInput = new TextEditingController(); bool _isLoading = false; - User user; - User selectedUser; + late User user; + User? selectedUser; List privileges = []; bool isNew = true; @@ -38,8 +38,8 @@ class _StaffEditorState extends State { user = User(); if (!isNew) { user = - User(name: widget.staff.name, phoneNumber: widget.staff.phoneNumber); - user.privileges = widget.staff.privileges; + User(name: widget.staff!.name, phoneNumber: widget.staff!.phoneNumber); + user.privileges = widget.staff!.privileges; privileges.forEach((p) => user.privileges.contains(p.id) ? p.isChecked = true : p.isChecked = false); @@ -64,7 +64,8 @@ class _StaffEditorState extends State { new Checkbox( value: p.isChecked == null ? false : p.isChecked, activeColor: primaryColor, - onChanged: (bool value) { + onChanged: (bool? value) { + if(value != null) setState(() { p.isChecked = value; }); @@ -110,7 +111,7 @@ class _StaffEditorState extends State { style: textStyle, decoration: new InputDecoration( labelText: - AppTranslations.of(context).text('staff.phone.search'), + AppTranslations.of(context)!.text('staff.phone.search'), labelStyle: languageModel.isEng ? labelStyle : labelStyleMM, // icon: Icon( // Icons.search, @@ -226,7 +227,7 @@ class _StaffEditorState extends State { }); StaffModel staffModel = Provider.of(context, listen: false); try { - await staffModel.updatePrivileges(this.selectedUser.id, privilegesIDs()); + await staffModel.updatePrivileges(this.selectedUser!.id, privilegesIDs()); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); @@ -248,7 +249,7 @@ class _StaffEditorState extends State { if (widget.staff == null) return; StaffModel staffModel = Provider.of(context, listen: false); try { - await staffModel.updatePrivileges(widget.staff.id, privilegesIDs()); + await staffModel.updatePrivileges(widget.staff!.id, privilegesIDs()); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/staff/staff_list.dart b/lib/pages/staff/staff_list.dart index fabcc6c..0fe6735 100644 --- a/lib/pages/staff/staff_list.dart +++ b/lib/pages/staff/staff_list.dart @@ -5,7 +5,6 @@ import 'package:fcs/pages/widgets/local_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:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -84,7 +83,7 @@ class _StaffListState extends State { padding: new EdgeInsets.symmetric( horizontal: 32.0 - dotSize / 2), child: Icon( - MaterialCommunityIcons.worker, + Icons.person, color: primaryColor, size: 40, ), diff --git a/lib/pages/user_search/user_list_row.dart b/lib/pages/user_search/user_list_row.dart index da8822f..2fb7b74 100644 --- a/lib/pages/user_search/user_list_row.dart +++ b/lib/pages/user_search/user_list_row.dart @@ -4,9 +4,9 @@ import 'package:fcs/pages/user_search/user_serach.dart'; import 'package:flutter/material.dart'; class UserListRow extends StatefulWidget { - final OnUserRowSelect onUserRowSelect; + final OnUserRowSelect? onUserRowSelect; final User user; - const UserListRow({this.user, this.onUserRowSelect}); + const UserListRow({required this.user, this.onUserRowSelect}); @override _UserListRowState createState() => _UserListRowState(); @@ -14,7 +14,7 @@ class UserListRow extends StatefulWidget { class _UserListRowState extends State { final double dotSize = 15.0; - User user; + late User user; @override void initState() { super.initState(); @@ -31,7 +31,7 @@ class _UserListRowState extends State { child: InkWell( onTap: () { if (widget.onUserRowSelect != null) - widget.onUserRowSelect(widget.user); + widget.onUserRowSelect!(widget.user); }, child: Row( children: [ diff --git a/lib/pages/user_search/user_serach.dart b/lib/pages/user_search/user_serach.dart index 0225b62..5d4bfb6 100644 --- a/lib/pages/user_search/user_serach.dart +++ b/lib/pages/user_search/user_serach.dart @@ -8,8 +8,8 @@ import 'package:provider/provider.dart'; typedef OnUserSelect(User suer); typedef OnUserRowSelect(User suer); -Future searchUser(BuildContext context, - {OnUserSelect onUserSelect, bool popPage = false}) async => +Future searchUser(BuildContext context, + {required OnUserSelect onUserSelect, bool popPage = false}) async => await showSearch( context: context, delegate: @@ -17,10 +17,10 @@ Future searchUser(BuildContext context, ); class UserSearchDelegate extends SearchDelegate { - final OnUserSelect onUserSelect; + final OnUserSelect? onUserSelect; final bool popPage; - UserSearchDelegate({this.onUserSelect, this.popPage}); + UserSearchDelegate({this.onUserSelect, required this.popPage}); @override String get searchFieldLabel => 'Search by FCS ID or Name'; @@ -31,10 +31,10 @@ class UserSearchDelegate extends SearchDelegate { return theme.copyWith( inputDecorationTheme: InputDecorationTheme( hintStyle: TextStyle( - color: theme.primaryTextTheme.caption.color, fontSize: 14)), + color: theme.primaryTextTheme.caption?.color, fontSize: 14)), textTheme: theme.textTheme.copyWith( - title: theme.textTheme.title.copyWith( - color: theme.primaryTextTheme.title.color, fontSize: 16)), + title: theme.textTheme.title?.copyWith( + color: theme.primaryTextTheme.title?.color, fontSize: 16)), primaryColor: primaryColor, ); } @@ -53,7 +53,7 @@ class UserSearchDelegate extends SearchDelegate { Widget buildLeading(BuildContext context) { return IconButton( icon: Icon(Icons.arrow_back), - onPressed: () => close(context, null), + onPressed: () => close(context,User()), ); } @@ -64,7 +64,7 @@ class UserSearchDelegate extends SearchDelegate { future: packageModel.searchUser(query), builder: (context, AsyncSnapshot> snapshot) { if (snapshot.hasData) { - if (snapshot.data.length == 0) { + if (snapshot.data?.length == 0) { return Container( child: Center( child: Text( @@ -77,7 +77,7 @@ class UserSearchDelegate extends SearchDelegate { return Container( padding: EdgeInsets.only(top: 15), child: ListView( - children: snapshot.data + children: snapshot.data! .map((u) => UserListRow( user: u, onUserRowSelect: (u) => _onUserRowSelect(context, u), @@ -119,7 +119,7 @@ class UserSearchDelegate extends SearchDelegate { _onUserRowSelect(BuildContext context, User user) { if (onUserSelect != null) { - onUserSelect(user); + onUserSelect!(user); } if (popPage) { Navigator.pop(context); diff --git a/pubspec.lock b/pubspec.lock index a551a79..2abfb07 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -349,6 +349,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.5.1" + flutter_local_notifications: + dependency: "direct main" + description: + name: flutter_local_notifications + url: "https://pub.dartlang.org" + source: hosted + version: "8.2.0" + flutter_local_notifications_platform_interface: + dependency: transitive + description: + name: flutter_local_notifications_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.1" flutter_localizations: dependency: "direct main" description: flutter @@ -373,6 +387,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_vector_icons: + dependency: "direct main" + description: + name: flutter_vector_icons + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" flutter_web_plugins: dependency: transitive description: flutter @@ -866,6 +887,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.5" + timezone: + dependency: transitive + description: + name: timezone + url: "https://pub.dartlang.org" + source: hosted + version: "0.8.0" typed_data: dependency: transitive description: From 376153e22f22fddd091c53d7ef6427b1236a8d41 Mon Sep 17 00:00:00 2001 From: Phaung Phaung Date: Fri, 10 Sep 2021 15:23:13 +0630 Subject: [PATCH 2/3] null safety --- lib/pages/delivery/delivery_info.dart | 18 ++++++------- lib/pages/delivery/model/delivery_model.dart | 2 +- .../delivery_address_editor.dart | 12 ++++----- lib/pages/discount/discount_editor.dart | 12 ++++----- lib/pages/faq/faq_detail_page.dart | 3 ++- lib/pages/faq/faq_edit_page.dart | 14 +++++------ .../fcs_shipment/fcs_shipment_editor.dart | 19 ++++++++------ lib/pages/fcs_shipment/fcs_shipment_info.dart | 25 +++++++++++-------- .../fcs_shipment/fcs_shipment_list_row.dart | 8 +++--- .../main/initial_language_selection.dart | 2 +- lib/pages/staff/staff_editor.dart | 14 +++++------ lib/pages/staff/staff_list.dart | 4 +-- lib/pages/user_search/user_list_row.dart | 6 ++--- pubspec.lock | 7 ++++++ 14 files changed, 80 insertions(+), 66 deletions(-) diff --git a/lib/pages/delivery/delivery_info.dart b/lib/pages/delivery/delivery_info.dart index ff3a4d2..20746c9 100644 --- a/lib/pages/delivery/delivery_info.dart +++ b/lib/pages/delivery/delivery_info.dart @@ -60,9 +60,8 @@ class _DeliveryInfoState extends State { @override void initState() { super.initState(); - if(widget.box != null) - _box = widget.box!; - _selectedCartonType = _box.cartonType; + if (widget.box != null) _box = widget.box!; + _selectedCartonType = _box.cartonType ?? ''; //for shipment weight volumetricRatio = Provider.of(context, listen: false) @@ -81,7 +80,7 @@ class _DeliveryInfoState extends State { _heightController.text = _box.height.toString(); _lengthController.text = _box.length.toString(); _cargoTypes = _box.cargoTypes; - _deliveryAddress = _box.deliveryAddress; + _deliveryAddress = _box.deliveryAddress!; isMixBox = _box.cartonType == carton_mix_box; isFromShipments = _box.cartonType == carton_from_shipments; isFromPackages = _box.cartonType == carton_from_packages; @@ -97,7 +96,7 @@ class _DeliveryInfoState extends State { if (_box.cartonType == carton_from_packages && _box.userID == null) return; PackageModel packageModel = Provider.of(context, listen: false); - List packages = await packageModel.getPackages(_box.userID, [ + List packages = await packageModel.getPackages(_box.userID!, [ package_processed_status, package_packed_status, package_shipped_status, @@ -136,8 +135,9 @@ class _DeliveryInfoState extends State { final cartonTypeBox = LocalRadioButtons( readOnly: true, values: cartonModel.cartonTypesInfo, - selectedValue: - _box.isShipmentCarton ? carton_from_shipments : _box.cartonType); + selectedValue: _box.isShipmentCarton ?? false + ? carton_from_shipments + : _box.cartonType); final shipmentBox = DisplayText( text: _box.fcsShipmentNumber, labelTextKey: "box.fcs_shipment_num", @@ -174,11 +174,11 @@ class _DeliveryInfoState extends State { children: [ Expanded( child: new Text( - _selectedShipmentBox.shipmentNumber, + _selectedShipmentBox.shipmentNumber ?? "", style: textStyle, )), new Text( - _selectedShipmentBox.desc, + _selectedShipmentBox.desc ?? "", style: textStyle, ), ], diff --git a/lib/pages/delivery/model/delivery_model.dart b/lib/pages/delivery/model/delivery_model.dart index b200684..ac89a7b 100644 --- a/lib/pages/delivery/model/delivery_model.dart +++ b/lib/pages/delivery/model/delivery_model.dart @@ -42,7 +42,7 @@ class DeliveryModel extends BaseModel { if (listener != null) listener.cancel(); _cartons = []; try { - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection("$path") .where("status", isEqualTo: carton_shipped_status) .where("carton_type", whereIn: [ diff --git a/lib/pages/delivery_address/delivery_address_editor.dart b/lib/pages/delivery_address/delivery_address_editor.dart index 6bb5be1..aa84ba2 100644 --- a/lib/pages/delivery_address/delivery_address_editor.dart +++ b/lib/pages/delivery_address/delivery_address_editor.dart @@ -39,12 +39,12 @@ class _DeliveryAddressEditorState extends State { if (widget.deliveryAddress != null) { _isNew = false; _deliveryAddress = widget.deliveryAddress!; - _nameController.text = _deliveryAddress.fullName; - _address1Controller.text = _deliveryAddress.addressLine1; - _address2Controller.text = _deliveryAddress.addressLine2; - _cityController.text = _deliveryAddress.city; - _stateController.text = _deliveryAddress.state; - _phoneController.text = _deliveryAddress.phoneNumber; + _nameController.text = _deliveryAddress.fullName ?? ""; + _address1Controller.text = _deliveryAddress.addressLine1 ?? ""; + _address2Controller.text = _deliveryAddress.addressLine2 ?? ""; + _cityController.text = _deliveryAddress.city ?? ""; + _stateController.text = _deliveryAddress.state ?? ""; + _phoneController.text = _deliveryAddress.phoneNumber?? ""; } else { _cityController.text = "Yangon"; _stateController.text = "Yangon"; diff --git a/lib/pages/discount/discount_editor.dart b/lib/pages/discount/discount_editor.dart index 1422dee..3b66baf 100644 --- a/lib/pages/discount/discount_editor.dart +++ b/lib/pages/discount/discount_editor.dart @@ -37,11 +37,11 @@ class _DiscountEditorState extends State { super.initState(); if (widget.discount != null) { _discount = widget.discount!; - _codeController.text = _discount.code; + _codeController.text = _discount.code ?? ""; _amountController.text = _discount.amount.toStringAsFixed(2); - _statusController.text = _discount.status; - customerName = _discount.customerName; - customerId = _discount.customerId; + _statusController.text = _discount.status ?? ''; + customerName = _discount.customerName ?? ""; + customerId = _discount.customerId ?? ""; } else { _isNew = true; } @@ -77,8 +77,8 @@ class _DiscountEditorState extends State { icon: Icon(Icons.search, color: primaryColor), onPressed: () => searchUser(context, onUserSelect: (u) { setState(() { - customerId = u.id; - customerName = u.name; + customerId = u.id ?? ""; + customerName = u.name ?? ""; }); },popPage: true)), ], diff --git a/lib/pages/faq/faq_detail_page.dart b/lib/pages/faq/faq_detail_page.dart index 9e7ea4b..d2bd99c 100644 --- a/lib/pages/faq/faq_detail_page.dart +++ b/lib/pages/faq/faq_detail_page.dart @@ -28,7 +28,8 @@ class _FAQDetailPageState extends State { @override Widget build(BuildContext context) { - faq = context.select((FAQModel m) => m.getFAQ(widget.faq.id)); + if(widget.faq.id != null) + faq = context.select((FAQModel m) => m.getFAQ(widget.faq.id!)); if (faq == null) return Text("Deleted"); bool isEditable = context.select((MainModel m) => m.faqEditable()); diff --git a/lib/pages/faq/faq_edit_page.dart b/lib/pages/faq/faq_edit_page.dart index 885741c..d56471c 100644 --- a/lib/pages/faq/faq_edit_page.dart +++ b/lib/pages/faq/faq_edit_page.dart @@ -44,13 +44,13 @@ class _FAQEditorState extends State { if (widget.faq != null) { _faq = widget.faq!; _sn.text = _faq.sn.toString(); - _engQ.text = _faq.questionEng; - _mmQ.text = _faq.questionMm; - _engA.text = _faq.answerEng; - _mmA.text = _faq.answerMm; - _pageLabelEng.text = _faq.pageLinkLabelEng; - _pageLabelMm.text = _faq.pageLinkLabelMm; - _pageLink = _faq.pageLink; + _engQ.text = _faq.questionEng ?? ""; + _mmQ.text = _faq.questionMm ?? ''; + _engA.text = _faq.answerEng ?? ''; + _mmA.text = _faq.answerMm ?? ''; + _pageLabelEng.text = _faq.pageLinkLabelEng ?? ""; + _pageLabelMm.text = _faq.pageLinkLabelMm ?? ""; + _pageLink = _faq.pageLink ?? ''; } } diff --git a/lib/pages/fcs_shipment/fcs_shipment_editor.dart b/lib/pages/fcs_shipment/fcs_shipment_editor.dart index 006ad94..e14fed6 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_editor.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_editor.dart @@ -49,16 +49,19 @@ class _FcsShipmentEditorState extends State { _isNew = widget.shipment == null; if (widget.shipment != null) { _shipment = widget.shipment!; - _shipmentNumberController.text = _shipment.shipmentNumber; - _cutoffDateController.text = dateFormatter.format(_shipment.cutoffDate); - _arrivalDateController.text = dateFormatter.format(_shipment.arrivalDate); + _shipmentNumberController.text = _shipment.shipmentNumber ?? ""; + if(_shipment.cutoffDate != null) + _cutoffDateController.text = dateFormatter.format(_shipment.cutoffDate!); + if(_shipment.arrivalDate != null) + _arrivalDateController.text = dateFormatter.format(_shipment.arrivalDate!); + if(_shipment.departureDate != null) _departureDateControler.text = - dateFormatter.format(_shipment.departureDate); - _statusController.text = _shipment.status; + dateFormatter.format(_shipment.departureDate!); + _statusController.text = _shipment.status ?? ""; _currentShipmentType = _shipment.shipType; - _consigneeController.text = _shipment.consignee; - _portController.text = _shipment.port; - _destinationController.text = _shipment.destination; + _consigneeController.text = _shipment.consignee ?? ""; + _portController.text = _shipment.port ?? ""; + _destinationController.text = _shipment.destination ?? ""; } else { var mainModel = Provider.of(context, listen: false); _currentShipmentType = mainModel.setting.shipmentTypes[0]; diff --git a/lib/pages/fcs_shipment/fcs_shipment_info.dart b/lib/pages/fcs_shipment/fcs_shipment_info.dart index 3635571..ffd7723 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_info.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_info.dart @@ -48,17 +48,20 @@ class _FcsShipmentInfoState extends State { } _load() { - _shipmentNumberController.text = _fcsShipment!.shipmentNumber; - _cutoffDateController.text = dateFormatter.format(_fcsShipment!.cutoffDate); + _shipmentNumberController.text = _fcsShipment!.shipmentNumber ?? ""; + if(_fcsShipment!.cutoffDate != null) + _cutoffDateController.text = dateFormatter.format(_fcsShipment!.cutoffDate!); + if(_fcsShipment!.arrivalDate != null) _arrivalDateController.text = - dateFormatter.format(_fcsShipment!.arrivalDate); + dateFormatter.format(_fcsShipment!.arrivalDate!); + if(_fcsShipment!.departureDate != null) _departureDateControler.text = - dateFormatter.format(_fcsShipment!.departureDate); - _shipmentTypeControler.text = _fcsShipment!.shipType; - _consigneeController.text = _fcsShipment!.consignee; - _portController.text = _fcsShipment!.port; - _destinationController.text = _fcsShipment!.destination; - _statusController.text = _fcsShipment!.status; + dateFormatter.format(_fcsShipment!.departureDate!); + _shipmentTypeControler.text = _fcsShipment!.shipType ?? ""; + _consigneeController.text = _fcsShipment!.consignee ?? ""; + _portController.text = _fcsShipment!.port ?? ""; + _destinationController.text = _fcsShipment!.destination ?? ""; + _statusController.text = _fcsShipment!.status ?? ""; } @override @@ -182,6 +185,7 @@ class _FcsShipmentInfoState extends State { } _edit() async { + var f; bool? updated = await Navigator.push( context, CupertinoPageRoute( @@ -189,7 +193,8 @@ class _FcsShipmentInfoState extends State { ); if (updated ?? false) { var shipmentModel = Provider.of(context, listen: false); - var f = await shipmentModel.getFcsShipment(_fcsShipment!.id); + if(_fcsShipment != null && _fcsShipment!.id != null ) + f = await shipmentModel.getFcsShipment(_fcsShipment!.id!); setState(() { _fcsShipment = f; }); diff --git a/lib/pages/fcs_shipment/fcs_shipment_list_row.dart b/lib/pages/fcs_shipment/fcs_shipment_list_row.dart index 3a6da34..b16e410 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_list_row.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_list_row.dart @@ -43,9 +43,7 @@ class FcsShipmentListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - shipment!.shipmentNumber == null - ? '' - : shipment!.shipmentNumber, + shipment?.shipmentNumber ?? '', style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -53,7 +51,7 @@ class FcsShipmentListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 10.0, top: 10), child: new Text( - dateFormatter.format(shipment!.cutoffDate), + dateFormatter.format(shipment!.cutoffDate!), style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), @@ -67,7 +65,7 @@ class FcsShipmentListRow extends StatelessWidget { ), Padding( padding: const EdgeInsets.all(0), - child: getStatus(shipment!.status), + child: getStatus(shipment!.status ?? ''), ), ], ), diff --git a/lib/pages/main/initial_language_selection.dart b/lib/pages/main/initial_language_selection.dart index 0253db3..1dd0864 100644 --- a/lib/pages/main/initial_language_selection.dart +++ b/lib/pages/main/initial_language_selection.dart @@ -177,7 +177,7 @@ class _InitialLanguageSelectionPageState setState(() { selectedIndex = index; selectedLanguage = lang; - Translation().onLocaleChanged!(Locale(languagesMap[lang])); + Translation().onLocaleChanged(Locale(languagesMap[lang])); Provider.of(context, listen: false) .saveLanguage(selectedLanguage); }); diff --git a/lib/pages/staff/staff_editor.dart b/lib/pages/staff/staff_editor.dart index 6cf876c..5a703b0 100644 --- a/lib/pages/staff/staff_editor.dart +++ b/lib/pages/staff/staff_editor.dart @@ -56,7 +56,7 @@ class _StaffEditorState extends State { title: InkWell( onTap: () { setState(() { - p.isChecked = p.isChecked == null ? true : !p.isChecked; + p.isChecked = p.isChecked == null ? true : !p.isChecked!; }); }, child: new Row( @@ -79,10 +79,10 @@ class _StaffEditorState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ new Text( - p.name, + p.name ??"", style: TextStyle(fontSize: 15.0, color: primaryColor), ), - Text(p.desc, + Text(p.desc ?? "", style: TextStyle(fontSize: 13, color: Colors.grey[600])) ], ), @@ -151,7 +151,7 @@ class _StaffEditorState extends State { ? Container() : IconButton( icon: Icon(Icons.open_in_new, color: primaryColor), - onPressed: () => call(context, user.phoneNumber)), + onPressed: () => call(context, user.phoneNumber!)), ], ); @@ -227,7 +227,7 @@ class _StaffEditorState extends State { }); StaffModel staffModel = Provider.of(context, listen: false); try { - await staffModel.updatePrivileges(this.selectedUser!.id, privilegesIDs()); + await staffModel.updatePrivileges(this.selectedUser!.id!, privilegesIDs()); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); @@ -239,7 +239,7 @@ class _StaffEditorState extends State { } List privilegesIDs() { - return this.privileges.where((p) => p.isChecked).map((p) => p.id).toList(); + return this.privileges.where((p) => p.isChecked!).map((p) => p.id).toList(); } _save() async { @@ -249,7 +249,7 @@ class _StaffEditorState extends State { if (widget.staff == null) return; StaffModel staffModel = Provider.of(context, listen: false); try { - await staffModel.updatePrivileges(widget.staff!.id, privilegesIDs()); + await staffModel.updatePrivileges(widget.staff!.id!, privilegesIDs()); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/staff/staff_list.dart b/lib/pages/staff/staff_list.dart index 0fe6735..11fd119 100644 --- a/lib/pages/staff/staff_list.dart +++ b/lib/pages/staff/staff_list.dart @@ -93,13 +93,13 @@ class _StaffListState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ new Text( - user.name, + user.name ?? "", style: new TextStyle(fontSize: 15.0), ), Padding( padding: const EdgeInsets.only(top: 8.0), child: new Text( - user.phoneNumber, + user.phoneNumber ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), diff --git a/lib/pages/user_search/user_list_row.dart b/lib/pages/user_search/user_list_row.dart index 2fb7b74..5760047 100644 --- a/lib/pages/user_search/user_list_row.dart +++ b/lib/pages/user_search/user_list_row.dart @@ -53,17 +53,17 @@ class _UserListRowState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ new Text( - user.name == null ? '' : user.name, + user.name ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.black), ), new Text( - user.fcsID == null ? "" : user.fcsID, + user.fcsID ?? "", style: new TextStyle( fontSize: 13.0, color: Colors.grey), ), new Text( - user.phoneNumber == null ? "" : user.phoneNumber, + user.phoneNumber ?? "", style: new TextStyle( fontSize: 13.0, color: Colors.grey), ), diff --git a/pubspec.lock b/pubspec.lock index 2abfb07..20ac1cb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -349,6 +349,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.5.1" + flutter_icons_null_safety: + dependency: "direct main" + description: + name: flutter_icons_null_safety + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" flutter_local_notifications: dependency: "direct main" description: From 0f84fec2f742c6042a472b3789bc14f8f15def30 Mon Sep 17 00:00:00 2001 From: Phaung Phaung Date: Fri, 10 Sep 2021 16:48:20 +0630 Subject: [PATCH 3/3] null safety --- lib/pages/delivery/delivery_info.dart | 2 +- lib/pages/delivery/model/delivery_model.dart | 20 ++++---- .../model/delivery_address_model.dart | 35 +++++++------- lib/pages/discount/model/discount_model.dart | 28 +++++------ lib/pages/faq/model/faq_model.dart | 12 ++--- .../fcs_shipment/fcs_shipment_editor.dart | 6 +-- .../model/fcs_shipment_model.dart | 48 +++++++++---------- .../invoice/editor/invoice_discount_list.dart | 6 +-- lib/pages/invoice/editor/invoice_editor.dart | 2 +- lib/pages/staff/model/staff_model.dart | 36 +++++++------- lib/pages/staff/staff_editor.dart | 2 +- .../widgets/local_popup_menu_button.dart | 12 ++--- 12 files changed, 103 insertions(+), 106 deletions(-) diff --git a/lib/pages/delivery/delivery_info.dart b/lib/pages/delivery/delivery_info.dart index 20746c9..fef0d5e 100644 --- a/lib/pages/delivery/delivery_info.dart +++ b/lib/pages/delivery/delivery_info.dart @@ -135,7 +135,7 @@ class _DeliveryInfoState extends State { final cartonTypeBox = LocalRadioButtons( readOnly: true, values: cartonModel.cartonTypesInfo, - selectedValue: _box.isShipmentCarton ?? false + selectedValue: (_box.isShipmentCarton ?? false) ? carton_from_shipments : _box.cartonType); final shipmentBox = DisplayText( diff --git a/lib/pages/delivery/model/delivery_model.dart b/lib/pages/delivery/model/delivery_model.dart index ac89a7b..235f820 100644 --- a/lib/pages/delivery/model/delivery_model.dart +++ b/lib/pages/delivery/model/delivery_model.dart @@ -14,18 +14,18 @@ class DeliveryModel extends BaseModel { List get cartons => _selectedIndex == 1 ? _cartons : List.from(_delivered.values); - Paginator _delivered; + late Paginator _delivered; int _selectedIndex = 1; bool isLoading = false; List _cartons = []; - StreamSubscription listener; + StreamSubscription? listener; set selectedIndex(int index) { _selectedIndex = index; notifyListeners(); } - get selectedIndex => _selectedIndex; + int get selectedIndex => _selectedIndex; initData() { _selectedIndex = 1; @@ -37,9 +37,9 @@ class DeliveryModel extends BaseModel { } Future _loadCartons() async { - if (user == null || !user.hasDeliveries()) return; + if (user == null || !user!.hasDeliveries()) return; String path = "/$cartons_collection/"; - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); _cartons = []; try { listener = FirebaseFirestore.instance @@ -55,9 +55,9 @@ class DeliveryModel extends BaseModel { .snapshots() .listen((QuerySnapshot snapshot) { _cartons.clear(); - _cartons = snapshot.documents.map((documentSnapshot) { + _cartons = snapshot.docs.map((documentSnapshot) { var s = Carton.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, documentSnapshot.id); return s; }).toList(); notifyListeners(); @@ -68,9 +68,9 @@ class DeliveryModel extends BaseModel { } Paginator _getDelivered() { - if (user == null || !user.hasDeliveries()) return null; + if (user == null || !user!.hasDeliveries()) throw "No Privilege"; - var pageQuery = Firestore.instance + var pageQuery = FirebaseFirestore.instance .collection("/$cartons_collection") .where("is_delivered", isEqualTo: true) .where("status", whereIn: [carton_delivered_status]).where("is_deleted", @@ -105,7 +105,7 @@ class DeliveryModel extends BaseModel { @override logout() async { - if (listener != null) await listener.cancel(); + if (listener != null) await listener!.cancel(); if (_delivered != null) _delivered.close(); _cartons = []; } diff --git a/lib/pages/delivery_address/model/delivery_address_model.dart b/lib/pages/delivery_address/model/delivery_address_model.dart index a344c82..0ccbf33 100644 --- a/lib/pages/delivery_address/model/delivery_address_model.dart +++ b/lib/pages/delivery_address/model/delivery_address_model.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'package:barcode_scan2/gen/protos/protos.pb.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:fcs/data/services/services.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; @@ -10,13 +11,13 @@ class DeliveryAddressModel extends BaseModel { final log = Logger('FcsShipmentModel'); List deliveryAddresses = []; - StreamSubscription listener; + StreamSubscription? listener; DeliveryAddress get defalutAddress => - deliveryAddresses.firstWhere((e) => e.isDefault, orElse: () => null); + deliveryAddresses.firstWhere((e) => e.isDefault, orElse: () => DeliveryAddress()); DeliveryAddress getLocalDeliveryAddress(String id) => - deliveryAddresses.firstWhere((e) => e.id == id, orElse: () => null); + deliveryAddresses.firstWhere((e) => e.id == id, orElse: () => DeliveryAddress()); @override void privilegeChanged() { @@ -26,26 +27,26 @@ class DeliveryAddressModel extends BaseModel { @override logout() async { - if (listener != null) await listener.cancel(); + if (listener != null) await listener!.cancel(); deliveryAddresses = []; } Future _loadDeliveryAddresses() async { if (user == null) return; String path = "$delivery_address_collection/"; - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); deliveryAddresses = []; try { - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection('users') - .document("${user.id}") + .doc("${user!.id}") .collection("$path") .snapshots() .listen((QuerySnapshot snapshot) { deliveryAddresses.clear(); - deliveryAddresses = snapshot.documents.map((documentSnapshot) { + deliveryAddresses = snapshot.docs.map((documentSnapshot) { var s = DeliveryAddress.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, documentSnapshot.id); return s; }).toList(); notifyListeners(); @@ -56,9 +57,9 @@ class DeliveryAddressModel extends BaseModel { } Future getDeliveryAddress(String id) async { - String path = "/$user_collection/${user.id}/$delivery_address_collection"; - var snap = await Firestore.instance.collection(path).document(id).get(); - return DeliveryAddress.fromMap(snap.data, snap.documentID); + String path = "/$user_collection/${user!.id}/$delivery_address_collection"; + var snap = await FirebaseFirestore.instance.collection(path).doc(id).get(); + return DeliveryAddress.fromMap(snap.data as Map, snap.id); } void initUser(user) { @@ -87,14 +88,14 @@ class DeliveryAddressModel extends BaseModel { Future> getDeliveryAddresses(String userID) async { String path = "$delivery_address_collection/"; - var querySnap = await Firestore.instance + var querySnap = await FirebaseFirestore.instance .collection('users') - .document("$userID") + .doc("$userID") .collection("$path") .orderBy("full_name") - .getDocuments(); - return querySnap.documents - .map((e) => DeliveryAddress.fromMap(e.data, e.documentID)) + .get(); + return querySnap.docs + .map((e) => DeliveryAddress.fromMap(e.data as Map, e.id)) .toList(); } } diff --git a/lib/pages/discount/model/discount_model.dart b/lib/pages/discount/model/discount_model.dart index 445853f..df50e03 100644 --- a/lib/pages/discount/model/discount_model.dart +++ b/lib/pages/discount/model/discount_model.dart @@ -30,9 +30,7 @@ class DiscountModel extends BaseModel { initData() { _selectedIndex = 1; _load(); - - if (_used != null) _used.close(); - if (_getUsed() != null) _used = _getUsed()!; + if (_getUsed() != null) _used = _getUsed(); _used.load(); } @@ -44,14 +42,14 @@ class DiscountModel extends BaseModel { _load() { if (listener != null) listener!.cancel(); try { - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection("/$discounts_collection") .orderBy("code", descending: false) .snapshots() .listen((snaps) { _discounts.clear(); - snaps.documents.forEach((d) { - _discounts.add(Discount.fromMap(d.data, d.documentID)); + snaps.docs.forEach((d) { + _discounts.add(Discount.fromMap(d.data as Map, d.id)); }); notifyListeners(); }); @@ -60,10 +58,10 @@ class DiscountModel extends BaseModel { } } - Paginator? _getUsed() { - if (user == null || !user.hasFcsShipments()) return null; + Paginator _getUsed() { + if (user == null || !user!.hasFcsShipments()) throw "No Privilege"; - var pageQuery = Firestore.instance + var pageQuery = FirebaseFirestore.instance .collection("/$discounts_collection") .where("status", isEqualTo: fcs_shipment_shipped_status) .orderBy("code", descending: false); @@ -73,17 +71,17 @@ class DiscountModel extends BaseModel { return paginator; } - Future?> getDiscount(String userID) async { + Future?> getDiscount(String userID) async { String path = "/$discounts_collection"; try { - var q = Firestore.instance + var q = FirebaseFirestore.instance .collection("$path") .where("customer_id", isEqualTo: userID) .where("status", isEqualTo: "available"); - var snaps = await q.getDocuments(source: Source.server); - List discounts = snaps.documents.map((snap) { + var snaps = await q.get(const GetOptions(source: Source.server)); + var discounts = snaps.docs.map((snap) { if (snap.exists) { - var s = Discount.fromMap(snap.data, snap.documentID); + var s = Discount.fromMap(snap.data as Map, snap.id); return s; } }).toList(); @@ -128,6 +126,6 @@ class DiscountModel extends BaseModel { } Future deleteDiscount(Discount discount) async { - return Services.instance.commonService.deleteDiscount(discount.id); + return Services.instance.commonService.deleteDiscount(discount.id!); } } diff --git a/lib/pages/faq/model/faq_model.dart b/lib/pages/faq/model/faq_model.dart index ece61b7..cc43d41 100644 --- a/lib/pages/faq/model/faq_model.dart +++ b/lib/pages/faq/model/faq_model.dart @@ -12,22 +12,22 @@ class FAQModel extends BaseModel { List faqs = []; FAQ getFAQ(String id) { - return faqs.firstWhere((e) => e.id == id, orElse: () => null); + return faqs.firstWhere((e) => e.id == id, orElse: () => FAQ()); } - StreamSubscription listener; + StreamSubscription? listener; FAQModel() { - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); try { - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection("/faqs") .orderBy("sn", descending: false) .snapshots() .listen((snaps) { faqs.clear(); - snaps.documents.forEach((d) { - faqs.add(FAQ.fromMap(d.data, d.documentID)); + snaps.docs.forEach((d) { + faqs.add(FAQ.fromMap(d.data as Map, d.id)); }); notifyListeners(); }); diff --git a/lib/pages/fcs_shipment/fcs_shipment_editor.dart b/lib/pages/fcs_shipment/fcs_shipment_editor.dart index e14fed6..0a48598 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_editor.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_editor.dart @@ -64,7 +64,7 @@ class _FcsShipmentEditorState extends State { _destinationController.text = _shipment.destination ?? ""; } else { var mainModel = Provider.of(context, listen: false); - _currentShipmentType = mainModel.setting.shipmentTypes[0]; + _currentShipmentType = mainModel.setting!.shipmentTypes[0]; } } @@ -149,7 +149,7 @@ class _FcsShipmentEditorState extends State { labelText: AppTranslations.of(context)! .text('FCSshipment.shipment_type'), icon: Icon(Ionicons.ios_airplane, color: primaryColor)), - items: mainModel.setting.shipmentTypes + items: mainModel.setting!.shipmentTypes .map((e) => DropdownMenuItem(child: Text(e), value: e)) .toList(), onChanged: (String? selected) => { @@ -288,7 +288,7 @@ class _FcsShipmentEditorState extends State { _consigneeController.text != "" || _portController.text != "" || _destinationController.text != "" || - _currentShipmentType != mainModel.setting.shipmentTypes[0]; + _currentShipmentType != mainModel.setting!.shipmentTypes[0]; } else { FcsShipment fcsShipment = _getPayload(); return widget.shipment!.isChangedForEdit(fcsShipment); diff --git a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart index aaf40a4..45d2141 100644 --- a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart +++ b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart @@ -11,13 +11,13 @@ import 'package:logging/logging.dart'; class FcsShipmentModel extends BaseModel { final log = Logger('FcsShipmentModel'); - StreamSubscription listener; + StreamSubscription? listener; List _fcsShipments = []; List get fcsShipments => _selectedIndex == 1 ? _fcsShipments : List.from(_shipped.values); - Paginator _shipped; + late Paginator _shipped; bool isLoading = false; int _selectedIndex = 1; set selectedIndex(int index) { @@ -25,7 +25,7 @@ class FcsShipmentModel extends BaseModel { notifyListeners(); } - get selectedIndex => _selectedIndex; + int get selectedIndex => _selectedIndex; @override void privilegeChanged() { @@ -43,12 +43,12 @@ class FcsShipmentModel extends BaseModel { } Future _loadFcsShipments() async { - if (user == null || !user.hasFcsShipments()) return; + if (user == null || !user!.hasFcsShipments()) throw "No Privilege"; String path = "/$fcs_shipment_collection/"; - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); _fcsShipments = []; try { - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection("$path") .where("status", isEqualTo: fcs_shipment_confirmed_status) .where("is_deleted", isEqualTo: false) @@ -56,9 +56,9 @@ class FcsShipmentModel extends BaseModel { .snapshots() .listen((QuerySnapshot snapshot) { _fcsShipments.clear(); - _fcsShipments = snapshot.documents.map((documentSnapshot) { + _fcsShipments = snapshot.docs.map((documentSnapshot) { var s = FcsShipment.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, documentSnapshot.id); return s; }).toList(); notifyListeners(); @@ -69,9 +69,9 @@ class FcsShipmentModel extends BaseModel { } Paginator _getShipped() { - if (user == null || !user.hasFcsShipments()) return null; + if (user == null || !user!.hasFcsShipments()) throw "No Privilege"; - var pageQuery = Firestore.instance + var pageQuery = FirebaseFirestore.instance .collection("/$fcs_shipment_collection") .where("status", isEqualTo: fcs_shipment_shipped_status) .where("is_deleted", isEqualTo: false) @@ -102,13 +102,13 @@ class FcsShipmentModel extends BaseModel { Future> getActiveFcsShipments() async { List fcsShipments = []; try { - var snaps = await Firestore.instance + var snaps = await FirebaseFirestore.instance .collection("/$fcs_shipment_collection") .where("status", isEqualTo: fcs_shipment_confirmed_status) - .getDocuments(source: Source.server); - fcsShipments = snaps.documents.map((documentSnapshot) { + .get(const GetOptions(source: Source.server)); + fcsShipments = snaps.docs.map((documentSnapshot) { var fcs = FcsShipment.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, documentSnapshot.id); return fcs; }).toList(); } catch (e) { @@ -117,13 +117,13 @@ class FcsShipmentModel extends BaseModel { return fcsShipments; } - Future getFcsShipment(String id) async { + Future getFcsShipment(String id) async { try { - var snap = await Firestore.instance + var snap = await FirebaseFirestore.instance .collection("/$fcs_shipment_collection") - .document(id) - .get(source: Source.server); - var fcs = FcsShipment.fromMap(snap.data, snap.documentID); + .doc(id) + .get(const GetOptions(source: Source.server)); + var fcs = FcsShipment.fromMap(snap.data as Map, snap.id); return fcs; } catch (e) { @@ -135,13 +135,13 @@ class FcsShipmentModel extends BaseModel { Future> getInvoiceFcsShipments() async { List fcsShipments = []; try { - var snaps = await Firestore.instance + var snaps = await FirebaseFirestore.instance .collection("/$fcs_shipment_collection") .where("pending_invoice_user_count", isGreaterThan: 0) - .getDocuments(source: Source.server); - fcsShipments = snaps.documents.map((documentSnapshot) { + .get(const GetOptions(source: Source.server)); + fcsShipments = snaps.docs.map((documentSnapshot) { var fcs = FcsShipment.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, documentSnapshot.id); return fcs; }).toList(); } catch (e) { @@ -156,7 +156,7 @@ class FcsShipmentModel extends BaseModel { @override logout() async { - if (listener != null) await listener.cancel(); + if (listener != null) await listener!.cancel(); if (_shipped != null) _shipped.close(); _fcsShipments = []; } diff --git a/lib/pages/invoice/editor/invoice_discount_list.dart b/lib/pages/invoice/editor/invoice_discount_list.dart index 3381a3e..a86a056 100644 --- a/lib/pages/invoice/editor/invoice_discount_list.dart +++ b/lib/pages/invoice/editor/invoice_discount_list.dart @@ -6,7 +6,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class InvoiceDiscountList extends StatelessWidget { - final List? discounts; + final List? discounts; const InvoiceDiscountList({ Key? key, @@ -68,14 +68,14 @@ class InvoiceDiscountList extends StatelessWidget { onSelectChanged: (value) => Navigator.pop(context, c), cells: [ MyDataCell(new Text( - c.code!, + c?.code ?? '', style: textStyle, )), MyDataCell( Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - Text(c.amount.toStringAsFixed(2), style: textStyle), + Text(c?.amount.toStringAsFixed(2) ?? "", style: textStyle), ], ), ), diff --git a/lib/pages/invoice/editor/invoice_editor.dart b/lib/pages/invoice/editor/invoice_editor.dart index b40c834..c8b9efa 100644 --- a/lib/pages/invoice/editor/invoice_editor.dart +++ b/lib/pages/invoice/editor/invoice_editor.dart @@ -113,7 +113,7 @@ class _InvoiceEditorState extends State { }); } - List discounts = []; + List discounts = []; _loadDiscount() async { DiscountModel discountModel = Provider.of(context, listen: false); diff --git a/lib/pages/staff/model/staff_model.dart b/lib/pages/staff/model/staff_model.dart index cadb5a4..b2c2ebb 100644 --- a/lib/pages/staff/model/staff_model.dart +++ b/lib/pages/staff/model/staff_model.dart @@ -11,8 +11,8 @@ import 'package:logging/logging.dart'; class StaffModel extends BaseModel { final log = Logger('StaffModel'); - StreamSubscription listener; - StreamSubscription privilegeListener; + StreamSubscription? listener; + StreamSubscription? privilegeListener; List employees = []; List privileges = []; @@ -26,28 +26,28 @@ class StaffModel extends BaseModel { @override logout() async { - if (listener != null) listener.cancel(); - if (privilegeListener != null) privilegeListener.cancel(); + if (listener != null) listener!.cancel(); + if (privilegeListener != null) privilegeListener!.cancel(); employees = []; privileges = []; } Future _loadEmployees() async { - if (user == null || !user.hasStaffs()) return; + if (user == null || !user!.hasStaffs()) throw "No Privilege"; try { - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection("/$user_collection") .where("is_employee", isEqualTo: true) .where("is_sys_admin", isEqualTo: false) .snapshots() .listen((QuerySnapshot snapshot) { employees.clear(); - employees = snapshot.documents.map((documentSnapshot) { + employees = snapshot.docs.map((documentSnapshot) { var user = - User.fromMap(documentSnapshot.data, documentSnapshot.documentID); + User.fromMap(documentSnapshot.data as Map, documentSnapshot.id); return user; }).toList(); notifyListeners(); @@ -59,14 +59,14 @@ class StaffModel extends BaseModel { Future _loadPrivileges() async { try { - privilegeListener = Firestore.instance + privilegeListener = FirebaseFirestore.instance .collection("/$privilege_collection") .snapshots() .listen((QuerySnapshot snapshot) { privileges.clear(); - privileges = snapshot.documents.map((documentSnapshot) { + privileges = snapshot.docs.map((documentSnapshot) { var privilege = Privilege.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, documentSnapshot.id); return privilege; }).toList(); notifyListeners(); @@ -82,27 +82,27 @@ class StaffModel extends BaseModel { token: await getToken()); } - Future findUser(String phoneNumber) { + Future findUser(String phoneNumber) { return Services.instance.userService.findUser(phoneNumber); } Future> getPickupEmployees() async { - if (user == null || !user.hasShipment()) return []; + if (user == null || !user!.hasShipment()) return []; return _getUsers(privilege_shipment); } Future> _getUsers(String privilege) async { List users = []; try { - var snaps = await Firestore.instance + var snaps = await FirebaseFirestore.instance .collection("/$user_collection") .where("is_employee", isEqualTo: true) .where("is_sys_admin", isEqualTo: false) .where("privileges", arrayContains: privilege) - .getDocuments(source: Source.server); - users = snaps.documents.map((documentSnapshot) { + .get(const GetOptions(source: Source.server)); + users = snaps.docs.map((documentSnapshot) { var user = - User.fromMap(documentSnapshot.data, documentSnapshot.documentID); + User.fromMap(documentSnapshot.data as Map, documentSnapshot.id); return user; }).toList(); } catch (e) { diff --git a/lib/pages/staff/staff_editor.dart b/lib/pages/staff/staff_editor.dart index 5a703b0..67197e0 100644 --- a/lib/pages/staff/staff_editor.dart +++ b/lib/pages/staff/staff_editor.dart @@ -268,7 +268,7 @@ class _StaffEditorState extends State { _isLoading = true; }); try { - User _user = await staffModel.findUser(_phoneInput.text); + User? _user = await staffModel.findUser(_phoneInput.text); if (_user == null) { showMsgDialog(context, "Error", _phoneInput.text + " not found!"); return; diff --git a/lib/pages/widgets/local_popup_menu_button.dart b/lib/pages/widgets/local_popup_menu_button.dart index a73bb86..8fa1e62 100644 --- a/lib/pages/widgets/local_popup_menu_button.dart +++ b/lib/pages/widgets/local_popup_menu_button.dart @@ -78,7 +78,7 @@ class _LocalPopupMenuButtonState extends State { children: [ Icon( widget.buttonIcon ?? Icons.filter_list, - color: widget.buttonColor ?? primaryColor, + color: widget.buttonColor, ), hightlight ? Positioned( @@ -98,14 +98,12 @@ class _LocalPopupMenuButtonState extends State { )), itemBuilder: (BuildContext context) { return popmenus.map((LocalPopupMenu choice) { - if (choice == null) return null; return PopupMenuItem( value: choice, child: Row( children: [ - LocalText(context, choice.textKey, - color: - choice?.enabled ?? true ? primaryColor : Colors.grey), + LocalText(context, choice.textKey ?? "", + color: choice.enabled ? primaryColor : Colors.grey), SizedBox( width: 10, ), @@ -124,8 +122,8 @@ class _LocalPopupMenuButtonState extends State { bool _needHighlight() { popmenus.forEach((e) { - if (e == null) return false; - if (e.selected && e.highlight) return true; + if (e == null) return; + if (e.selected && e.highlight) return; }); return false; }