From d862049b457ca6af9384d722ab23cab8ef7bd96e Mon Sep 17 00:00:00 2001 From: Phaung Phaung Date: Fri, 10 Sep 2021 14:29:55 +0630 Subject: [PATCH 1/5] 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/5] 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/5] 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; } From bb4f4ad7c25ef98be4a95d064978dda3074117a4 Mon Sep 17 00:00:00 2001 From: phyothandar Date: Fri, 10 Sep 2021 16:48:21 +0630 Subject: [PATCH 4/5] null safety --- lib/pages/invoice/invoice_list_row.dart | 4 +- .../invoice/invoice_shipment_list_row.dart | 2 +- lib/pages/package/model/package_model.dart | 41 ++--- lib/pages/package/package_editor.dart | 10 +- lib/pages/package/package_info.dart | 8 +- lib/pages/package/package_list.dart | 2 +- lib/pages/package/package_list_row.dart | 14 +- lib/pages/package/package_new.dart | 4 +- lib/pages/package/tracking_id_page.dart | 8 +- .../model/payment_method_model.dart | 13 +- .../payment_method_editor.dart | 14 +- .../payment_methods/payment_method_page.dart | 12 +- .../processing/model/processing_model.dart | 8 +- lib/pages/processing/package_editor.dart | 14 +- .../processing/processing_edit_editor.dart | 8 +- lib/pages/processing/processing_info.dart | 6 +- lib/pages/processing/processing_list.dart | 2 +- lib/pages/processing/processing_list_row.dart | 10 +- .../processing_old/processing_editor.dart | 40 ++--- lib/pages/processing_old/processing_info.dart | 39 ++--- lib/pages/processing_old/processing_list.dart | 2 +- .../processing_old/processing_list_row.dart | 22 +-- lib/pages/profile/profile_currency_edit.dart | 6 +- lib/pages/profile/profile_edit.dart | 2 +- lib/pages/profile/profile_page.dart | 28 ++-- lib/pages/receiving/receiving_editor.dart | 4 +- lib/pages/receiving/receiving_info.dart | 4 +- lib/pages/receiving/receiving_list.dart | 2 +- lib/pages/receiving/receiving_list_row.dart | 10 +- lib/pages/shipment/box_row.dart | 2 +- lib/pages/shipment/model/shipment_model.dart | 60 +++---- lib/pages/shipment/shipment_assign.dart | 35 +++-- lib/pages/shipment/shipment_box_editor.dart | 49 +++--- lib/pages/shipment/shipment_confirm.dart | 17 +- lib/pages/shipment/shipment_editor.dart | 57 +++---- lib/pages/shipment/shipment_info.dart | 148 ++++++++++-------- lib/pages/shipment/shipment_list.dart | 2 +- lib/pages/shipment/shipment_list_row.dart | 12 +- lib/pages/shipment/shipment_pack.dart | 20 +-- lib/pages/widgets/multi_img_controller.dart | 4 +- 40 files changed, 393 insertions(+), 352 deletions(-) diff --git a/lib/pages/invoice/invoice_list_row.dart b/lib/pages/invoice/invoice_list_row.dart index 1ffc7b1..2022362 100644 --- a/lib/pages/invoice/invoice_list_row.dart +++ b/lib/pages/invoice/invoice_list_row.dart @@ -58,7 +58,9 @@ class InvoiceListRow extends StatelessWidget { fontSize: 13.0, color: primaryColor), ), new Text( - dateFormatter.format(invoice!.invoiceDate!), + invoice!.invoiceDate != null + ? dateFormatter.format(invoice!.invoiceDate!) + : '', style: new TextStyle( fontSize: 15.0, color: Colors.grey), ) diff --git a/lib/pages/invoice/invoice_shipment_list_row.dart b/lib/pages/invoice/invoice_shipment_list_row.dart index e77cc75..a08a362 100644 --- a/lib/pages/invoice/invoice_shipment_list_row.dart +++ b/lib/pages/invoice/invoice_shipment_list_row.dart @@ -86,7 +86,7 @@ class _InvoiceShipmentListRowState extends State { ), Padding( padding: const EdgeInsets.all(0), - child: getStatus(_fcsShipment.status!), + child: getStatus(_fcsShipment.status??"") ), ], ), diff --git a/lib/pages/package/model/package_model.dart b/lib/pages/package/model/package_model.dart index 1d2e439..9e979e1 100644 --- a/lib/pages/package/model/package_model.dart +++ b/lib/pages/package/model/package_model.dart @@ -16,9 +16,9 @@ import 'package:path/path.dart' as Path; class PackageModel extends BaseModel { final log = Logger('PackageModel'); - PaginatorListener? packages; - PaginatorListener? customerPackages; - PaginatorListener? activePackages; + late PaginatorListener packages; + late PaginatorListener customerPackages; + late PaginatorListener activePackages; bool isLoading = false; int _menuSelectedIndex = 1; @@ -63,15 +63,16 @@ class PackageModel extends BaseModel { @override logout() async { - if (customerPackages != null) customerPackages!.close(); - if (packages != null) packages!.close(); - if (activePackages != null) activePackages!.close(); + if (customerPackages != null) customerPackages.close(); + if (packages != null) packages.close(); + if (activePackages != null) activePackages.close(); } Future _loadPackages(bool isDelivered) async { if (user == null) return; - if (!((user!.hasPackages() || user!.hasReceiving() || user!.hasProcessing()))) - return; + if (!((user!.hasPackages() || + user!.hasReceiving() || + user!.hasProcessing()))) return; String path = "/$packages_collection"; try { @@ -83,7 +84,7 @@ class PackageModel extends BaseModel { .where("is_delivered", isEqualTo: isDelivered); pageQuery = pageQuery.orderBy("update_time", descending: true); - packages!.refresh(listeningQuery: listenerQuery, pageQuery: pageQuery); + packages.refresh(listeningQuery: listenerQuery, pageQuery: pageQuery); } catch (e) { log.warning("Error!! $e"); } @@ -104,7 +105,7 @@ class PackageModel extends BaseModel { .where("user_id", isEqualTo: user!.id) .orderBy("update_time", descending: true); - customerPackages!.refresh( + customerPackages.refresh( listeningQuery: listenerQuery, pageQuery: pageQuery); } catch (e) { log.warning("Error!! $e"); @@ -113,8 +114,9 @@ class PackageModel extends BaseModel { Future _loadActivePackages() async { if (user == null) return; - if (!((user!.hasPackages() || user!.hasReceiving() || user!.hasProcessing()))) - return; + if (!((user!.hasPackages() || + user!.hasReceiving() || + user!.hasProcessing()))) return; String path = "/$packages_collection"; try { @@ -126,7 +128,7 @@ class PackageModel extends BaseModel { .where("is_delivered", isEqualTo: false); pageQuery = pageQuery.orderBy("update_time", descending: true); - activePackages!.refresh( + activePackages.refresh( listeningQuery: listenerQuery, pageQuery: pageQuery); } catch (e) { log.warning("Error!! $e"); @@ -161,7 +163,8 @@ class PackageModel extends BaseModel { .get(const GetOptions(source: Source.server)); if (snaps.docs.length == 1) { var snap = snaps.docs[0]; - var package = Package.fromMap(snap.data as Map, snap.id); + var package = + Package.fromMap(snap.data as Map, snap.id); return package; } } catch (e) { @@ -184,7 +187,8 @@ class PackageModel extends BaseModel { if (qsnap.docs.length > 0) { var snap = qsnap.docs[0]; if (snap.exists) { - var package = Package.fromMap(snap.data as Map, snap.id); + var package = + Package.fromMap(snap.data as Map, snap.id); return package; } } @@ -198,7 +202,8 @@ class PackageModel extends BaseModel { if (qsnap.docs.length > 0) { var snap = qsnap.docs[0]; if (snap.exists) { - var package = Package.fromMap(snap.data as Map, snap.id); + var package = + Package.fromMap(snap.data as Map, snap.id); return package; } } @@ -218,8 +223,8 @@ class PackageModel extends BaseModel { .where("is_deleted", isEqualTo: false) .get(const GetOptions(source: Source.server)); packages = snaps.docs.map((documentSnapshot) { - var p = - Package.fromMap(documentSnapshot.data as Map, documentSnapshot.id); + var p = Package.fromMap( + documentSnapshot.data as Map, documentSnapshot.id); return p; }).toList(); } catch (e) { diff --git a/lib/pages/package/package_editor.dart b/lib/pages/package/package_editor.dart index 231e04a..9afa78b 100644 --- a/lib/pages/package/package_editor.dart +++ b/lib/pages/package/package_editor.dart @@ -38,8 +38,8 @@ class _PackageEditorPageState extends State { super.initState(); _package = widget.package!; selectedMarket = _package!.market; - _descCtl.text = _package!.desc; - _remarkCtl.text = _package!.remark; + _descCtl.text = _package!.desc!; + _remarkCtl.text = _package!.remark!; multiImgController.setImageUrls = _package!.photoUrls; } @@ -157,7 +157,7 @@ class _PackageEditorPageState extends State { String? selectedMarket; Widget marketDropdown() { List _markets = Provider.of(context).markets; - List markets = _markets.map((e) => e.name).toList(); + List markets = _markets.map((e) => e.name).toList(); markets.insert(0, MANAGE_MARKET); if (!markets.contains(selectedMarket)) { markets.insert(0, selectedMarket!); @@ -194,10 +194,10 @@ class _PackageEditorPageState extends State { }); }, isExpanded: true, - items: markets.map>((String value) { + items: markets.map>((String? value) { return DropdownMenuItem( value: value, - child: Text(value, + child: Text(value ?? "", overflow: TextOverflow.ellipsis, style: TextStyle( color: value == MANAGE_MARKET diff --git a/lib/pages/package/package_info.dart b/lib/pages/package/package_info.dart index 658059b..cb755e6 100644 --- a/lib/pages/package/package_info.dart +++ b/lib/pages/package/package_info.dart @@ -51,10 +51,10 @@ class _PackageInfoState extends State { initPackage(Package pkg) async { PackageModel packageModel = Provider.of(context, listen: false); - Package package = await packageModel.getPackageByTrackingID(pkg.trackingID); + Package? package = await packageModel.getPackageByTrackingID(pkg.trackingID!); setState(() { _package = package; - multiImgController.setImageUrls = package.photoUrls; + multiImgController.setImageUrls = package!.photoUrls; }); } @@ -65,7 +65,7 @@ class _PackageInfoState extends State { @override Widget build(BuildContext context) { - String id = Provider.of(context).user.id; + String? id = Provider.of(context).user!.id; bool owner = _package?.userID == id; bool canChangeDeliveryAddress = _package?.status == package_received_status || @@ -199,7 +199,7 @@ class _PackageInfoState extends State { try { await packageModel.changeDeliveryAddress(_package!, deliveryAddress); var da = - await deliveryAddressModel.getDeliveryAddress(deliveryAddress.id); + await deliveryAddressModel.getDeliveryAddress(deliveryAddress.id!); setState(() { _package!.deliveryAddress = da; }); diff --git a/lib/pages/package/package_list.dart b/lib/pages/package/package_list.dart index d98fbcc..e806ead 100644 --- a/lib/pages/package/package_list.dart +++ b/lib/pages/package/package_list.dart @@ -97,7 +97,7 @@ class _PackageListState extends State { _searchCallback(Package package) async { var packageModel = Provider.of(context, listen: false); - Package _package = await packageModel.getPackage(package.id); + Package? _package = await packageModel.getPackage(package.id!); if (_package == null) return; Navigator.push( context, diff --git a/lib/pages/package/package_list_row.dart b/lib/pages/package/package_list_row.dart index 067287c..a613c26 100644 --- a/lib/pages/package/package_list_row.dart +++ b/lib/pages/package/package_list_row.dart @@ -60,7 +60,9 @@ class PackageListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - package!.id == null ? '' : package!.trackingID, + package!.id == null + ? '' + : package!.trackingID!, style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -68,7 +70,9 @@ class PackageListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - package!.market == null ? '' : package!.market, + package!.market == null + ? '' + : package!.market!, style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -84,12 +88,14 @@ class PackageListRow extends StatelessWidget { children: [ Padding( padding: const EdgeInsets.all(3.0), - child: getStatus(package!.status), + child: getStatus(package!.status??""), ), Padding( padding: const EdgeInsets.all(0), child: new Text( - dateFormat.format(package!.currentStatusDate), + package!.currentStatusDate != null + ? dateFormat.format(package!.currentStatusDate!) + : '', style: new TextStyle(fontSize: 15.0, color: Colors.grey), ), diff --git a/lib/pages/package/package_new.dart b/lib/pages/package/package_new.dart index 4fe53fd..1b33c1d 100644 --- a/lib/pages/package/package_new.dart +++ b/lib/pages/package/package_new.dart @@ -144,8 +144,8 @@ class _PackageNewState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(packages[index].market), - Text(packages[index].trackingID), + Text(packages[index].market!), + Text(packages[index].trackingID!), // DisplayText( // labelText: "Tracking ID", // text: packages[index].trackingID, diff --git a/lib/pages/package/tracking_id_page.dart b/lib/pages/package/tracking_id_page.dart index b4c6644..1856f7a 100644 --- a/lib/pages/package/tracking_id_page.dart +++ b/lib/pages/package/tracking_id_page.dart @@ -87,7 +87,7 @@ class _TrackingIDPageState extends State { String? selectedMarket; Widget dropDown() { List _markets = Provider.of(context).markets; - List markets = _markets.map((e) => e.name).toList(); + List markets = _markets.map((e) => e.name).toList(); markets.insert(0, MANAGE_MARKET); markets.insert(0, SELECT_MARKET); @@ -126,10 +126,10 @@ class _TrackingIDPageState extends State { }); }, isExpanded: true, - items: markets.map>((String value) { + items: markets.map>((String? value) { return DropdownMenuItem( value: value, - child: Text(value, + child: Text(value ?? "", overflow: TextOverflow.ellipsis, style: TextStyle( color: value == MANAGE_MARKET @@ -146,7 +146,7 @@ class _TrackingIDPageState extends State { _manageMarket() { Navigator.push( context, - CupertinoPageRoute(builder: (context) => MarketEditor()), + CupertinoPageRoute(builder: (context) => MarketEditor()), ); } diff --git a/lib/pages/payment_methods/model/payment_method_model.dart b/lib/pages/payment_methods/model/payment_method_model.dart index 25d9f11..229bd9f 100644 --- a/lib/pages/payment_methods/model/payment_method_model.dart +++ b/lib/pages/payment_methods/model/payment_method_model.dart @@ -12,21 +12,22 @@ class PaymentMethodModel extends BaseModel { List paymentMethods = []; PaymentMethod getPaymentMethod(String id) { - return paymentMethods.firstWhere((e) => e.id == id, orElse: () => null); + return paymentMethods.firstWhere((e) => e.id == id); } - StreamSubscription listener; + StreamSubscription? 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, d.id)); }); notifyListeners(); }); diff --git a/lib/pages/payment_methods/payment_method_editor.dart b/lib/pages/payment_methods/payment_method_editor.dart index 77cf8cb..9699db7 100644 --- a/lib/pages/payment_methods/payment_method_editor.dart +++ b/lib/pages/payment_methods/payment_method_editor.dart @@ -38,12 +38,12 @@ class _PaymentMethodEditorState extends State { 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 { }); try { await Provider.of(context, listen: false) - .deletePaymentMethod(_paymentMethod!.id); + .deletePaymentMethod(_paymentMethod!.id!); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/payment_methods/payment_method_page.dart b/lib/pages/payment_methods/payment_method_page.dart index 4c91d3c..0fb95e2 100644 --- a/lib/pages/payment_methods/payment_method_page.dart +++ b/lib/pages/payment_methods/payment_method_page.dart @@ -84,13 +84,13 @@ class _PaymentMethodPageState extends State { } _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 { Padding( padding: const EdgeInsets.all(8.0), child: Text( - method.name, + method.name!, style: TextStyle( color: primaryColor, fontWeight: FontWeight.bold, diff --git a/lib/pages/processing/model/processing_model.dart b/lib/pages/processing/model/processing_model.dart index e5782c8..0977245 100644 --- a/lib/pages/processing/model/processing_model.dart +++ b/lib/pages/processing/model/processing_model.dart @@ -11,7 +11,7 @@ class ProcessingModel extends BaseModel { List processings = []; final log = Logger('ProcessingModel'); - StreamSubscription listener; + StreamSubscription? listener; void initUser(user) { super.initUser(user); @@ -19,12 +19,12 @@ class ProcessingModel extends BaseModel { @override logout() async { - if (listener != null) await listener.cancel(); + if (listener != null) await listener!.cancel(); processings = []; } - Future createProcessing(Processing processing) {} + Future createProcessing(Processing processing) async {} - Future updateProcessing(Processing processing) {} + Future updateProcessing(Processing processing) async {} } diff --git a/lib/pages/processing/package_editor.dart b/lib/pages/processing/package_editor.dart index 86da544..458e3dc 100644 --- a/lib/pages/processing/package_editor.dart +++ b/lib/pages/processing/package_editor.dart @@ -44,14 +44,14 @@ class _PackageEditorState extends State { void initState() { super.initState(); _package = Package(); - _loadPackageData(widget.package!.id); + _loadPackageData(widget.package!.id!); } _loadPackageData(String id) async { if (id != null) { PackageModel packageModel = Provider.of(context, listen: false); - Package package = await packageModel.getPackage(id); + Package? package = await packageModel.getPackage(id); if (package != null) { if (package.status != package_received_status) { showMsgDialog(context, "Error", @@ -65,8 +65,8 @@ class _PackageEditorState extends State { } setState(() { selectedMarket = _package!.market ?? ""; - _descCtl.text = _package!.desc; - _remarkCtl.text = _package!.remark; + _descCtl.text = _package!.desc!; + _remarkCtl.text = _package!.remark!; multiImgController.setImageUrls = _package!.photoUrls; }); } @@ -84,7 +84,7 @@ class _PackageEditorState extends State { IconButton( icon: Icon(Icons.search, color: primaryColor), onPressed: () => searchPackage(context, callbackPackageSelect: (u) { - _loadPackageData(u.id); + _loadPackageData(u.id!); Navigator.pop(context); })), ], @@ -177,7 +177,7 @@ class _PackageEditorState extends State { String? selectedMarket; Widget marketDropdown() { List _markets = Provider.of(context).markets; - List markets = _markets.map((e) => e.name).toList(); + List markets = _markets.map((e) => e.name).toList(); markets.insert(0, MANAGE_MARKET); if (!markets.contains(selectedMarket)) { markets.insert(0, selectedMarket!); @@ -221,7 +221,7 @@ class _PackageEditorState extends State { }); }, isExpanded: true, - items: markets.map>((String value) { + items: markets.map>((String? value) { return DropdownMenuItem( value: value, child: Text(value ?? "", diff --git a/lib/pages/processing/processing_edit_editor.dart b/lib/pages/processing/processing_edit_editor.dart index c096f0b..4751134 100644 --- a/lib/pages/processing/processing_edit_editor.dart +++ b/lib/pages/processing/processing_edit_editor.dart @@ -42,8 +42,8 @@ class _ProcessingEditEditorState extends State { super.initState(); _package = widget.package; selectedMarket = _package!.market ?? ""; - _descCtl.text = _package!.desc; - _remarkCtl.text = _package!.remark; + _descCtl.text = _package!.desc!; + _remarkCtl.text = _package!.remark!; multiImgController.setImageUrls = _package!.photoUrls; _user = User( fcsID: _package!.fcsID ?? "", @@ -162,7 +162,7 @@ class _ProcessingEditEditorState extends State { String? selectedMarket; Widget marketDropdown() { List _markets = Provider.of(context).markets; - List markets = _markets.map((e) => e.name).toList(); + List markets = _markets.map((e) => e.name).toList(); markets.insert(0, MANAGE_MARKET); if (!markets.contains(selectedMarket)) { markets.insert(0, selectedMarket!); @@ -208,7 +208,7 @@ class _ProcessingEditEditorState extends State { }); }, isExpanded: true, - items: markets.map>((String value) { + items: markets.map>((String? value) { return DropdownMenuItem( value: value, child: Text(value ?? "", diff --git a/lib/pages/processing/processing_info.dart b/lib/pages/processing/processing_info.dart index 39e2014..d15d0c9 100644 --- a/lib/pages/processing/processing_info.dart +++ b/lib/pages/processing/processing_info.dart @@ -175,7 +175,7 @@ class _ProcessingInfoState extends State { _package!.photoUrls.length == 0 ? Container() : img, StatusTree( shipmentHistory: _package!.shipmentHistory, - currentStatus: _package!.status), + currentStatus: _package!.status??""), SizedBox( height: 20, ) @@ -222,8 +222,8 @@ class _ProcessingInfoState extends State { } else { PackageModel packageModel = Provider.of(context, listen: false); - Package p = await packageModel.getPackage(_package!.id); - initPackage(p); + Package? p = await packageModel.getPackage(_package!.id!); + initPackage(p!); } } } diff --git a/lib/pages/processing/processing_list.dart b/lib/pages/processing/processing_list.dart index 7f5855a..ec021b0 100644 --- a/lib/pages/processing/processing_list.dart +++ b/lib/pages/processing/processing_list.dart @@ -85,7 +85,7 @@ class _ProcessingListState extends State { _searchCallback(Package package) async { var packageModel = Provider.of(context, listen: false); - Package _package = await packageModel.getPackage(package.id); + Package? _package = await packageModel.getPackage(package.id!); if (_package == null) return; Navigator.push( context, diff --git a/lib/pages/processing/processing_list_row.dart b/lib/pages/processing/processing_list_row.dart index 527c621..d702d4f 100644 --- a/lib/pages/processing/processing_list_row.dart +++ b/lib/pages/processing/processing_list_row.dart @@ -57,7 +57,7 @@ class ProcessingListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - package!.id == null ? '' : package!.trackingID, + package!.id == null ? '' : package!.trackingID!, style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -65,7 +65,7 @@ class ProcessingListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - package!.market == null ? '' : package!.market, + package!.market == null ? '' : package!.market!, style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -81,12 +81,14 @@ class ProcessingListRow extends StatelessWidget { children: [ Padding( padding: const EdgeInsets.all(3.0), - child: getStatus(package!.status), + child: getStatus(package!.status??""), ), Padding( padding: const EdgeInsets.all(0), child: new Text( - dateFormat.format(package!.currentStatusDate), + package!.currentStatusDate != null + ? dateFormat.format(package!.currentStatusDate!) + : '', style: new TextStyle(fontSize: 15.0, color: Colors.grey), ), ), diff --git a/lib/pages/processing_old/processing_editor.dart b/lib/pages/processing_old/processing_editor.dart index 634247d..62fb147 100644 --- a/lib/pages/processing_old/processing_editor.dart +++ b/lib/pages/processing_old/processing_editor.dart @@ -18,12 +18,12 @@ import 'package:fcs/pages/widgets/multi_img_file.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:flutter_icons_null_safety/flutter_icons_null_safety.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; class ProcessingEditor extends StatefulWidget { - final Package package; + final Package? package; ProcessingEditor({this.package}); @override @@ -34,22 +34,22 @@ class _ProcessingEditorState extends State { TextEditingController _remarkCtl = new TextEditingController(); TextEditingController _descCtl = new TextEditingController(); - Package _package; - User _user; + Package? _package; + User? _user; bool _isLoading = false; @override void initState() { super.initState(); _package = widget.package; - selectedMarket = _package.market ?? ""; - _descCtl.text = _package.desc; - _remarkCtl.text = _package.remark; - multiImgController.setImageUrls = _package.photoUrls; + selectedMarket = _package!.market ?? ""; + _descCtl.text = _package!.desc!; + _remarkCtl.text = _package!.remark!; + multiImgController.setImageUrls = _package!.photoUrls; _user = User( - fcsID: _package.fcsID ?? "", - name: _package.userName ?? "", - phoneNumber: _package.phoneNumber ?? ""); + fcsID: _package!.fcsID ?? "", + name: _package!.userName ?? "", + phoneNumber: _package!.phoneNumber ?? ""); } final DateFormat dateFormat = DateFormat("d MMM yyyy"); @@ -63,7 +63,7 @@ class _ProcessingEditorState extends State { children: [ Expanded( child: DisplayText( - text: _user.fcsID, + text: _user!.fcsID??"", labelTextKey: "processing.fcs.id", icon: FcsIDIcon(), )), @@ -77,18 +77,18 @@ class _ProcessingEditorState extends State { ], ); final namebox = DisplayText( - text: _user.name, + text: _user!.name??"", labelTextKey: "processing.name", iconData: Icons.person, ); final phoneNumberBox = DisplayText( - text: _user.phoneNumber, + text: _user!.phoneNumber??"", labelTextKey: "processing.phone", iconData: Icons.phone, ); final trackingIdBox = DisplayText( - text: _package.trackingID, + text: _package!.trackingID??"", labelTextKey: "processing.tracking.id", iconData: MaterialCommunityIcons.barcode_scan, ); @@ -152,13 +152,13 @@ class _ProcessingEditorState extends State { ); } - String selectedMarket; + String? selectedMarket; Widget marketDropdown() { List _markets = Provider.of(context).markets; - List markets = _markets.map((e) => e.name).toList(); + List markets = _markets.map((e) => e.name).toList(); markets.insert(0, MANAGE_MARKET); if (!markets.contains(selectedMarket)) { - markets.insert(0, selectedMarket); + markets.insert(0, selectedMarket!); } return Padding( @@ -190,7 +190,7 @@ class _ProcessingEditorState extends State { height: 1, color: Colors.grey, ), - onChanged: (String newValue) { + onChanged: (String? newValue) { setState(() { if (newValue == MANAGE_MARKET) { selectedMarket = null; @@ -201,7 +201,7 @@ class _ProcessingEditorState extends State { }); }, isExpanded: true, - items: markets.map>((String value) { + items: markets.map>((String? value) { return DropdownMenuItem( value: value, child: Text(value ?? "", diff --git a/lib/pages/processing_old/processing_info.dart b/lib/pages/processing_old/processing_info.dart index 0b6fe43..d48a433 100644 --- a/lib/pages/processing_old/processing_info.dart +++ b/lib/pages/processing_old/processing_info.dart @@ -12,7 +12,8 @@ import 'package:fcs/pages/widgets/progress.dart'; import 'package:fcs/pages/widgets/status_tree.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_icons/flutter_icons.dart'; +import 'package:flutter_icons_null_safety/flutter_icons_null_safety.dart'; + import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -21,7 +22,7 @@ import 'processing_editor.dart'; final DateFormat dateFormat = DateFormat("d MMM yyyy"); class ProcessingInfo extends StatefulWidget { - final Package package; + final Package? package; ProcessingInfo({this.package}); @override @@ -30,14 +31,14 @@ class ProcessingInfo extends StatefulWidget { class _ProcessingInfoState extends State { var dateFormatter = new DateFormat('dd MMM yyyy'); - Package _package; + Package? _package; bool _isLoading = false; MultiImgController multiImgController = MultiImgController(); @override void initState() { super.initState(); - initPackage(widget.package); + initPackage(widget.package!); } initPackage(Package package) { @@ -55,37 +56,37 @@ class _ProcessingInfoState extends State { @override Widget build(BuildContext context) { final trackingIdBox = DisplayText( - text: _package.trackingID, + text: _package!.trackingID ?? "", labelTextKey: "processing.tracking.id", iconData: MaterialCommunityIcons.barcode_scan, ); var fcsIDBox = DisplayText( - text: _package.fcsID, + text: _package!.fcsID??"", labelTextKey: "processing.fcs.id", icon: FcsIDIcon(), ); final phoneNumberBox = DisplayText( - text: _package.phoneNumber, + text: _package!.phoneNumber??"", labelTextKey: "processing.phone", iconData: Icons.phone, ); final customerNameBox = DisplayText( - text: _package.userName, + text: _package!.userName??"", labelTextKey: "processing.name", iconData: Icons.perm_identity, ); final marketBox = DisplayText( - text: _package.market ?? "-", + text: _package!.market ?? "-", labelTextKey: "processing.market", iconData: Icons.store, ); final descBox = DisplayText( - text: _package.desc ?? "-", + text: _package!.desc ?? "-", labelTextKey: "processing.desc", iconData: MaterialCommunityIcons.message_text_outline, ); final remarkBox = DisplayText( - text: _package.remark ?? "-", + text: _package!.remark ?? "-", labelTextKey: "processing.remark", iconData: Entypo.new_message, ); @@ -137,10 +138,10 @@ class _ProcessingInfoState extends State { marketBox, descBox, remarkBox, - _package.photoUrls.length == 0 ? Container() : img, + _package!.photoUrls.length == 0 ? Container() : img, StatusTree( - shipmentHistory: _package.shipmentHistory, - currentStatus: _package.status), + shipmentHistory: _package!.shipmentHistory, + currentStatus: _package!.status??""), SizedBox( height: 20, ) @@ -164,7 +165,7 @@ class _ProcessingInfoState extends State { PackageModel packageModel = Provider.of(context, listen: false); try { - await packageModel.deleteProcessing(_package); + await packageModel.deleteProcessing(_package!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); @@ -176,19 +177,19 @@ class _ProcessingInfoState extends State { } _gotoEditor() async { - bool deleted = await Navigator.push( + bool? deleted = await Navigator.push( context, CupertinoPageRoute( builder: (context) => ProcessingEditor( - package: widget.package, + package: widget.package!, ))); if (deleted ?? false) { Navigator.pop(context); } else { PackageModel packageModel = Provider.of(context, listen: false); - Package p = await packageModel.getPackage(_package.id); - initPackage(p); + Package? p = await packageModel.getPackage(_package!.id!); + initPackage(p!); } } } diff --git a/lib/pages/processing_old/processing_list.dart b/lib/pages/processing_old/processing_list.dart index 6ab3497..38e5c0a 100644 --- a/lib/pages/processing_old/processing_list.dart +++ b/lib/pages/processing_old/processing_list.dart @@ -77,7 +77,7 @@ class _ProcessingListState extends State { _searchCallback(Package package) async { var packageModel = Provider.of(context, listen: false); - Package _package = await packageModel.getPackage(package.id); + Package? _package = await packageModel.getPackage(package.id!); if (_package == null) return; Navigator.push( context, diff --git a/lib/pages/processing_old/processing_list_row.dart b/lib/pages/processing_old/processing_list_row.dart index cc06c16..a287b2c 100644 --- a/lib/pages/processing_old/processing_list_row.dart +++ b/lib/pages/processing_old/processing_list_row.dart @@ -3,7 +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_icons/flutter_icons.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; import 'processing_info.dart'; @@ -11,12 +11,12 @@ import 'processing_info.dart'; typedef CallbackPackageSelect(Package package); class ProcessingListRow extends StatelessWidget { - final Package package; - final CallbackPackageSelect callbackPackageSelect; + final Package? package; + final CallbackPackageSelect? callbackPackageSelect; final double dotSize = 15.0; final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); - ProcessingListRow({Key key, this.package, this.callbackPackageSelect}) + ProcessingListRow({Key? key, this.package, this.callbackPackageSelect}) : super(key: key); @override @@ -24,7 +24,7 @@ class ProcessingListRow extends StatelessWidget { return InkWell( onTap: () { if (callbackPackageSelect != null) { - callbackPackageSelect(package); + callbackPackageSelect!(package!); return; } Navigator.push( @@ -45,7 +45,7 @@ class ProcessingListRow extends StatelessWidget { Container( padding: EdgeInsets.only(left: 5, right: 10), child: Icon( - FontAwesome.dropbox, + FontAwesomeIcons.dropbox, color: primaryColor, size: 30, ), @@ -57,7 +57,7 @@ class ProcessingListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - package.id == null ? '' : package.trackingID, + package!.id == null ? '' : package!.trackingID!, style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -65,7 +65,7 @@ class ProcessingListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - package.market == null ? '' : package.market, + package!.market == null ? '' : package!.market!, style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -81,12 +81,14 @@ class ProcessingListRow extends StatelessWidget { children: [ Padding( padding: const EdgeInsets.all(3.0), - child: getStatus(package.status), + child: getStatus(package!.status ?? ""), ), Padding( padding: const EdgeInsets.all(0), child: new Text( - dateFormat.format(package.currentStatusDate), + package!.currentStatusDate != null + ? dateFormat.format(package!.currentStatusDate!) + : '', style: new TextStyle(fontSize: 15.0, color: Colors.grey), ), ), diff --git a/lib/pages/profile/profile_currency_edit.dart b/lib/pages/profile/profile_currency_edit.dart index f1d3b71..db76f8d 100644 --- a/lib/pages/profile/profile_currency_edit.dart +++ b/lib/pages/profile/profile_currency_edit.dart @@ -24,7 +24,7 @@ class _ProfileCurrencyEditState extends State { void initState() { super.initState(); MainModel mainModel = Provider.of(context, listen: false); - if (mainModel.user.preferCurrency == "MMK") { + if (mainModel.user!.preferCurrency == "MMK") { _currency = Currency.MMK; } else { _currency = Currency.USD; @@ -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/profile/profile_edit.dart b/lib/pages/profile/profile_edit.dart index db9a610..9880a87 100644 --- a/lib/pages/profile/profile_edit.dart +++ b/lib/pages/profile/profile_edit.dart @@ -24,7 +24,7 @@ class _ProfileEditState extends State { void initState() { super.initState(); MainModel mainModel = Provider.of(context, listen: false); - nameController.text = mainModel.user.name; + nameController.text = mainModel.user!.name ?? ""; } @override diff --git a/lib/pages/profile/profile_page.dart b/lib/pages/profile/profile_page.dart index 00668cb..a618c3a 100644 --- a/lib/pages/profile/profile_page.dart +++ b/lib/pages/profile/profile_page.dart @@ -18,6 +18,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import '../../helpers/theme.dart'; @@ -31,7 +32,7 @@ class Profile extends StatefulWidget { class _ProfileState extends State { GlobalKey key = GlobalKey(); bool _isLoading = false; - String? selectedLanguage ; + String? selectedLanguage; TextEditingController bizNameController = new TextEditingController(); static final List languagesList = Translation().supportedLanguages; @@ -67,18 +68,19 @@ class _ProfileState extends State { Provider.of(context); final namebox = DisplayText( - text: mainModel.user.name + " (${mainModel.user.status})", + text: "${mainModel.user!.name ?? ''}" + + " (${mainModel.user!.status ?? ''})", labelTextKey: "profile.name", iconData: Icons.person, ); final currencyBox = DisplayText( - text: mainModel.user.preferCurrency, + text: mainModel.user!.preferCurrency ?? "", labelTextKey: "profile.currency", - iconData: FontAwesome5.money_bill_alt, + iconData: FontAwesome5Regular.money_bill_alt, ); final phonenumberbox = DisplayText( - text: mainModel.user.phone, + text: mainModel.user!.phone ?? "", labelTextKey: "profile.phone", iconData: Icons.phone, ); @@ -86,15 +88,15 @@ class _ProfileState extends State { children: [ Expanded( child: DisplayText( - text: mainModel.user.fcsID, + text: mainModel.user!.fcsID ?? "", labelTextKey: "customer.fcs.id", icon: FcsIDIcon(), ), ), IconButton( icon: Icon(Icons.content_copy, color: Colors.grey), - onPressed: () => _copy( - getLocalString(context, "customer.fcs.id"), mainModel.user.fcsID), + onPressed: () => _copy(getLocalString(context, "customer.fcs.id"), + mainModel.user!.fcsID ?? ""), ) ], ); @@ -103,7 +105,7 @@ class _ProfileState extends State { children: [ Expanded( child: DisplayText( - text: mainModel.setting.usaAddress, + text: mainModel.setting!.usaAddress ?? "", labelTextKey: "profile.usa.shipping.address", iconData: Icons.location_on, ), @@ -112,7 +114,7 @@ class _ProfileState extends State { icon: Icon(Icons.content_copy, color: Colors.grey), onPressed: () => _copy( getLocalString(context, "profile.usa.shipping.address"), - mainModel.setting.usaAddress), + mainModel.setting!.usaAddress ?? ""), ) ], ); @@ -195,14 +197,14 @@ class _ProfileState extends State { } Widget getPrivilegeBox(BuildContext context) { - User user = Provider.of(context, listen: false).user; + User? user = Provider.of(context, listen: false).user; List _privileges = Provider.of(context, listen: false).privileges; if (user == null || user.isCustomer()) return Container(); List privileges = []; user.privileges.forEach((e) { - var p = _privileges.firstWhere((p) => p.id == e, orElse: () => null); + var p = _privileges.firstWhere((p) => p.id == e); if (p != null) { privileges.add(p); } @@ -270,7 +272,7 @@ class _ProfileState extends State { } _showToast(String title) { - final ScaffoldState scaffold = key.currentState; + final ScaffoldState scaffold = key.currentState as ScaffoldState; scaffold.showSnackBar( SnackBar( content: Text('copied "$title" data to clipboard'), diff --git a/lib/pages/receiving/receiving_editor.dart b/lib/pages/receiving/receiving_editor.dart index 4b0b84a..e8ec46c 100644 --- a/lib/pages/receiving/receiving_editor.dart +++ b/lib/pages/receiving/receiving_editor.dart @@ -42,8 +42,8 @@ class _ReceivingEditorState extends State { _isNew = widget.package == null; if (!_isNew) { package = widget.package!; - _trackingIDCtl.text = package.trackingID; - _remarkCtl.text = package.remark; + _trackingIDCtl.text = package.trackingID!; + _remarkCtl.text = package.remark!; _multiImgController.setImageUrls = package.photoUrls; user = User( fcsID: package.fcsID, diff --git a/lib/pages/receiving/receiving_info.dart b/lib/pages/receiving/receiving_info.dart index 08938df..d029bf8 100644 --- a/lib/pages/receiving/receiving_info.dart +++ b/lib/pages/receiving/receiving_info.dart @@ -149,8 +149,8 @@ class _ReceivingInfoState extends State { ); PackageModel packageModel = Provider.of(context, listen: false); - var pkg = await packageModel.getPackage(widget.package!.id); - initPackage(pkg); + var pkg = await packageModel.getPackage(widget.package!.id!); + initPackage(pkg!); } _delete() { diff --git a/lib/pages/receiving/receiving_list.dart b/lib/pages/receiving/receiving_list.dart index d8e9777..8f23bbb 100644 --- a/lib/pages/receiving/receiving_list.dart +++ b/lib/pages/receiving/receiving_list.dart @@ -94,7 +94,7 @@ class _ReceivingListState extends State { _searchCallback(Package package) async { var packageModel = Provider.of(context, listen: false); - Package _package = await packageModel.getPackage(package.id); + Package? _package = await packageModel.getPackage(package.id!); if (_package == null) return; Navigator.push( context, diff --git a/lib/pages/receiving/receiving_list_row.dart b/lib/pages/receiving/receiving_list_row.dart index fd65134..95430de 100644 --- a/lib/pages/receiving/receiving_list_row.dart +++ b/lib/pages/receiving/receiving_list_row.dart @@ -55,7 +55,7 @@ class ReceivingListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - package!.id == null ? '' : package!.trackingID, + package!.id == null ? '' : package!.trackingID!, style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -63,7 +63,7 @@ class ReceivingListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - package!.market == null ? '' : package!.market, + package!.market == null ? '' : package!.market!, style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -79,12 +79,14 @@ class ReceivingListRow extends StatelessWidget { children: [ Padding( padding: const EdgeInsets.all(3.0), - child: getStatus(package!.status), + child: getStatus(package!.status??""), ), Padding( padding: const EdgeInsets.all(0), child: new Text( - dateFormat.format(package!.currentStatusDate), + package!.currentStatusDate != null + ? dateFormat.format(package!.currentStatusDate!) + : '', style: new TextStyle(fontSize: 15.0, color: Colors.grey), ), ), diff --git a/lib/pages/shipment/box_row.dart b/lib/pages/shipment/box_row.dart index 5b41300..7e9d589 100644 --- a/lib/pages/shipment/box_row.dart +++ b/lib/pages/shipment/box_row.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; class BoxRow extends StatelessWidget { final Carton box; - const BoxRow({Key key, this.box}) : super(key: key); + const BoxRow({Key? key, required this.box}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/pages/shipment/model/shipment_model.dart b/lib/pages/shipment/model/shipment_model.dart index b78c4bb..0dd8c56 100644 --- a/lib/pages/shipment/model/shipment_model.dart +++ b/lib/pages/shipment/model/shipment_model.dart @@ -11,7 +11,7 @@ import 'package:logging/logging.dart'; class ShipmentModel extends BaseModel { final log = Logger('ShipmentModel'); - StreamSubscription listener; + StreamSubscription? listener; List get shipments => _menuSelectedIndex == 1 ? _shipments @@ -19,7 +19,7 @@ class ShipmentModel extends BaseModel { List _shipments = []; - Paginator _delivered; + late Paginator _delivered; bool isLoading = false; int _menuSelectedIndex = 1; @@ -28,7 +28,7 @@ class ShipmentModel extends BaseModel { notifyListeners(); } - get menuSelectedIndex => _menuSelectedIndex; + int get menuSelectedIndex => _menuSelectedIndex; initData(bool forCustomer, {bool myPickup = false}) { logout(); @@ -43,11 +43,11 @@ class ShipmentModel extends BaseModel { @override logout() async { if (_delivered != null) _delivered.close(); - if (listener != null) await listener.cancel(); + if (listener != null) await listener!.cancel(); _shipments = []; } - Future loadMore({bool isCustomer}) async { + Future loadMore({bool? isCustomer}) async { if (menuSelectedIndex == 1) return; // when delivered menu is not selected return if (_delivered.ended) return; @@ -59,7 +59,7 @@ class ShipmentModel extends BaseModel { }); } - Future refresh({bool isCustomer}) async { + Future refresh({bool? isCustomer}) async { if (menuSelectedIndex == 1) return; // when delivered menu is not selected return await _delivered.refresh(onFinished: () { @@ -70,16 +70,16 @@ class ShipmentModel extends BaseModel { Paginator _getDelivered(bool isCustomer) { if (!isCustomer) { if (user == null || - !((user.hasPackages() || - user.hasReceiving() || - user.hasProcessing()))) throw "No privilege"; + !((user!.hasPackages() || + user!.hasReceiving() || + user!.hasProcessing()))) throw "No privilege"; } - var pageQuery = Firestore.instance + var pageQuery = FirebaseFirestore.instance .collection("/$shipments_collection") .where("is_delivered", isEqualTo: true) .where("is_deleted", isEqualTo: false); if (isCustomer) { - pageQuery = pageQuery.where("user_id", isEqualTo: user.id); + pageQuery = pageQuery.where("user_id", isEqualTo: user!.id); } pageQuery = pageQuery.orderBy("status_date", descending: true); var paginator = new Paginator(pageQuery, rowPerLoad: 20, toObj: (data, id) { @@ -90,30 +90,31 @@ class ShipmentModel extends BaseModel { Future _loadShipments(bool forCustomer, bool myPickup) async { if (user == null) return; - if (!forCustomer && !user.hasShipment()) return; - if (listener != null) listener.cancel(); + if (!forCustomer && !user!.hasShipment()) return; + if (listener != null) listener!.cancel(); _shipments = []; try { - var q = Firestore.instance + var q = FirebaseFirestore.instance .collection("$shipments_collection") .where("is_delivered", isEqualTo: false) .where("is_canceled", isEqualTo: false) .where("is_deleted", isEqualTo: false); if (forCustomer) { - q = q.where("user_id", isEqualTo: user.id); + q = q.where("user_id", isEqualTo: user!.id); } if (myPickup) { - q = q.where("pickup_user_id", isEqualTo: user.id); + q = q.where("pickup_user_id", isEqualTo: user!.id); } q = q.orderBy("created_at", descending: true); listener = q.snapshots().listen((QuerySnapshot snapshot) { _shipments.clear(); - _shipments = snapshot.documents.map((documentSnapshot) { + _shipments = snapshot.docs.map((documentSnapshot) { var s = Shipment.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, + documentSnapshot.id); return s; }).toList(); notifyListeners(); @@ -130,18 +131,17 @@ class ShipmentModel extends BaseModel { shipment_courier_dropoff ]; - Shipment getActiveShipment(String shipmentID) { - return _shipments?.firstWhere((e) => e.id == shipmentID, - orElse: () => null); + Shipment? getActiveShipment(String shipmentID) { + return _shipments.firstWhere((e) => e.id == shipmentID); } - Future getShipment(String shipmentID) async { + Future getShipment(String shipmentID) async { String path = "/$shipments_collection"; try { - var ref = Firestore.instance.collection("$path").document(shipmentID); - var snap = await ref.get(source: Source.server); + var ref = FirebaseFirestore.instance.collection("$path").doc(shipmentID); + var snap = await ref.get(const GetOptions(source: Source.server)); if (snap.exists) { - var s = Shipment.fromMap(snap.data, snap.documentID); + var s = Shipment.fromMap(snap.data as Map, snap.id); return s; } } catch (e) { @@ -150,20 +150,20 @@ class ShipmentModel extends BaseModel { return null; } - Future> getShipmentWithHandlingFee( + Future?> getShipmentWithHandlingFee( String fcsShipmentID, String userID) async { String path = "/$shipments_collection"; try { - var q = Firestore.instance + var q = FirebaseFirestore.instance .collection("$path") .where("user_id", isEqualTo: userID) .where("is_deleted", isEqualTo: false) .where("handling_fee", isGreaterThan: 0) .where("fcs_shipment_id", isEqualTo: fcsShipmentID); - var snaps = await q.getDocuments(source: Source.server); - List shipments = snaps.documents.map((snap) { + var snaps = await q.get(const GetOptions(source: Source.server)); + List shipments = snaps.docs.map((snap) { if (snap.exists) { - var s = Shipment.fromMap(snap.data, snap.documentID); + var s = Shipment.fromMap(snap.data as Map, snap.id); return s; } }).toList(); diff --git a/lib/pages/shipment/shipment_assign.dart b/lib/pages/shipment/shipment_assign.dart index 5d160b2..7c37695 100644 --- a/lib/pages/shipment/shipment_assign.dart +++ b/lib/pages/shipment/shipment_assign.dart @@ -14,14 +14,14 @@ 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_icons/flutter_icons.dart'; +import 'package:flutter_icons_null_safety/flutter_icons_null_safety.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; import 'widgets.dart'; class ShipmentAssign extends StatefulWidget { - final Shipment shipment; + final Shipment? shipment; ShipmentAssign({this.shipment}); @override @@ -38,13 +38,13 @@ class _ShipmentAssignState extends State { TextEditingController _pickupDate = new TextEditingController(); TextEditingController _handlingFee = new TextEditingController(); - Shipment _shipment; + Shipment? _shipment; bool _isLoading = false; var now = new DateTime.now(); - String _selectedShipmentType; - User _user; - List _users; + String? _selectedShipmentType; + User? _user; + List? _users; @override void initState() { @@ -53,18 +53,19 @@ class _ShipmentAssignState extends State { _shipment = widget.shipment; _loadUsers(); - _selectedShipmentType = _shipment.shipmentType; - _fromTimeEditingController.text = _shipment.pickupTimeStart; - _toTimeEditingController.text = _shipment.pickupTimeEnd; - _pickupDate.text = dateFormatter.format(_shipment.pickupDate ?? now); - _handlingFee.text = _shipment.handlingFee?.toString() ?? "0"; + _selectedShipmentType = _shipment!.shipmentType; + _fromTimeEditingController.text = _shipment!.pickupTimeStart!; + _toTimeEditingController.text = _shipment!.pickupTimeEnd!; + _pickupDate.text = dateFormatter.format(_shipment!.pickupDate! ?? now); + _handlingFee.text = _shipment!.handlingFee != null + ? _shipment!.handlingFee.toString() + : "0"; } _loadUsers() async { StaffModel staffModel = Provider.of(context, listen: false); var users = await staffModel.getPickupEmployees(); - var selectUser = users.firstWhere((e) => e.id == _shipment.pickupUserID, - orElse: () => null); + var selectUser = users.firstWhere((e) => e.id == _shipment!.pickupUserID); setState(() { _users = users; _user = selectUser; @@ -74,7 +75,7 @@ class _ShipmentAssignState extends State { @override Widget build(BuildContext context) { ShipmentModel pickupModel = Provider.of(context); - final shipmentNumberBox = getShipmentNumberStatus(context, _shipment); + final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!); bool isLocalPickup = _selectedShipmentType == shipment_local_pickup; bool isCourierPickup = _selectedShipmentType == shipment_courier_pickup; bool isLocalDropoff = _selectedShipmentType == shipment_local_dropoff; @@ -146,15 +147,15 @@ class _ShipmentAssignState extends State { } _save() async { - _shipment.pickupUserID = this._user.id; - _shipment.handlingFee = double.tryParse(_handlingFee.text) ?? 0; + _shipment!.pickupUserID = this._user!.id; + _shipment!.handlingFee = double.tryParse(_handlingFee.text) ?? 0; setState(() { _isLoading = true; }); try { ShipmentModel shipmentModel = Provider.of(context, listen: false); - await shipmentModel.assignShipment(_shipment); + await shipmentModel.assignShipment(_shipment!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/shipment/shipment_box_editor.dart b/lib/pages/shipment/shipment_box_editor.dart index c04338d..1fd3778 100644 --- a/lib/pages/shipment/shipment_box_editor.dart +++ b/lib/pages/shipment/shipment_box_editor.dart @@ -17,11 +17,12 @@ import 'package:fcs/pages/widgets/my_data_table.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:flutter_icons_null_safety/flutter_icons_null_safety.dart'; + import 'package:provider/provider.dart'; class ShipmentBoxEditor extends StatefulWidget { - final Carton box; + final Carton? box; ShipmentBoxEditor({this.box}); @override @@ -33,9 +34,9 @@ class _ShipmentBoxEditorState extends State { TextEditingController _widthCtl = new TextEditingController(); TextEditingController _heightCtl = new TextEditingController(); - Carton _box; + Carton? _box; bool _isLoading = false; - bool _isNew; + late bool _isNew; double volumetricRatio = 0; double shipmentWeight = 0; @@ -50,16 +51,16 @@ class _ShipmentBoxEditorState extends State { if (widget.box != null) { _box = widget.box; _isNew = false; - _lengthCtl.text = _box.length.toString(); - _widthCtl.text = _box.width.toString(); - _heightCtl.text = _box.height.toString(); + _lengthCtl.text = _box!.length != null ? _box!.length.toString() : ''; + _widthCtl.text = _box!.width != null ? _box!.width.toString() : ''; + _heightCtl.text = _box!.height != null ? _box!.height.toString() : ''; } else { var shipmentModel = Provider.of(context, listen: false); _isNew = true; _box = Carton(cargoTypes: []); - _box.deliveryAddress = shipmentModel.defalutAddress; + _box!.deliveryAddress = shipmentModel.defalutAddress; _lengthCtl.text = "12"; _widthCtl.text = "12"; @@ -151,10 +152,11 @@ class _ShipmentBoxEditorState extends State { color: primaryColor, ), onPressed: () async { - CargoType cargo = await Navigator.push( + CargoType? cargo = await Navigator.push( context, CupertinoPageRoute( builder: (context) => CargoTypeEditor())); + if (cargo == null) return; _addCargo(cargo); }), ), @@ -186,19 +188,19 @@ class _ShipmentBoxEditorState extends State { shipmentWeightBox, LocalTitle(textKey: "shipment.box.delivery"), DefaultDeliveryAddress( - deliveryAddress: _box.deliveryAddress, + deliveryAddress: _box!.deliveryAddress, labelKey: "shipment.box.delivery", onTap: () async { - DeliveryAddress d = await Navigator.push( + DeliveryAddress? d = await Navigator.push( context, CupertinoPageRoute( builder: (context) => DeliveryAddressSelection( - deliveryAddress: _box.deliveryAddress, + deliveryAddress: _box!.deliveryAddress, user: mainModel.user)), ); if (d == null) return; setState(() { - _box.deliveryAddress = d; + _box!.deliveryAddress = d; }); }), createBtn @@ -210,25 +212,26 @@ class _ShipmentBoxEditorState extends State { } List getCargoRows(BuildContext context) { - if (_box.cargoTypes == null) { + if (_box!.cargoTypes == null) { return []; } double total = 0; - var rows = _box.cargoTypes.map((c) { + var rows = _box!.cargoTypes.map((c) { total += c.weight; return MyDataRow( onSelectChanged: (bool selected) async { - CargoType cargo = await Navigator.push( + CargoType? cargo = await Navigator.push( context, CupertinoPageRoute( builder: (context) => CargoTypeEditor( cargo: c, ))); + if (cargo == null) return; _addCargo(cargo); }, cells: [ MyDataCell(new Text( - c.name == null ? "" : c.name, + c.name == null ? "" : c.name!, style: textStyle, )), MyDataCell( @@ -281,14 +284,14 @@ class _ShipmentBoxEditorState extends State { _addCargo(CargoType cargo) { if (cargo == null) return; setState(() { - _box.cargoTypes.remove(cargo); - _box.cargoTypes.add(cargo); + _box!.cargoTypes.remove(cargo); + _box!.cargoTypes.add(cargo); }); } _removeCargo(CargoType cargo) { setState(() { - _box.cargoTypes.remove(cargo); + _box!.cargoTypes.remove(cargo); }); } @@ -296,9 +299,9 @@ class _ShipmentBoxEditorState extends State { double l = double.parse(_lengthCtl.text, (s) => 0); double w = double.parse(_widthCtl.text, (s) => 0); double h = double.parse(_heightCtl.text, (s) => 0); - _box.length = l; - _box.width = w; - _box.height = h; + _box!.length = l; + _box!.width = w; + _box!.height = h; Navigator.pop(context, _box); } } diff --git a/lib/pages/shipment/shipment_confirm.dart b/lib/pages/shipment/shipment_confirm.dart index 5017eed..68daf42 100644 --- a/lib/pages/shipment/shipment_confirm.dart +++ b/lib/pages/shipment/shipment_confirm.dart @@ -8,14 +8,15 @@ 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:flutter_icons_null_safety/flutter_icons_null_safety.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; import 'widgets.dart'; class ShipmentConfirm extends StatefulWidget { - final Shipment shipment; + final Shipment? shipment; ShipmentConfirm({this.shipment}); @override @@ -27,7 +28,7 @@ class _ShipmentConfirmState extends State { var timeFormatter = new DateFormat('jm'); TextEditingController _handlingFee = new TextEditingController(); - Shipment _shipment; + Shipment? _shipment; bool _isLoading = false; var now = new DateTime.now(); @@ -36,17 +37,17 @@ class _ShipmentConfirmState extends State { super.initState(); _shipment = widget.shipment; - _handlingFee.text = _shipment.handlingFee?.toString() ?? "0"; + _handlingFee.text = _shipment!.handlingFee?.toString() ?? "0"; } @override Widget build(BuildContext context) { - final shipmentNumberBox = getShipmentNumberStatus(context, _shipment); + final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!); final handlingFeeBox = InputText( labelTextKey: "shipment.handling.fee", controller: _handlingFee, - iconData: FontAwesome.truck, + iconData: FontAwesomeIcons.truck, ); final confirmbtn = LocalButton( textKey: "shipment.confirm.btn", @@ -94,14 +95,14 @@ class _ShipmentConfirmState extends State { } _save() async { - _shipment.handlingFee = double.tryParse(_handlingFee.text) ?? 0; + _shipment!.handlingFee = double.tryParse(_handlingFee.text) ?? 0; setState(() { _isLoading = true; }); try { ShipmentModel shipmentModel = Provider.of(context, listen: false); - await shipmentModel.confirmShipment(_shipment); + await shipmentModel.confirmShipment(_shipment!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/shipment/shipment_editor.dart b/lib/pages/shipment/shipment_editor.dart index 6ea4f81..8dda866 100644 --- a/lib/pages/shipment/shipment_editor.dart +++ b/lib/pages/shipment/shipment_editor.dart @@ -29,7 +29,7 @@ import 'shipment_box_editor.dart'; import 'widgets.dart'; class ShipmentEditor extends StatefulWidget { - final Shipment shipment; + final Shipment? shipment; ShipmentEditor({this.shipment}); @override @@ -45,12 +45,12 @@ class _ShipmentEditorState extends State { TextEditingController _toTimeEditingController = new TextEditingController(); TextEditingController _pickupDate = new TextEditingController(); - Shipment _shipment; + Shipment? _shipment; bool _isLoading = false; var now = new DateTime.now(); - bool _isNew; + late bool _isNew; - String _selectedShipmentType; + String? _selectedShipmentType; @override void initState() { @@ -59,20 +59,21 @@ class _ShipmentEditorState extends State { if (widget.shipment != null) { _isNew = false; _shipment = widget.shipment; - _selectedShipmentType = _shipment.shipmentType; - _fromTimeEditingController.text = _shipment.pickupTimeStart; - _toTimeEditingController.text = _shipment.pickupTimeEnd; - _pickupDate.text = dateFormatter.format(_shipment.pickupDate ?? now); + _selectedShipmentType = _shipment!.shipmentType; + _fromTimeEditingController.text = _shipment!.pickupTimeStart ?? ""; + _toTimeEditingController.text = _shipment!.pickupTimeEnd ?? ""; + _pickupDate.text = dateFormatter.format(_shipment!.pickupDate ?? now); } else { _isNew = true; _selectedShipmentType = shipment_local_pickup; _pickupDate.text = dateFormatter.format(now); _fromTimeEditingController.text = "${timeFormatter.format(now)}"; _toTimeEditingController.text = "${timeFormatter.format(now)}"; - _shipment = Shipment(boxes: []); + // _shipment = Shipment(boxes: []); var shipmentModel = Provider.of(context, listen: false); - _shipment.pickupAddress = shipmentModel.defalutAddress; + _shipment!.pickupAddress = shipmentModel.defalutAddress; + _shipment!.boxes = []; _pickupDate.text = dateFormatter.format(now); } } @@ -86,7 +87,7 @@ class _ShipmentEditorState extends State { Widget build(BuildContext context) { MainModel mainModel = Provider.of(context); ShipmentModel pickupModel = Provider.of(context); - final shipmentNumberBox = getShipmentNumberStatus(context, _shipment); + final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!); bool isLocalPickup = _selectedShipmentType == shipment_local_pickup; bool isCourierPickup = _selectedShipmentType == shipment_courier_pickup; bool isLocalDropoff = _selectedShipmentType == shipment_local_dropoff; @@ -121,20 +122,20 @@ class _ShipmentEditorState extends State { backgroundColor: Colors.white, )); final pickupAddressBox = DefaultDeliveryAddress( - deliveryAddress: _shipment.pickupAddress, + deliveryAddress: _shipment!.pickupAddress, iconData: Icons.location_on, labelKey: "shipment.location", onTap: () async { - DeliveryAddress address = await Navigator.push( + DeliveryAddress? address = await Navigator.push( context, CupertinoPageRoute( builder: (context) => DeliveryAddressSelection( - deliveryAddress: _shipment.pickupAddress, + deliveryAddress: _shipment!.pickupAddress, user: mainModel.user)), ); if (address == null) return; setState(() { - _shipment.pickupAddress = address; + _shipment!.pickupAddress = address; }); }, ); @@ -142,7 +143,7 @@ class _ShipmentEditorState extends State { FcsIDIcon(), Expanded( child: DisplayText( - text: mainModel.setting.usaAddress, + text: mainModel.setting!.usaAddress, ), ) ]); @@ -194,7 +195,7 @@ class _ShipmentEditorState extends State { LocalRadioButtons( values: pickupModel.shipmentTypes, selectedValue: _selectedShipmentType, - callback: (v) { + callback: (String? v) { setState(() { _selectedShipmentType = v; }); @@ -239,7 +240,7 @@ class _ShipmentEditorState extends State { ), ), Column( - children: getBoxList(context, _shipment.boxes), + children: getBoxList(context, _shipment!.boxes), ), _isNew ? createBtn : updateBtn, ], @@ -276,7 +277,7 @@ class _ShipmentEditorState extends State { _addBox(Carton box) { if (box == null) return; box.cartonType = carton_from_shipments; - _shipment.boxes.add(box); + _shipment!.boxes.add(box); setState(() {}); } @@ -287,15 +288,15 @@ class _ShipmentEditorState extends State { _removeBox(Carton box) { if (box == null) return; - _shipment.boxes.remove(box); + _shipment!.boxes.remove(box); setState(() {}); } _save() async { - _shipment.shipmentType = this._selectedShipmentType; - _shipment.pickupDate = dateFormatter.parse(_pickupDate.text); - _shipment.pickupTimeStart = _fromTimeEditingController.text; - _shipment.pickupTimeEnd = _toTimeEditingController.text; + _shipment!.shipmentType = this._selectedShipmentType; + _shipment!.pickupDate = dateFormatter.parse(_pickupDate.text); + _shipment!.pickupTimeStart = _fromTimeEditingController.text; + _shipment!.pickupTimeEnd = _toTimeEditingController.text; setState(() { _isLoading = true; }); @@ -303,9 +304,9 @@ class _ShipmentEditorState extends State { ShipmentModel shipmentModel = Provider.of(context, listen: false); if (_isNew) { - await shipmentModel.createShipment(_shipment); + await shipmentModel.createShipment(_shipment!); } else { - await shipmentModel.updateShipment(_shipment); + await shipmentModel.updateShipment(_shipment!); } Navigator.pop(context, true); } catch (e) { @@ -319,10 +320,10 @@ class _ShipmentEditorState extends State { _openCourierWebsite() { MainModel mainModel = Provider.of(context, listen: false); - launch("${mainModel.setting.courierWebsite}"); + launch("${mainModel.setting!.courierWebsite}"); } isDataChanged() { - return _shipment.boxes.isNotEmpty; + return _shipment!.boxes.isNotEmpty; } } diff --git a/lib/pages/shipment/shipment_info.dart b/lib/pages/shipment/shipment_info.dart index 0b011bc..382d2af 100644 --- a/lib/pages/shipment/shipment_info.dart +++ b/lib/pages/shipment/shipment_info.dart @@ -20,7 +20,7 @@ import 'package:fcs/pages/widgets/multi_img_controller.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:flutter_icons_null_safety/flutter_icons_null_safety.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -32,8 +32,8 @@ import 'shipment_editor.dart'; import 'widgets.dart'; class ShipmentInfo extends StatefulWidget { - final bool isCustomer; - final Shipment shipment; + final bool? isCustomer; + final Shipment? shipment; ShipmentInfo({this.shipment, this.isCustomer}); @override @@ -62,39 +62,42 @@ class _ShipmentInfoState extends State { TextEditingController _pickupDate = new TextEditingController(); TextEditingController _handlingFeeController = new TextEditingController(); - Shipment _shipment; + Shipment? _shipment; bool _isLoading = false; - bool _isCustomer; + late bool _isCustomer; var now = new DateTime.now(); @override void initState() { super.initState(); _shipment = widget.shipment; - _isCustomer = widget.isCustomer; - _loadCartons(_shipment.id); + _isCustomer = widget.isCustomer!; + _loadCartons(_shipment!.id!); - _addressEditingController.text = _shipment.address; - _fromTimeEditingController.text = _shipment.pickupTimeStart; - _toTimeEditingController.text = _shipment.pickupTimeEnd; - _noOfPackageEditingController.text = _shipment.numberOfPackage.toString(); - _weightEditingController.text = _shipment.weight.toString(); - _pickupDate.text = dateFormatter.format(_shipment.pickupDate ?? now); + _addressEditingController.text = _shipment!.address ?? ""; + _fromTimeEditingController.text = _shipment!.pickupTimeStart ?? ""; + _toTimeEditingController.text = _shipment!.pickupTimeEnd ?? ""; + _noOfPackageEditingController.text = _shipment!.numberOfPackage != null + ? _shipment!.numberOfPackage.toString() + : ""; + _weightEditingController.text = + _shipment!.weight != null ? _shipment!.weight.toString() : ""; + _pickupDate.text = dateFormatter.format(_shipment!.pickupDate ?? now); } _loadCartons(String shipmentID) async { CartonModel cartonModel = Provider.of(context, listen: false); var cartons = await cartonModel.getCartons(shipmentID); setState(() { - _shipment.boxes = cartons; + _shipment!.boxes = cartons; }); } _loadShipment(String id) async { ShipmentModel shipmentModel = Provider.of(context, listen: false); - Shipment s = await shipmentModel.getShipment(id); - s.boxes = _shipment.boxes; + Shipment? s = await shipmentModel.getShipment(id); + s!.boxes = _shipment!.boxes; setState(() { _shipment = s; }); @@ -109,31 +112,34 @@ class _ShipmentInfoState extends State { Widget build(BuildContext context) { MainModel mainModel = Provider.of(context); ShipmentModel pickupModel = Provider.of(context); - bool isLocalPickup = _shipment.shipmentType == shipment_local_pickup; - bool isCourierPickup = _shipment.shipmentType == shipment_courier_pickup; - bool isLocalDropoff = _shipment.shipmentType == shipment_local_dropoff; - bool isCourierDropoff = _shipment.shipmentType == shipment_courier_dropoff; - bool isEditable = widget.isCustomer - ? (_shipment.isPending || _shipment.isAssigned) - : (_shipment.isPending || _shipment.isAssigned || _shipment.isPickuped); + bool isLocalPickup = _shipment!.shipmentType == shipment_local_pickup; + bool isCourierPickup = _shipment!.shipmentType == shipment_courier_pickup; + bool isLocalDropoff = _shipment!.shipmentType == shipment_local_dropoff; + bool isCourierDropoff = _shipment!.shipmentType == shipment_courier_dropoff; + bool isEditable = widget.isCustomer! + ? (_shipment!.isPending || _shipment!.isAssigned) + : (_shipment!.isPending || + _shipment!.isAssigned || + _shipment!.isPickuped); bool canCancel = - _shipment.isPending || _shipment.isConfirmed || _shipment.isAssigned; + _shipment!.isPending || _shipment!.isConfirmed || _shipment!.isAssigned; final popupMenu = LocalPopupMenuButton( popmenus: [ LocalPopupMenu( - enabled: _shipment.isPending && isLocalPickup, + enabled: _shipment!.isPending && isLocalPickup, id: 1, textKey: "shipment.assign.for.pickup", ), LocalPopupMenu( enabled: - (_shipment.isPickuped && isLocalPickup) || _shipment.isReceived, + (_shipment!.isPickuped && isLocalPickup) || _shipment!.isReceived, id: 3, textKey: "shipment.pack.menuitem", ), LocalPopupMenu( - enabled: _shipment.isPending && (isCourierPickup || isCourierDropoff), + enabled: + _shipment!.isPending && (isCourierPickup || isCourierDropoff), id: 4, textKey: "shipment.confirm.menuitem", ), @@ -149,7 +155,11 @@ class _ShipmentInfoState extends State { ? _gotoAssign() : p.id == 2 ? _cancel() - : p.id == 3 ? _gotoPack() : p.id == 4 ? _gotoConfirm() : null, + : p.id == 3 + ? _gotoPack() + : p.id == 4 + ? _gotoConfirm() + : null, ); final popupMenuCustomer = LocalPopupMenuButton( popmenus: [ @@ -163,29 +173,31 @@ class _ShipmentInfoState extends State { buttonIcon: Icons.more_vert, popupMenuCallback: (p) => p.id == 2 ? _cancel() : null, ); - final shipmentNumberBox = getShipmentNumberStatus(context, _shipment); + final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!); final fromTimeBox = DisplayText( labelTextKey: 'shipment.from', iconData: Icons.timer, - text: _shipment.pickupTimeStart, + text: _shipment!.pickupTimeStart ?? "", ); final toTimeBox = DisplayText( labelTextKey: 'shipment.to', iconData: Icons.timer_off, - text: _shipment.pickupTimeEnd, + text: _shipment!.pickupTimeEnd ?? "", ); final pickupDateBox = DisplayText( labelTextKey: "shipment.date", iconData: Icons.date_range, - text: dateFormatter.format(_shipment.pickupDate), + text: _shipment!.pickupDate != null + ? dateFormatter.format(_shipment!.pickupDate!) + : '', ); var localDropoffAddressBox = Row(children: [ FcsIDIcon(), Expanded( child: DisplayText( - text: mainModel.setting.usaAddress, + text: mainModel.setting!.usaAddress ?? "", ), ) ]); @@ -201,17 +213,17 @@ class _ShipmentInfoState extends State { backgroundColor: Colors.white, )); final pickupAddressBox = DefaultDeliveryAddress( - deliveryAddress: _shipment.pickupAddress, + deliveryAddress: _shipment!.pickupAddress, iconData: Icons.location_on, labelKey: "shipment.location", ); var usersBox = DisplayText( labelTextKey: "shipment.staff", - text: _shipment.pickupUserName, + text: _shipment!.pickupUserName ?? "", iconData: MaterialCommunityIcons.worker); var handlingFeeBox = DisplayText( labelTextKey: "shipment.handling.fee", - text: (_shipment.handlingFee ?? 0).toString(), + text: (_shipment!.handlingFee ?? 0).toString(), iconData: FontAwesome.truck); final assignCompleteBtn = LocalButton( @@ -232,7 +244,7 @@ class _ShipmentInfoState extends State { ); final fcsShipmentNumberBox = DisplayText( - text: _shipment.fcsShipmentNumber, + text: _shipment!.fcsShipmentNumber ?? "", labelTextKey: "FCSshipment.number", iconData: Ionicons.ios_airplane, ); @@ -267,7 +279,7 @@ class _ShipmentInfoState extends State { color: isEditable ? primaryColor : Colors.grey), onPressed: isEditable ? _edit : null, ), - widget.isCustomer ? popupMenuCustomer : popupMenu, + widget.isCustomer! ? popupMenuCustomer : popupMenu, ]), body: Padding( padding: const EdgeInsets.all(10.0), @@ -278,7 +290,7 @@ class _ShipmentInfoState extends State { LocalRadioButtons( readOnly: true, values: pickupModel.shipmentTypes, - selectedValue: _shipment.shipmentType, + selectedValue: _shipment!.shipmentType, ), ...(isLocalDropoff ? [ @@ -305,13 +317,13 @@ class _ShipmentInfoState extends State { LocalTitle( textKey: "boxes.name", trailing: Text( - "${_shipment.totalCount} Cartons - ${_shipment.totalWeight} lb"), + "${_shipment!.totalCount} Cartons - ${_shipment!.totalWeight} lb"), ), Column( - children: getBoxList(context, _shipment.boxes), + children: getBoxList(context, _shipment!.boxes), ), !_isCustomer ? fcsShipmentNumberBox : Container(), - ...(!_shipment.isPending + ...(!_shipment!.isPending ? [ handlingFeeBox, ] @@ -324,22 +336,22 @@ class _ShipmentInfoState extends State { : []), ...(isLocalPickup && !_isCustomer ? [ - _shipment.isPending ? assignCompleteBtn : Container(), - _shipment.isAssigned ? completePickupBtn : Container(), - _shipment.isPickuped ? completePackBtn : Container(), + _shipment!.isPending ? assignCompleteBtn : Container(), + _shipment!.isAssigned ? completePickupBtn : Container(), + _shipment!.isPickuped ? completePackBtn : Container(), ] : []), ...((isCourierPickup || isCourierDropoff) && !_isCustomer ? [ - _shipment.isPending ? confirmCompleteBtn : Container(), - _shipment.isConfirmed ? completeReceiveBtn : Container(), - _shipment.isReceived ? completePackBtn : Container(), + _shipment!.isPending ? confirmCompleteBtn : Container(), + _shipment!.isConfirmed ? completeReceiveBtn : Container(), + _shipment!.isReceived ? completePackBtn : Container(), ] : []), ...((isLocalDropoff) && !_isCustomer ? [ - _shipment.isPending ? completeReceiveBtn : Container(), - _shipment.isReceived ? completePackBtn : Container(), + _shipment!.isPending ? completeReceiveBtn : Container(), + _shipment!.isReceived ? completePackBtn : Container(), ] : []), ], @@ -361,7 +373,7 @@ class _ShipmentInfoState extends State { } _edit() async { - bool updated = await Navigator.push( + bool? updated = await Navigator.push( context, CupertinoPageRoute( builder: (context) => ShipmentEditor( @@ -369,8 +381,8 @@ class _ShipmentInfoState extends State { )), ); if (updated ?? false) { - await _loadShipment(_shipment.id); - await _loadCartons(_shipment.id); + await _loadShipment(_shipment!.id!); + await _loadCartons(_shipment!.id!); } } @@ -387,7 +399,7 @@ class _ShipmentInfoState extends State { try { ShipmentModel shipmentModel = Provider.of(context, listen: false); - await shipmentModel.cancelShipment(_shipment); + await shipmentModel.cancelShipment(_shipment!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); @@ -400,11 +412,11 @@ class _ShipmentInfoState extends State { _openCourierWebsite() { MainModel mainModel = Provider.of(context, listen: false); - launch("${mainModel.setting.courierWebsite}"); + launch("${mainModel.setting!.courierWebsite}"); } _gotoAssign() async { - bool assigned = await Navigator.push( + bool? assigned = await Navigator.push( context, CupertinoPageRoute( builder: (context) => ShipmentAssign( @@ -412,7 +424,7 @@ class _ShipmentInfoState extends State { )), ); if (assigned ?? false) { - await _loadShipment(_shipment.id); + await _loadShipment(_shipment!.id!); } } @@ -429,7 +441,7 @@ class _ShipmentInfoState extends State { try { ShipmentModel shipmentModel = Provider.of(context, listen: false); - await shipmentModel.completeAssignShipment(_shipment); + await shipmentModel.completeAssignShipment(_shipment!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); @@ -453,7 +465,7 @@ class _ShipmentInfoState extends State { try { ShipmentModel shipmentModel = Provider.of(context, listen: false); - await shipmentModel.completePickupShipment(_shipment); + await shipmentModel.completePickupShipment(_shipment!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); @@ -465,16 +477,16 @@ class _ShipmentInfoState extends State { } _gotoPack() async { - bool assigned = await Navigator.push( + bool? assigned = await Navigator.push( context, CupertinoPageRoute( builder: (context) => ShipmentPack( - shipment: _shipment, + shipment: _shipment!, )), ); if (assigned ?? false) { - await _loadShipment(_shipment.id); - await _loadCartons(_shipment.id); + await _loadShipment(_shipment!.id!); + await _loadCartons(_shipment!.id!); } } @@ -491,7 +503,7 @@ class _ShipmentInfoState extends State { try { ShipmentModel shipmentModel = Provider.of(context, listen: false); - await shipmentModel.completePackShipment(_shipment); + await shipmentModel.completePackShipment(_shipment!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); @@ -503,7 +515,7 @@ class _ShipmentInfoState extends State { } _gotoConfirm() async { - bool assigned = await Navigator.push( + bool? assigned = await Navigator.push( context, CupertinoPageRoute( builder: (context) => ShipmentConfirm( @@ -511,7 +523,7 @@ class _ShipmentInfoState extends State { )), ); if (assigned ?? false) { - await _loadShipment(_shipment.id); + await _loadShipment(_shipment!.id!); } } @@ -528,7 +540,7 @@ class _ShipmentInfoState extends State { try { ShipmentModel shipmentModel = Provider.of(context, listen: false); - await shipmentModel.completeConfirmShipment(_shipment); + await shipmentModel.completeConfirmShipment(_shipment!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); @@ -552,7 +564,7 @@ class _ShipmentInfoState extends State { try { ShipmentModel shipmentModel = Provider.of(context, listen: false); - await shipmentModel.completeReceiveShipment(_shipment); + await shipmentModel.completeReceiveShipment(_shipment!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/shipment/shipment_list.dart b/lib/pages/shipment/shipment_list.dart index 1424639..af047ab 100644 --- a/lib/pages/shipment/shipment_list.dart +++ b/lib/pages/shipment/shipment_list.dart @@ -17,7 +17,7 @@ import 'shipment_list_row.dart'; class ShipmentList extends StatefulWidget { final bool forCustomer; - const ShipmentList({Key key, this.forCustomer = true}) : super(key: key); + const ShipmentList({Key? key, this.forCustomer = true}) : super(key: key); @override _ShipmentListState createState() => _ShipmentListState(); } diff --git a/lib/pages/shipment/shipment_list_row.dart b/lib/pages/shipment/shipment_list_row.dart index d09d086..329e29b 100644 --- a/lib/pages/shipment/shipment_list_row.dart +++ b/lib/pages/shipment/shipment_list_row.dart @@ -2,15 +2,15 @@ import 'package:fcs/domain/entities/shipment.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_icons/flutter_icons.dart'; +import 'package:flutter_icons_null_safety/flutter_icons_null_safety.dart'; import '../main/util.dart'; import 'shipment_info.dart'; class ShipmentListRow extends StatelessWidget { - final Shipment shipment; - final bool isCustomer; - const ShipmentListRow({Key key, this.shipment, this.isCustomer}) + final Shipment? shipment; + final bool? isCustomer; + const ShipmentListRow({Key? key, this.shipment, this.isCustomer}) : super(key: key); @override @@ -45,7 +45,7 @@ class ShipmentListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - shipment.shipmentNumber ?? "", + shipment!.shipmentNumber ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -69,7 +69,7 @@ class ShipmentListRow extends StatelessWidget { children: [ Padding( padding: const EdgeInsets.all(0), - child: getStatus(shipment.status ?? ""), + child: getStatus(shipment!.status ?? ""), ), // Padding( // padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5), diff --git a/lib/pages/shipment/shipment_pack.dart b/lib/pages/shipment/shipment_pack.dart index 245c1ff..affdfad 100644 --- a/lib/pages/shipment/shipment_pack.dart +++ b/lib/pages/shipment/shipment_pack.dart @@ -11,14 +11,14 @@ 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_icons/flutter_icons.dart'; +import 'package:flutter_icons_null_safety/flutter_icons_null_safety.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; import 'widgets.dart'; class ShipmentPack extends StatefulWidget { - final Shipment shipment; + final Shipment? shipment; ShipmentPack({this.shipment}); @override @@ -29,12 +29,12 @@ class _ShipmentPackState extends State { var dateFormatter = new DateFormat('dd MMM yyyy'); var timeFormatter = new DateFormat('jm'); - Shipment _shipment; + Shipment? _shipment; bool _isLoading = false; var now = new DateTime.now(); - FcsShipment _fcsShipment; - List _fcsShipments; + FcsShipment? _fcsShipment; + List? _fcsShipments; @override void initState() { @@ -48,8 +48,8 @@ class _ShipmentPackState extends State { FcsShipmentModel fcsShipmentModel = Provider.of(context, listen: false); var fcsShipments = await fcsShipmentModel.getActiveFcsShipments(); - var fcsShipment = fcsShipments - .firstWhere((e) => e.id == _shipment.fcsShipmentID, orElse: () => null); + var fcsShipment = + fcsShipments.firstWhere((e) => e.id == _shipment?.fcsShipmentID); setState(() { _fcsShipments = fcsShipments; _fcsShipment = fcsShipment; @@ -58,7 +58,7 @@ class _ShipmentPackState extends State { @override Widget build(BuildContext context) { - final shipmentNumberBox = getShipmentNumberStatus(context, _shipment); + final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!); var fcsShipmentsBox = LocalDropdown( callback: (v) { @@ -120,14 +120,14 @@ class _ShipmentPackState extends State { } _save() async { - _shipment.fcsShipmentID = this._fcsShipment.id; + _shipment!.fcsShipmentID = this._fcsShipment!.id; setState(() { _isLoading = true; }); try { ShipmentModel shipmentModel = Provider.of(context, listen: false); - await shipmentModel.packShipment(_shipment); + await shipmentModel.packShipment(_shipment!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/widgets/multi_img_controller.dart b/lib/pages/widgets/multi_img_controller.dart index 794796a..273055d 100644 --- a/lib/pages/widgets/multi_img_controller.dart +++ b/lib/pages/widgets/multi_img_controller.dart @@ -78,9 +78,9 @@ class MultiImgController { } } - List get getUpdatedFile { + List get getUpdatedFile { List _addfiles = getAddedFile; - this.imageFiles.addAll(_addfiles); + this.imageFiles!.addAll(_addfiles); return this.imageFiles; } From d5fea4f81feecaa5a1cc0513af0feaa78551c837 Mon Sep 17 00:00:00 2001 From: phyothandar Date: Fri, 10 Sep 2021 16:56:12 +0630 Subject: [PATCH 5/5] merge --- pubspec.lock | 43 +++++++++++++++++++++++++++++++++++++++---- pubspec.yaml | 1 - 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index a551a79..2901b05 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -112,21 +112,21 @@ packages: name: cloud_firestore url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.5.2" cloud_firestore_platform_interface: dependency: transitive description: name: cloud_firestore_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "5.4.0" + version: "5.4.1" cloud_firestore_web: dependency: transitive description: name: cloud_firestore_web url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.4.2" collection: dependency: transitive description: @@ -280,7 +280,7 @@ packages: name: firebase_core url: "https://pub.dartlang.org" source: hosted - version: "1.5.0" + version: "1.6.0" firebase_core_platform_interface: dependency: transitive description: @@ -349,6 +349,27 @@ 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: + 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 +394,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 +894,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: diff --git a/pubspec.yaml b/pubspec.yaml index fa11d2e..e60aa6c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -46,7 +46,6 @@ dependencies: flutter_icons_null_safety: ^1.1.0 country_icons: ^2.0.2 timeline_list: ^0.0.5 - barcode_scan2: ^4.1.3 barcode_scan2: ^4.1.4 flutter_pdfview: ^1.2.1 flutter_local_notifications: ^8.2.0