From d8c86a512b6a7145f220064cfb0633c30bed53c6 Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 10 Sep 2021 16:33:52 +0630 Subject: [PATCH 1/3] check null safety --- lib/domain/entities/carton.dart | 9 ++- lib/domain/entities/rate.dart | 4 +- lib/pages/carton/cargo_table.dart | 4 +- lib/pages/carton/cargo_type_addtion.dart | 8 +- lib/pages/carton/cargo_type_editor.dart | 4 +- lib/pages/carton/carton_cargo_table.dart | 13 ++- lib/pages/carton/carton_cargo_table_old.dart | 6 +- lib/pages/carton/carton_editor.dart | 26 +++--- lib/pages/carton/carton_info.dart | 24 +++--- lib/pages/carton/carton_list_row.dart | 12 +-- lib/pages/carton/carton_mix_table.dart | 4 +- lib/pages/carton/carton_package_table.dart | 8 +- lib/pages/carton/carton_row.dart | 14 ++-- lib/pages/carton/model/carton_model.dart | 80 +++++++++---------- lib/pages/carton/package_carton_editor.dart | 9 +-- lib/pages/carton/widgets.dart | 2 +- lib/pages/carton_search/carton_list_row.dart | 27 ++----- lib/pages/carton_size/carton_size_editor.dart | 2 +- lib/pages/carton_size/carton_size_list.dart | 4 +- .../carton_size/model/carton_size_model.dart | 13 +-- lib/pages/chat/bubble.dart | 25 +++--- lib/pages/chat/message_detail.dart | 32 ++++---- lib/pages/chat/model/message_model.dart | 43 +++++----- lib/pages/contact/contact_page.dart | 11 +-- lib/pages/customer/customer_editor.dart | 6 +- lib/pages/customer/customer_list.dart | 10 +-- lib/pages/customer/invitation_editor.dart | 6 +- lib/pages/customer/model/customer_model.dart | 49 ++++++------ lib/pages/main/home_page.dart | 10 ++- lib/pages/rates/cargo_editor.dart | 4 +- lib/pages/rates/cargo_type_list.dart | 2 +- lib/pages/rates/custom_editor.dart | 4 +- lib/pages/rates/custom_list.dart | 2 +- lib/pages/rates/custom_row.dart | 2 +- .../rates/discount_by_weight_editor.dart | 2 +- .../rates/model/shipment_rate_model.dart | 13 ++- lib/pages/rates/shipment_rates.dart | 8 +- lib/pages/rates/shipment_rates_calculate.dart | 1 + lib/pages/rates/shipment_rates_edit.dart | 11 ++- lib/pages/signin/signin_logic.dart | 7 +- lib/pages/signin/signin_page.dart | 2 +- lib/pages/user_search/user_list_row.dart | 26 ++---- lib/pages/user_search/user_serach.dart | 18 ++--- lib/pages/widgets/banner.dart | 2 +- lib/pages/widgets/barcode_scanner.dart | 8 +- lib/pages/widgets/bottom_widgets.dart | 2 +- 46 files changed, 275 insertions(+), 304 deletions(-) diff --git a/lib/domain/entities/carton.dart b/lib/domain/entities/carton.dart index 8006051..22254ac 100644 --- a/lib/domain/entities/carton.dart +++ b/lib/domain/entities/carton.dart @@ -64,8 +64,9 @@ class Carton { // String get packageNumber => // shipmentNumber + "-" + receiverNumber + " #" + boxNumber; - double get actualWeight => - cargoTypes == null ? 0 : cargoTypes.fold(0, (p, e) => e.weight + p); + double get actualWeight => cargoTypes == null + ? 0 + : cargoTypes.fold(0, (p, e) => e.weight + p); int getShipmentWeight(double volumetricRatio) { if (length == null || @@ -114,8 +115,8 @@ class Carton { double total = 0; cargoTypes.forEach((e) { - double r = - e.rate - (discountByWeight != null ? (discountByWeight.discount) : 0); + double r = e.rate - + (discountByWeight != null ? (discountByWeight.discount) : 0); double amount = e.weight * r; total += amount; }); diff --git a/lib/domain/entities/rate.dart b/lib/domain/entities/rate.dart index 566d827..54442e8 100644 --- a/lib/domain/entities/rate.dart +++ b/lib/domain/entities/rate.dart @@ -19,9 +19,7 @@ class Rate { return discountByWeights.firstWhere((e) => e.weight < weight); } - CargoType? get defaultCargoType => cargoTypes == null - ? null - : cargoTypes.firstWhere((e) => e.name == "General"); + CargoType get defaultCargoType => cargoTypes.firstWhere((e) => e.name == "General"); Rate( {this.deliveryFee = 0, diff --git a/lib/pages/carton/cargo_table.dart b/lib/pages/carton/cargo_table.dart index 9e85b0f..9266868 100644 --- a/lib/pages/carton/cargo_table.dart +++ b/lib/pages/carton/cargo_table.dart @@ -59,7 +59,7 @@ class _CargoTableState extends State { } double total = 0; var rows = widget.cargoTypes!.map((c) { - total += c.weight!; + total += c.weight; return MyDataRow( onSelectChanged: (bool selected) async {}, cells: [ @@ -81,7 +81,7 @@ class _CargoTableState extends State { ), )), MyDataCell( - Text(c.weight == null ? "0" : c.weight!.toStringAsFixed(2), + Text(c.weight == null ? "0" : c.weight.toStringAsFixed(2), style: textStyle), ), ], diff --git a/lib/pages/carton/cargo_type_addtion.dart b/lib/pages/carton/cargo_type_addtion.dart index c60fa0d..0201e9b 100644 --- a/lib/pages/carton/cargo_type_addtion.dart +++ b/lib/pages/carton/cargo_type_addtion.dart @@ -61,7 +61,7 @@ class _CargoTypeAdditionState extends State { child: InkWell( onTap: () { setState(() { - c.isChecked = !c.isChecked!; + c.isChecked = !c.isChecked; }); }, child: Row( @@ -71,7 +71,7 @@ class _CargoTypeAdditionState extends State { activeColor: primaryColor, onChanged: (bool? check) { setState(() { - c.isChecked = check; + c.isChecked = check ?? false; }); }), new Text(c.name ?? '', style: textStyle), @@ -88,9 +88,9 @@ class _CargoTypeAdditionState extends State { getLocalString(context, 'box.cargo.select.btn'), callack: () { List _cargos = - this.cargos.where((c) => c.isChecked!).toList(); + this.cargos.where((c) => c.isChecked).toList(); List _scargos = - this.specialCargos.where((c) => c.isChecked!).toList(); + this.specialCargos.where((c) => c.isChecked).toList(); _cargos.addAll(_scargos); Navigator.pop(context, _cargos); }, diff --git a/lib/pages/carton/cargo_type_editor.dart b/lib/pages/carton/cargo_type_editor.dart index a4eac59..7c8553a 100644 --- a/lib/pages/carton/cargo_type_editor.dart +++ b/lib/pages/carton/cargo_type_editor.dart @@ -30,7 +30,7 @@ class _CargoTypeEditorState extends State { super.initState(); if (widget.cargo != null) { _cargo = widget.cargo; - _weightController.text = _cargo!.weight!.toStringAsFixed(2); + _weightController.text = _cargo!.weight.toStringAsFixed(2); } else { _loadDefalut(); } @@ -39,7 +39,7 @@ class _CargoTypeEditorState extends State { _loadDefalut() { ShipmentRateModel shipmentRateModel = Provider.of(context, listen: false); - _cargo = shipmentRateModel.rate.defaultCargoType.clone(); + _cargo = shipmentRateModel.rate.defaultCargoType?.clone(); } @override diff --git a/lib/pages/carton/carton_cargo_table.dart b/lib/pages/carton/carton_cargo_table.dart index 6b2c16f..cd02930 100644 --- a/lib/pages/carton/carton_cargo_table.dart +++ b/lib/pages/carton/carton_cargo_table.dart @@ -33,7 +33,7 @@ class _CargoTableState extends State { cargoTypes = widget.cargoTypes; if (!widget.isNew!) { totalWeight = - cargoTypes!.fold(0, (previous, current) => previous + current.weight!); + cargoTypes!.fold(0, (previous, current) => previous + current.weight); } super.initState(); @@ -42,7 +42,7 @@ class _CargoTableState extends State { @override Widget build(BuildContext context) { print("Cargotypes:${cargoTypes!.length}"); - + return SingleChildScrollView( scrollDirection: Axis.horizontal, child: MyDataTable( @@ -86,7 +86,7 @@ class _CargoTableState extends State { cells: [ MyDataCell( new Text( - c.name ??'', + c.name ?? '', style: textStyle, ), ), @@ -144,7 +144,7 @@ class _CargoTableState extends State { context: context, builder: (_) => DialogInput( label: "cargo.weight", - value: c.weight!.toStringAsFixed(2))); + value: c.weight.toStringAsFixed(2))); if (_t == null) return; setState(() { @@ -162,7 +162,7 @@ class _CargoTableState extends State { borderRadius: BorderRadius.all(Radius.circular(5.0)), ), child: Text( - c.weight == null ? "0.00" : c.weight!.toStringAsFixed(2), + c.weight == null ? "0.00" : c.weight.toStringAsFixed(2), style: textStyle), ), ), @@ -252,11 +252,10 @@ class _CargoTableState extends State { } CargoType? autoCalWeight(List cargoTypes, double total) { - if ((cargoTypes?.length ?? 0) == 0 || total == 0) return null; List noWeight = cargoTypes.where((c) => c.weight == 0).toList(); if (noWeight.length != 1) return null; - var _existing = + double _existing = cargoTypes.fold(0, (previous, current) => previous + current.weight); noWeight[0].weight = total - _existing; diff --git a/lib/pages/carton/carton_cargo_table_old.dart b/lib/pages/carton/carton_cargo_table_old.dart index 1b0c840..05378f2 100644 --- a/lib/pages/carton/carton_cargo_table_old.dart +++ b/lib/pages/carton/carton_cargo_table_old.dart @@ -1,12 +1,10 @@ import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/my_data_table.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'cargo_type_editor.dart'; import 'total_weight_edit.dart'; typedef OnAdd(CargoType cargoType); @@ -68,7 +66,7 @@ class _CargoTableState extends State { double _total = 0; var rows = widget.cargoTypes!.map((c) { - _total += c.weight!; + _total += c.weight; return MyDataRow( onSelectChanged: (bool selected) async {}, cells: [ @@ -88,7 +86,7 @@ class _CargoTableState extends State { Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - Text(c.weight!.toStringAsFixed(2), style: textStyle), + Text(c.weight.toStringAsFixed(2), style: textStyle), widget.onRemove == null ? SizedBox( width: 50, diff --git a/lib/pages/carton/carton_editor.dart b/lib/pages/carton/carton_editor.dart index 6281b57..e83d6b1 100644 --- a/lib/pages/carton/carton_editor.dart +++ b/lib/pages/carton/carton_editor.dart @@ -51,7 +51,7 @@ class _CartonEditorState extends State { TextEditingController _widthController = new TextEditingController(); TextEditingController _heightController = new TextEditingController(); TextEditingController _lengthController = new TextEditingController(); - DeliveryAddress _deliveryAddress = new DeliveryAddress(); + DeliveryAddress? _deliveryAddress = new DeliveryAddress(); List _cargoTypes = []; Carton? _carton; @@ -151,12 +151,12 @@ class _CartonEditorState extends State { PackageModel packageModel = Provider.of(context, listen: false); List packages = await packageModel.getPackages( - _user!.id, [package_processed_status, package_packed_status]); + _user!.id!, [package_processed_status, package_packed_status]); if (_isNew) { String? prevCompare; packages.forEach((p) { - String compare = - (p.deliveryAddress.fullName) + (p.deliveryAddress.phoneNumber); + String compare = (p.deliveryAddress?.fullName ?? "") + + (p.deliveryAddress?.phoneNumber ?? ""); if (prevCompare != null && compare == prevCompare) { p.isChecked = true; } else { @@ -195,9 +195,9 @@ class _CartonEditorState extends State { // } _calShipmentWeight() { - double l = double.parse(_lengthController.text, (s) => 0); - double w = double.parse(_widthController.text, (s) => 0); - double h = double.parse(_heightController.text, (s) => 0); + double l = double.parse(_lengthController.text); + double w = double.parse(_widthController.text); + double h = double.parse(_heightController.text); setState(() { shipmentWeight = l * w * h / volumetricRatio; }); @@ -757,7 +757,7 @@ class _CartonEditorState extends State { .map>((CartonSize value) { return DropdownMenuItem( value: value, - child: Text(value.name, + child: Text(value.name ?? "", overflow: TextOverflow.ellipsis, style: TextStyle( color: value.name == MANAGE_CARTONSIZE @@ -863,7 +863,7 @@ class _CartonEditorState extends State { ); if (_c == null) return; var cartonModel = Provider.of(context, listen: false); - Carton _carton = await cartonModel.getCarton(_c.id); + Carton _carton = await cartonModel.getCarton(_c.id ?? ""); if (isFromPackages) { _cartons.add(_carton); } @@ -935,13 +935,13 @@ class _CartonEditorState extends State { showMsgDialog(context, "Error", "Expect at least one cargo type"); return; } - if (_cargoTypes.where((c) => c.weight! <= 0).isNotEmpty) { + if (_cargoTypes.where((c) => c.weight <= 0).isNotEmpty) { showMsgDialog(context, "Error", "Invalid cargo weight"); return; } - double l = double.parse(_lengthController.text, (s) => 0); - double w = double.parse(_widthController.text, (s) => 0); - double h = double.parse(_heightController.text, (s) => 0); + double l = double.parse(_lengthController.text); + double w = double.parse(_widthController.text); + double h = double.parse(_heightController.text); if ((l <= 0 || w <= 0 || h <= 0) && (isFromPackages || isFromCartons)) { showMsgDialog(context, "Error", "Invalid dimension"); return; diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index 6b6c1de..68358c3 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -1,7 +1,5 @@ import 'package:fcs/domain/constants.dart'; -import 'package:fcs/domain/entities/cargo_type.dart'; import 'package:fcs/domain/entities/carton.dart'; -import 'package:fcs/domain/entities/carton_size.dart'; import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/helpers/theme.dart'; @@ -43,7 +41,7 @@ class CartonInfo extends StatefulWidget { class _CartonInfoState extends State { bool _isLoading = false; Carton? _box; - DeliveryAddress _deliveryAddress = new DeliveryAddress(); + DeliveryAddress? _deliveryAddress = new DeliveryAddress(); TextEditingController _widthController = new TextEditingController(); TextEditingController _heightController = new TextEditingController(); TextEditingController _lengthController = new TextEditingController(); @@ -80,7 +78,7 @@ class _CartonInfoState extends State { _widthController.text = _box!.width.toString(); _heightController.text = _box!.height.toString(); _lengthController.text = _box!.length.toString(); - _cartonSizeController.text = _box!.cartonSizeName; + _cartonSizeController.text = _box!.cartonSizeName ?? ""; _deliveryAddress = _box!.deliveryAddress; isMixBox = _box!.cartonType == carton_mix_box; isFromShipments = _box!.cartonType == carton_from_shipments; @@ -101,7 +99,7 @@ class _CartonInfoState extends State { c.width == _box!.width && c.height == _box!.height) { setState(() { - _cartonSizeController.text = c.name; + _cartonSizeController.text = c.name ?? ""; }); } }); @@ -114,7 +112,8 @@ class _CartonInfoState extends State { 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, @@ -145,9 +144,9 @@ class _CartonInfoState extends State { } _calShipmentWeight() { - double l = double.parse(_lengthController.text, (s) => 0); - double w = double.parse(_widthController.text, (s) => 0); - double h = double.parse(_heightController.text, (s) => 0); + double l = double.parse(_lengthController.text); + double w = double.parse(_widthController.text); + double h = double.parse(_heightController.text); setState(() { shipmentWeight = l * w * h / volumetricRatio; }); @@ -167,8 +166,9 @@ class _CartonInfoState 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", @@ -416,7 +416,7 @@ class _CartonInfoState extends State { ); if (updated ?? false) { var cartonModel = Provider.of(context, listen: false); - var c = await cartonModel.getCarton(widget.box!.id); + var c = await cartonModel.getCarton(widget.box!.id ?? ""); setState(() { _box = c; _loadPackages(); diff --git a/lib/pages/carton/carton_list_row.dart b/lib/pages/carton/carton_list_row.dart index aada457..8f61bb3 100644 --- a/lib/pages/carton/carton_list_row.dart +++ b/lib/pages/carton/carton_list_row.dart @@ -8,8 +8,8 @@ import 'package:intl/intl.dart'; import 'carton_info.dart'; class CartonListRow extends StatelessWidget { - final Carton? box; - CartonListRow({Key? key, this.box}) : super(key: key); + final Carton box; + CartonListRow({Key? key, required this.box}) : super(key: key); final double dotSize = 15.0; final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); @@ -47,7 +47,7 @@ class CartonListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - box!.cartonNumber , + box.cartonNumber ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -55,7 +55,7 @@ class CartonListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 10.0, top: 10), child: new Text( - box!.userName, + box.userName ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), @@ -71,14 +71,14 @@ class CartonListRow extends StatelessWidget { children: [ Padding( padding: const EdgeInsets.all(0), - child: getStatus(box!.status == null ? "" : box!.status), + child: getStatus(box.status ?? ""), ), Padding( padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5), child: Row( children: [ new Text( - "${box!.cartonWeight.toStringAsFixed(2)} lb", + "${box.cartonWeight?.toStringAsFixed(2)} lb", style: new TextStyle(fontSize: 15.0, color: Colors.grey), ), diff --git a/lib/pages/carton/carton_mix_table.dart b/lib/pages/carton/carton_mix_table.dart index 5187c2e..6d2cee4 100644 --- a/lib/pages/carton/carton_mix_table.dart +++ b/lib/pages/carton/carton_mix_table.dart @@ -35,7 +35,7 @@ class CartonMixTable extends StatelessWidget { ? [Container()] : cartons!.asMap().entries.map((p) { return Container( - color: p.value.isChecked + color: (p.value.isChecked ?? false) ? Colors.grey.withOpacity(0.2) : Colors.grey.shade50.withOpacity(0.2), child: Container( @@ -60,7 +60,7 @@ class CartonMixTable extends StatelessWidget { }), Expanded( child: new Text( - p.value.cartonNumber, + p.value.cartonNumber ?? "", style: textStyle, )), new Text( diff --git a/lib/pages/carton/carton_package_table.dart b/lib/pages/carton/carton_package_table.dart index 0735472..7850efa 100644 --- a/lib/pages/carton/carton_package_table.dart +++ b/lib/pages/carton/carton_package_table.dart @@ -70,15 +70,15 @@ class CartonPackageTable extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - p.value.trackingID, + p.value.trackingID ?? "", style: textStyle, ), Text( - p.value.deliveryAddress.fullName, + p.value.deliveryAddress?.fullName ?? "", style: textStyle, ), Text( - p.value.deliveryAddress.phoneNumber, + p.value.deliveryAddress?.phoneNumber ?? "", style: textStyle, ), ], @@ -88,7 +88,7 @@ class CartonPackageTable extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ new Text( - p.value.desc, + p.value.desc ?? "", style: textStyle, ), new Text( diff --git a/lib/pages/carton/carton_row.dart b/lib/pages/carton/carton_row.dart index 131afea..970a3a2 100644 --- a/lib/pages/carton/carton_row.dart +++ b/lib/pages/carton/carton_row.dart @@ -8,9 +8,9 @@ import 'package:intl/intl.dart'; typedef OnRemove(Carton carton); class CartonRow extends StatelessWidget { - final Carton? box; + final Carton box; final OnRemove? onRemove; - CartonRow({Key? key, this.box, this.onRemove}) : super(key: key); + CartonRow({Key? key, required this.box, this.onRemove}) : super(key: key); final double dotSize = 15.0; final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); @@ -45,7 +45,7 @@ class CartonRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - box!.cartonNumber, + box.cartonNumber ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -53,7 +53,7 @@ class CartonRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 10.0, top: 10), child: new Text( - box!.userName, + box.userName ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), @@ -75,16 +75,16 @@ class CartonRow extends StatelessWidget { color: primaryColor, ), onPressed: () { - if (onRemove != null) onRemove!(box!); + if (onRemove != null) onRemove!(box); }), - box!.actualWeight == 0 + box.actualWeight == 0 ? Container() : Padding( padding: const EdgeInsets.only(left: 8.0, bottom: 5), child: Row( children: [ new Text( - "${box!.actualWeight.toStringAsFixed(2)} lb", + "${box.actualWeight.toStringAsFixed(2)} lb", style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), diff --git a/lib/pages/carton/model/carton_model.dart b/lib/pages/carton/model/carton_model.dart index e8694dc..da5a7fb 100644 --- a/lib/pages/carton/model/carton_model.dart +++ b/lib/pages/carton/model/carton_model.dart @@ -12,7 +12,7 @@ import 'package:logging/logging.dart'; class CartonModel extends BaseModel { List _boxes = []; - PaginatorListener? cartonsByFilter; + late PaginatorListener cartonsByFilter; final log = Logger('CartonModel'); List get boxes => _selectedIndex == 1 @@ -24,8 +24,8 @@ class CartonModel extends BaseModel { int _selectedIndexFilter = 1; bool isLoading = false; - StreamSubscription listener; - StreamSubscription cartonListener; + StreamSubscription? listener; + StreamSubscription? cartonListener; static List statusHistory = [ ShipmentStatus(status: "Packed", date: DateTime(2020, 6, 1), done: true), ShipmentStatus(status: "Shipped", date: DateTime(2020, 6, 5), done: false), @@ -101,7 +101,7 @@ class CartonModel extends BaseModel { @override void privilegeChanged() { - if (user != null || !user.hasCarton()) { + if (user != null || !user!.hasCarton()) { _initData(); } } @@ -119,12 +119,12 @@ class CartonModel extends BaseModel { } Future _loadBoxes() async { - if (user == null || !user.hasCarton()) return; + if (user == null || !user!.hasCarton()) return; String path = "/$cartons_collection/"; - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); _boxes = []; try { - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection("$path") .where("status", whereIn: [carton_packed_status, carton_shipped_status]) @@ -133,9 +133,10 @@ class CartonModel extends BaseModel { .snapshots() .listen((QuerySnapshot snapshot) { _boxes.clear(); - _boxes = snapshot.documents.map((documentSnapshot) { + _boxes = snapshot.docs.map((documentSnapshot) { var s = Carton.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data() as Map, + documentSnapshot.id); return s; }).toList(); notifyListeners(); @@ -146,18 +147,18 @@ class CartonModel extends BaseModel { } Future _loadCartonsByFilter(String orderName) async { - if (user == null || !user.hasCarton()) return null; + if (user == null || !user!.hasCarton()) return null; String path = "/$cartons_collection"; try { - Query listenerQuery = Firestore.instance + Query listenerQuery = FirebaseFirestore.instance .collection("$path") .where("carton_type", whereIn: [ carton_from_packages, carton_from_cartons ]).where("status", isEqualTo: carton_packed_status); - Query pageQuery = Firestore.instance + Query pageQuery = FirebaseFirestore.instance .collection("$path") .where("carton_type", whereIn: [carton_from_packages, carton_from_cartons]) @@ -171,10 +172,10 @@ class CartonModel extends BaseModel { } } - Paginator _getDelivered() { - if (user == null || !user.hasCarton()) return null; + Paginator? _getDelivered() { + if (user == null || !user!.hasCarton()) return null; - var pageQuery = Firestore.instance + var pageQuery = FirebaseFirestore.instance .collection("/$cartons_collection") .where("is_delivered", isEqualTo: true) .where("is_deleted", isEqualTo: false); @@ -185,10 +186,10 @@ class CartonModel extends BaseModel { } Future loadMore() async { - if (_delivered.ended || selectedIndex == 1) return; + if (_delivered == null && _delivered!.ended || selectedIndex == 1) return; isLoading = true; notifyListeners(); - await _delivered.load(onFinished: () { + await _delivered!.load(onFinished: () { isLoading = false; notifyListeners(); }); @@ -196,7 +197,7 @@ class CartonModel extends BaseModel { Future refresh() async { if (selectedIndex == 1) return; - await _delivered.refresh(onFinished: () { + await _delivered?.refresh(onFinished: () { notifyListeners(); }); } @@ -207,69 +208,62 @@ class CartonModel extends BaseModel { @override logout() async { - if (listener != null) await listener.cancel(); - if (cartonListener != null) await cartonListener.cancel(); - if (_delivered != null) _delivered.close(); + if (listener != null) await listener!.cancel(); + if (cartonListener != null) await cartonListener!.cancel(); + if (_delivered != null) _delivered!.close(); if (cartonsByFilter != null) cartonsByFilter.close(); _boxes = []; } Future> getCartons(String shipmentID) async { String path = "/$cartons_collection"; - var querySnap = await Firestore.instance + var querySnap = await FirebaseFirestore.instance .collection(path) .where("shipment_id", isEqualTo: shipmentID) - .getDocuments(); - return querySnap.documents - .map((e) => Carton.fromMap(e.data, e.documentID)) - .toList(); + .get(); + return querySnap.docs.map((e) => Carton.fromMap(e.data(), e.id)).toList(); } Future> getCartonsByFcsShipment(String fcsShipmentID) async { String path = "/$cartons_collection"; - var querySnap = await Firestore.instance + var querySnap = await FirebaseFirestore.instance .collection(path) .where("fcs_shipment_id", isEqualTo: fcsShipmentID) .where("is_deleted", isEqualTo: false) - .getDocuments(); - return querySnap.documents - .map((e) => Carton.fromMap(e.data, e.documentID)) - .toList(); + .get(); + return querySnap.docs.map((e) => Carton.fromMap(e.data(), e.id)).toList(); } Future> getCartonsForInvoice( String fcsShipmentID, String userID) async { String path = "/$cartons_collection"; - var querySnap = await Firestore.instance + var querySnap = await FirebaseFirestore.instance .collection(path) .where("fcs_shipment_id", isEqualTo: fcsShipmentID) .where("user_id", isEqualTo: userID) .where("is_deleted", isEqualTo: false) .where("is_invoiced", isEqualTo: false) - .getDocuments(); - List cartons = querySnap.documents - .map((e) => Carton.fromMap(e.data, e.documentID)) - .toList(); + .get(); + List cartons = + querySnap.docs.map((e) => Carton.fromMap(e.data(), e.id)).toList(); return cartons; } Future> getMixCartonsByFcsShipment(String fcsShipmentID) async { String path = "/$cartons_collection"; - var querySnap = await Firestore.instance + var querySnap = await FirebaseFirestore.instance .collection(path) .where("fcs_shipment_id", isEqualTo: fcsShipmentID) .where("carton_type", isEqualTo: carton_mix_box) .where("is_deleted", isEqualTo: false) - .getDocuments(); - return querySnap.documents - .map((e) => Carton.fromMap(e.data, e.documentID)) - .toList(); + .get(); + return querySnap.docs.map((e) => Carton.fromMap(e.data(), e.id)).toList(); } Future getCarton(String id) async { String path = "/$cartons_collection"; - var snap = await Firestore.instance.collection(path).document(id).get(); - return Carton.fromMap(snap.data, snap.documentID); + var snap = await FirebaseFirestore.instance.collection(path).doc(id).get(); + return Carton.fromMap(snap.data() as Map, snap.id); } Future createCarton(Carton carton) { diff --git a/lib/pages/carton/package_carton_editor.dart b/lib/pages/carton/package_carton_editor.dart index 9526e4c..2d52b7d 100644 --- a/lib/pages/carton/package_carton_editor.dart +++ b/lib/pages/carton/package_carton_editor.dart @@ -8,12 +8,9 @@ import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/carton_size/carton_size_list.dart'; import 'package:fcs/pages/carton_size/model/carton_size_model.dart'; -import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart'; import 'package:fcs/pages/main/util.dart'; -import 'package:fcs/pages/rates/model/shipment_rate_model.dart'; import 'package:fcs/pages/widgets/defalut_delivery_address.dart'; import 'package:fcs/pages/widgets/delivery_address_selection.dart'; -import 'package:fcs/pages/widgets/display_text.dart'; import 'package:fcs/pages/widgets/length_picker.dart'; import 'package:fcs/pages/widgets/local_button.dart'; import 'package:fcs/pages/widgets/local_text.dart'; @@ -45,7 +42,7 @@ class _PackageCartonEditorState extends State { Carton? _carton; bool _isLoading = false; - DeliveryAddress _deliveryAddress = new DeliveryAddress(); + DeliveryAddress? _deliveryAddress = new DeliveryAddress(); List _cargoTypes = []; CartonSize? selectedCatonSize; bool isFromPackages = false; @@ -263,7 +260,7 @@ class _PackageCartonEditorState extends State { .map>((CartonSize value) { return DropdownMenuItem( value: value, - child: Text(value.name, + child: Text(value.name ?? "", overflow: TextOverflow.ellipsis, style: TextStyle( color: value.name == MANAGE_CARTONSIZE @@ -354,7 +351,7 @@ class _PackageCartonEditorState extends State { Navigator.pop(context, _c); } else { await cartonModel.updateCarton(carton); - Carton _c = await cartonModel.getCarton(_carton!.id); + Carton _c = await cartonModel.getCarton(_carton!.id!); Navigator.pop(context, _c); } } catch (e) { diff --git a/lib/pages/carton/widgets.dart b/lib/pages/carton/widgets.dart index 3586d5b..c690008 100644 --- a/lib/pages/carton/widgets.dart +++ b/lib/pages/carton/widgets.dart @@ -17,7 +17,7 @@ Widget getCartonNumberStatus(BuildContext context, Carton carton) { ), Padding( padding: const EdgeInsets.only(left: 8.0), - child: Chip(label: Text(carton.status)), + child: Chip(label: Text(carton.status??"")), ), ], ); diff --git a/lib/pages/carton_search/carton_list_row.dart b/lib/pages/carton_search/carton_list_row.dart index d522a03..563084e 100644 --- a/lib/pages/carton_search/carton_list_row.dart +++ b/lib/pages/carton_search/carton_list_row.dart @@ -5,27 +5,15 @@ import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'carton_search.dart'; -class CartonListRow extends StatefulWidget { +class CartonListRow extends StatelessWidget { final CallbackCartonSelect? callbackCartonSelect; - final Carton? carton; + final Carton carton; // const CartonListRow({this.carton, this.callbackCartonSelect}); - CartonListRow( - {Key? key, this.carton, this.callbackCartonSelect}) + CartonListRow({Key? key, required this.carton, this.callbackCartonSelect}) : super(key: key); - @override - _CartonListRowState createState() => _CartonListRowState(); -} - -class _CartonListRowState extends State { final double dotSize = 15.0; - Carton? _carton; - @override - void initState() { - super.initState(); - this._carton = widget.carton; - } @override Widget build(BuildContext context) { @@ -38,8 +26,7 @@ class _CartonListRowState extends State { child: InkWell( onTap: () { Navigator.pop(context); - if (widget.callbackCartonSelect != null) - widget.callbackCartonSelect!(widget.carton!); + if (callbackCartonSelect != null) callbackCartonSelect!(carton); }, child: Row( children: [ @@ -64,7 +51,7 @@ class _CartonListRowState extends State { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - _carton!.cartonNumber, + carton.cartonNumber ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -72,7 +59,7 @@ class _CartonListRowState extends State { Padding( padding: const EdgeInsets.only(left: 10.0, top: 10), child: new Text( - _carton!.userName, + carton.userName ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), @@ -86,7 +73,7 @@ class _CartonListRowState extends State { child: Row( children: [ new Text( - "${_carton!.cartonWeight.toStringAsFixed(2)} lb", + "${carton.cartonWeight?.toStringAsFixed(2)} lb", style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), diff --git a/lib/pages/carton_size/carton_size_editor.dart b/lib/pages/carton_size/carton_size_editor.dart index 6f4f5df..b9a21c1 100644 --- a/lib/pages/carton_size/carton_size_editor.dart +++ b/lib/pages/carton_size/carton_size_editor.dart @@ -36,7 +36,7 @@ class _CartonSizeEditorState extends State { if (widget.cartonSize != null) { _cartonSize = widget.cartonSize; _isNew = false; - _nameController.text = _cartonSize!.name; + _nameController.text = _cartonSize!.name ?? ""; _widthController.text = _cartonSize!.width.toString(); _heightController.text = _cartonSize!.height.toString(); _lengthController.text = _cartonSize!.length.toString(); diff --git a/lib/pages/carton_size/carton_size_list.dart b/lib/pages/carton_size/carton_size_list.dart index 2341edb..e396f11 100644 --- a/lib/pages/carton_size/carton_size_list.dart +++ b/lib/pages/carton_size/carton_size_list.dart @@ -40,7 +40,7 @@ class _CartonSizeListState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ new Text( - p.name, + p.name ?? "", style: TextStyle(fontSize: 15.0), ), Padding( @@ -135,7 +135,7 @@ class _CartonSizeListState extends State { CartonSizeModel cartonSizeModel = Provider.of(context, listen: false); try { - await cartonSizeModel.deleteCartonSize(cartonSize.id); + await cartonSizeModel.deleteCartonSize(cartonSize.id!); } catch (e) { showMsgDialog(context, "Error", e.toString()); } finally { diff --git a/lib/pages/carton_size/model/carton_size_model.dart b/lib/pages/carton_size/model/carton_size_model.dart index d9e9c1b..c104453 100644 --- a/lib/pages/carton_size/model/carton_size_model.dart +++ b/lib/pages/carton_size/model/carton_size_model.dart @@ -13,7 +13,7 @@ class CartonSizeModel extends BaseModel { List cartonSizes = []; final log = Logger('CartonSizeModel'); - StreamSubscription listener; + StreamSubscription? listener; List get getCartonSizes { var _cartonSizes = new List.from(cartonSizes); @@ -27,17 +27,18 @@ class CartonSizeModel extends BaseModel { Future _loadCartonSizes() async { try { - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection( "/$config_collection/$setting_doc_id/$carton_sizes_collection") .snapshots() .listen((QuerySnapshot snapshot) { cartonSizes.clear(); - cartonSizes = snapshot.documents.map((documentSnapshot) { + cartonSizes = snapshot.docs.map((documentSnapshot) { var c = CartonSize.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data() as Map, + documentSnapshot.id); return c; }).toList(); notifyListeners(); @@ -49,7 +50,7 @@ class CartonSizeModel extends BaseModel { @override logout() async { - if (listener != null) await listener.cancel(); + if (listener != null) await listener!.cancel(); cartonSizes = []; } diff --git a/lib/pages/chat/bubble.dart b/lib/pages/chat/bubble.dart index 9a99de3..dabed50 100644 --- a/lib/pages/chat/bubble.dart +++ b/lib/pages/chat/bubble.dart @@ -2,7 +2,6 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/package/package_info.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/widgets/fcs_id_icon.dart'; -import 'package:fcs/pages/widgets/local_text.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; @@ -14,18 +13,18 @@ typedef CallbackOnViewDetail(); class Bubble extends StatelessWidget { Bubble( {this.message, - this.date, - this.delivered, - this.isMine, + required this.date, + required this.delivered, + required this.isMine, this.sender, - this.isSystem, - this.isCustomer, - this.showDate, + required this.isSystem, + required this.isCustomer, + required this.showDate, this.callbackOnViewDetail}); - final CallbackOnViewDetail callbackOnViewDetail; + final CallbackOnViewDetail? callbackOnViewDetail; final DateTime date; - final String message, sender; + final String? message, sender; final bool delivered, isMine, isSystem, isCustomer, showDate; @override @@ -84,7 +83,7 @@ class Bubble extends StatelessWidget { fontWeight: FontWeight.bold))) ] : [ - Text(isCustomer ? "FCS Team" : sender, + Text(isCustomer ? "FCS Team" : sender ?? "", style: TextStyle( color: Colors.black38, fontSize: 10.0, @@ -102,8 +101,8 @@ class Bubble extends StatelessWidget { children: [ Padding( padding: EdgeInsets.only(right: 48.0), - child: Text(message, - style: hasUnicode(message) + child: Text(message ?? "", + style: hasUnicode(message ?? "") ? newLabelStyleMM(color: primaryColor) : newLabelStyle(color: primaryColor))), Positioned( @@ -130,6 +129,6 @@ class Bubble extends StatelessWidget { } _viewDetail() { - if (callbackOnViewDetail != null) callbackOnViewDetail(); + if (callbackOnViewDetail != null) callbackOnViewDetail!(); } } diff --git a/lib/pages/chat/message_detail.dart b/lib/pages/chat/message_detail.dart index c1209e7..d1b7144 100644 --- a/lib/pages/chat/message_detail.dart +++ b/lib/pages/chat/message_detail.dart @@ -21,14 +21,17 @@ import 'package:provider/provider.dart'; import 'bubble.dart'; class MessageDetail extends StatelessWidget { - final String receiverName; - final String receiverID; + final String? receiverName; + final String? receiverID; final MessageModel messageModel; final TextEditingController textEditingController = TextEditingController(); final ScrollController listScrollController = ScrollController(); MessageDetail( - {Key key, this.messageModel, this.receiverName, this.receiverID}) + {Key? key, + required this.messageModel, + this.receiverName, + this.receiverID}) : super(key: key) { listScrollController.addListener(() { if (listScrollController.offset >= @@ -44,7 +47,7 @@ class MessageDetail extends StatelessWidget { @override Widget build(BuildContext context) { - String userID = Provider.of(context).user.id; + String userID = Provider.of(context).user?.id ?? ""; return Scaffold( appBar: AppBar( @@ -96,8 +99,8 @@ class MessageDetail extends StatelessWidget { Widget buildBubble(Message msg, String userID, bool showDate, CallbackOnViewDetail callback) { return Bubble( - message: msg.message, - date: msg.date, + message: msg.message ?? "", + date: msg.date!, delivered: true, sender: msg.senderName, isMine: msg.senderID == userID || msg.receiverID == receiverID, @@ -117,8 +120,8 @@ class MessageDetail extends StatelessWidget { child: Container( child: TextField( onSubmitted: (value) { - Provider.of(context, listen: false) - .sendMessage(textEditingController.text, receiverID); + Provider.of(context, listen: false).sendMessage( + textEditingController.text, receiverID ?? ""); textEditingController.text = ""; }, style: TextStyle(color: primaryColor, fontSize: 15.0), @@ -152,8 +155,8 @@ class MessageDetail extends StatelessWidget { child: IconButton( icon: Icon(Icons.send), onPressed: () { - Provider.of(context, listen: false) - .sendMessage(textEditingController.text, receiverID); + Provider.of(context, listen: false).sendMessage( + textEditingController.text, receiverID ?? ""); textEditingController.text = ""; }, color: primaryColor, @@ -165,7 +168,8 @@ class MessageDetail extends StatelessWidget { ), width: double.infinity, decoration: BoxDecoration( - border: Border(top: BorderSide(color: Colors.grey[700], width: 0.5)), + border: + Border(top: BorderSide(color: Colors.grey.shade700, width: 0.5)), color: Colors.white), ); } @@ -176,7 +180,7 @@ class MessageDetail extends StatelessWidget { message.messageID != "") { PackageModel packageModel = Provider.of(context, listen: false); - Package p = await packageModel.getPackage(message.messageID); + Package p = await packageModel.getPackage(message.messageID!); if (p == null) return; Navigator.push(context, CupertinoPageRoute(builder: (context) => PackageInfo(package: p))); @@ -186,7 +190,7 @@ class MessageDetail extends StatelessWidget { message.messageID != "") { MainModel mainModel = Provider.of(context, listen: false); - if (mainModel.user.isCustomer()) { + if (mainModel.user?.isCustomer() ?? false) { Navigator.push( context, CupertinoPageRoute(builder: (context) => Profile())); } else { @@ -202,7 +206,7 @@ class MessageDetail extends StatelessWidget { message.messageID != "") { ShipmentModel shipmentModel = Provider.of(context, listen: false); - Shipment s = await shipmentModel.getShipment(message.messageID); + Shipment s = await shipmentModel.getShipment(message.messageID!); if (s == null) return; await Navigator.push( context, diff --git a/lib/pages/chat/model/message_model.dart b/lib/pages/chat/model/message_model.dart index e075fd2..64535ef 100644 --- a/lib/pages/chat/model/message_model.dart +++ b/lib/pages/chat/model/message_model.dart @@ -10,45 +10,46 @@ import 'package:logging/logging.dart'; class MessageModel extends BaseModel { final log = Logger('MessageModel'); - List messages; + List messages = []; @override logout() async { - if (listener != null) await listener.cancel(); + if (listener != null) await listener!.cancel(); messages = []; } - Query query; - DocumentSnapshot prevSnap; - bool isEnded; - bool isLoading; - String userID; - StreamSubscription listener; + late Query query; + DocumentSnapshot? prevSnap; + late bool isEnded; + late bool isLoading; + String? userID; + StreamSubscription? listener; static const int rowPerLoad = 20; void initQuery(String? userID) { - if(userID == null)return; + if (userID == null) return; this.messages = []; this.userID = userID; this.prevSnap = null; - query = Firestore.instance + query = FirebaseFirestore.instance .collection("$user_collection/$userID/$messages_collection") .orderBy('date', descending: true); load(); } Future load() async { + if (prevSnap == null) return; Query _query = - prevSnap != null ? query.startAfterDocument(prevSnap) : query; + prevSnap != null ? query.startAfterDocument(prevSnap!) : query; QuerySnapshot snapshot = - await _query.limit(rowPerLoad).getDocuments(source: Source.server); + await _query.limit(rowPerLoad).get(GetOptions(source: Source.server)); - int count = snapshot.documents.length; + int count = snapshot.docs.length; isEnded = count < rowPerLoad; - prevSnap = count > 0 ? snapshot.documents[count - 1] : prevSnap; + prevSnap = count > 0 ? snapshot.docs[count - 1] : prevSnap; - snapshot.documents.forEach((e) { - messages.add(Message.fromMap(e.data, e.documentID)); + snapshot.docs.forEach((e) { + messages.add(Message.fromMap(e.data() as Map, e.id)); if (messages.length == 1) { _initListener(e); } @@ -57,20 +58,22 @@ class MessageModel extends BaseModel { } void _initListener(DocumentSnapshot snap) { - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection("$user_collection/$userID/$messages_collection") .endBeforeDocument(snap) .orderBy('date', descending: true) .snapshots(includeMetadataChanges: true) .listen((qs) { - qs.documentChanges.forEach((c) { + qs.docChanges.forEach((c) { switch (c.type) { case DocumentChangeType.added: log.info("added!! $c"); messages.insert( - 0, Message.fromMap(c.document.data, c.document.documentID)); + 0, + Message.fromMap( + c.doc.data() as Map, c.doc.id)); notifyListeners(); break; case DocumentChangeType.modified: diff --git a/lib/pages/contact/contact_page.dart b/lib/pages/contact/contact_page.dart index 0023a31..f0c1fae 100644 --- a/lib/pages/contact/contact_page.dart +++ b/lib/pages/contact/contact_page.dart @@ -21,7 +21,8 @@ class ContactPage extends StatefulWidget { class _ContactPageState extends State { @override Widget build(BuildContext context) { - Setting setting = Provider.of(context).setting; + Setting? setting = Provider.of(context).setting; + if (setting == null) return Container(); bool isEditable = context.select((MainModel m) => m.contactEditable()); return Scaffold( @@ -61,14 +62,14 @@ class _ContactPageState extends State { children: [ itemTitle(context, "contact.callus"), contactItem(context, setting.usaContactNumber, CupertinoIcons.phone, - onTap: () => _call(setting.usaContactNumber), + onTap: () => _call(setting.usaContactNumber ?? ""), labelKey: "contact.usa.phone"), contactItem( context, setting.mmContactNumber, CupertinoIcons.phone, onTap: () => _call( - setting.mmContactNumber, + setting.mmContactNumber ?? "", ), labelKey: "contact.mm.phone", ), @@ -90,7 +91,7 @@ class _ContactPageState extends State { context, setting.emailAddress, CupertinoIcons.mail, - onTap: () => _email(setting.emailAddress), + onTap: () => _email(setting.emailAddress ?? ""), labelKey: "contact.fcs.email", ), itemTitle(context, "contact.visitus"), @@ -98,7 +99,7 @@ class _ContactPageState extends State { context, setting.facebookLink, FontAwesomeIcons.facebook, - onTap: () => _opencontactItem(setting.facebookLink), + onTap: () => _opencontactItem(setting.facebookLink ?? ""), labelKey: "contact.facebook", ), ], diff --git a/lib/pages/customer/customer_editor.dart b/lib/pages/customer/customer_editor.dart index 3176e32..c85a44f 100644 --- a/lib/pages/customer/customer_editor.dart +++ b/lib/pages/customer/customer_editor.dart @@ -40,7 +40,7 @@ class _CustomerEditorState extends State { )), IconButton( icon: Icon(Icons.open_in_new, color: primaryColor), - onPressed: () => call(context, widget.customer!.phoneNumber)), + onPressed: () => call(context, widget.customer?.phoneNumber ?? "")), ], ); @@ -68,7 +68,7 @@ class _CustomerEditorState extends State { onPressed: () => Navigator.of(context).pop(), ), title: Text( - widget.customer!.name, + widget.customer?.name ?? "", style: TextStyle( fontSize: 20, color: primaryColor, @@ -119,7 +119,7 @@ class _CustomerEditorState extends State { CustomerModel customerModel = Provider.of(context, listen: false); try { - await customerModel.acceptRequest(widget.customer!.id); + await customerModel.acceptRequest(widget.customer?.id ?? ""); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/customer/customer_list.dart b/lib/pages/customer/customer_list.dart index 2f9031a..09c4cba 100644 --- a/lib/pages/customer/customer_list.dart +++ b/lib/pages/customer/customer_list.dart @@ -125,7 +125,7 @@ class _CustomerListState extends State { Padding( padding: const EdgeInsets.only(top: 2.0), child: new Text( - customer.name, + customer.name ?? "", style: new TextStyle( fontSize: 20.0, color: primaryColor), ), @@ -171,7 +171,7 @@ class _CustomerListState extends State { children: [ Padding( padding: const EdgeInsets.only(right: 5), - child: _status(customer.status), + child: _status(customer.status ?? ""), ), Padding( padding: const EdgeInsets.only(right: 5), @@ -222,17 +222,17 @@ class _CustomerListState extends State { ))) .then((value) { if (customer.fcsUnseenCount > 0) { - messageModel.seenMessages(customer.id, false); + messageModel.seenMessages(customer.id ?? "", false); } }); if (customer.fcsUnseenCount > 0) { - messageModel.seenMessages(customer.id, false); + messageModel.seenMessages(customer.id ?? "", false); } } _share(User user) async { MainModel mainModel = Provider.of(context, listen: false); - String appUrl = mainModel.setting.appUrl; + String appUrl = mainModel.setting?.appUrl ?? ""; final RenderBox? box = context.findRenderObject() as RenderBox; await Share.share( "Join us on FCS Logistics App. Here is the link:\n $appUrl\n" + diff --git a/lib/pages/customer/invitation_editor.dart b/lib/pages/customer/invitation_editor.dart index f8b89d6..fe2f946 100644 --- a/lib/pages/customer/invitation_editor.dart +++ b/lib/pages/customer/invitation_editor.dart @@ -37,7 +37,7 @@ class _InvitationEditorState extends State { )), IconButton( icon: Icon(Icons.open_in_new, color: primaryColor), - onPressed: () => call(context, widget.customer!.phoneNumber)), + onPressed: () => call(context, widget.customer?.phoneNumber ?? "")), ], ); @@ -57,7 +57,7 @@ class _InvitationEditorState extends State { onPressed: () => Navigator.of(context).pop(), ), title: Text( - widget.customer!.name, + widget.customer?.name ?? "", style: TextStyle(fontSize: 20, color: primaryColor), ), ), @@ -87,7 +87,7 @@ class _InvitationEditorState extends State { CustomerModel customerModel = Provider.of(context, listen: false); try { - await customerModel.deleteInvite(widget.customer!.phoneNumber); + await customerModel.deleteInvite(widget.customer?.phoneNumber ?? ""); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/customer/model/customer_model.dart b/lib/pages/customer/model/customer_model.dart index ea9525c..a82c24b 100644 --- a/lib/pages/customer/model/customer_model.dart +++ b/lib/pages/customer/model/customer_model.dart @@ -12,8 +12,8 @@ class CustomerModel extends BaseModel { List customers = []; List invitations = []; - late StreamSubscription customerListener; - late StreamSubscription invitationListener; + late StreamSubscription? customerListener; + late StreamSubscription? invitationListener; @override void privilegeChanged() { @@ -24,8 +24,8 @@ class CustomerModel extends BaseModel { @override logout() async { - if (customerListener != null) customerListener.cancel(); - if (invitationListener != null) invitationListener.cancel(); + if (customerListener != null) customerListener!.cancel(); + if (invitationListener != null) invitationListener!.cancel(); customers = []; invitations = []; } @@ -43,21 +43,22 @@ class CustomerModel extends BaseModel { } Future _loadCustomer() async { - if (user == null || !user.hasCustomers()) return; + if (user == null && !user!.hasCustomers()) return; try { - if (customerListener != null) customerListener.cancel(); + if (customerListener != null) customerListener!.cancel(); - customerListener = Firestore.instance + customerListener = FirebaseFirestore.instance .collection("/$user_collection") .where("is_sys_admin", isEqualTo: false) .orderBy("message_time", descending: true) .snapshots() .listen((QuerySnapshot snapshot) { customers.clear(); - customers = snapshot.documents.map((documentSnapshot) { - var user = - User.fromMap(documentSnapshot.data, documentSnapshot.documentID); + customers = snapshot.docs.map((documentSnapshot) { + var user = User.fromMap( + documentSnapshot.data() as Map, + documentSnapshot.id); return user; }).toList(); notifyListeners(); @@ -68,19 +69,20 @@ class CustomerModel extends BaseModel { } Future _loadInvitations() async { - if (user == null || !user.hasCustomers()) return; + if (user == null && !user!.hasCustomers()) return; try { - if (invitationListener != null) invitationListener.cancel(); + if (invitationListener != null) invitationListener!.cancel(); - invitationListener = Firestore.instance + invitationListener = FirebaseFirestore.instance .collection("/$invitations_collection") .snapshots() .listen((QuerySnapshot snapshot) { invitations.clear(); - invitations = snapshot.documents.map((documentSnapshot) { - var user = - User.fromMap(documentSnapshot.data, documentSnapshot.documentID); + invitations = snapshot.docs.map((documentSnapshot) { + var user = User.fromMap( + documentSnapshot.data() as Map, + documentSnapshot.id); return user; }).toList(); notifyListeners(); @@ -92,21 +94,20 @@ class CustomerModel extends BaseModel { Future getUser(String? id) async { String path = "/$user_collection"; - var snap = await Firestore.instance.collection(path).document(id).get(); - return User.fromMap(snap.data, snap.documentID); + var snap = await FirebaseFirestore.instance.collection(path).doc(id).get(); + return User.fromMap(snap.data() as Map, snap.id); } Future> getInvoiceUsers(String fcsShipmentID) async { List users = []; try { - var snaps = await Firestore.instance + var snaps = await FirebaseFirestore.instance .collection( "/$fcs_shipment_collection/$fcsShipmentID/$user_collection") .where("pending_invoice_carton_count", isGreaterThan: 0) - .getDocuments(source: Source.server); - users = snaps.documents.map((documentSnapshot) { - var user = - User.fromMap(documentSnapshot.data, documentSnapshot.documentID); + .get(GetOptions(source: Source.server)); + users = snaps.docs.map((documentSnapshot) { + var user = User.fromMap(documentSnapshot.data(), documentSnapshot.id); return user; }).toList(); } catch (e) { @@ -116,6 +117,6 @@ class CustomerModel extends BaseModel { } Future enableUser(User user, bool enabled) { - return Services.instance.userService.enableUser(user.id, enabled); + return Services.instance.userService.enableUser(user.id ?? "", enabled); } } diff --git a/lib/pages/main/home_page.dart b/lib/pages/main/home_page.dart index abd2f86..1f81ac0 100644 --- a/lib/pages/main/home_page.dart +++ b/lib/pages/main/home_page.dart @@ -151,7 +151,7 @@ class _HomePageState extends State { new AndroidInitializationSettings('@mipmap/ic_launcher'); var initializationSettingsIOS = new IOSInitializationSettings(); var initializationSettings = new InitializationSettings( - initializationSettingsAndroid, initializationSettingsIOS); + android: initializationSettingsAndroid, iOS: initializationSettingsIOS); _flutterLocalNotificationsPlugin.initialize(initializationSettings); } @@ -179,13 +179,15 @@ class _HomePageState extends State { 'your channel id', 'your channel name', 'your channel description', playSound: true, enableVibration: true, - importance: Importance.Max, - priority: Priority.High); + importance: Importance.max, + priority: Priority.high); + // @formatter:on var platformChannelSpecificsIos = new IOSNotificationDetails(presentSound: true); var platformChannelSpecifics = new NotificationDetails( - platformChannelSpecificsAndroid, platformChannelSpecificsIos); + android: platformChannelSpecificsAndroid, + iOS: platformChannelSpecificsIos); new Future.delayed(Duration.zero, () { _flutterLocalNotificationsPlugin.show( diff --git a/lib/pages/rates/cargo_editor.dart b/lib/pages/rates/cargo_editor.dart index 30224bf..2c25d86 100644 --- a/lib/pages/rates/cargo_editor.dart +++ b/lib/pages/rates/cargo_editor.dart @@ -31,7 +31,7 @@ class _CargoEditorState extends State { super.initState(); if (widget.cargo != null) { _cargo = widget.cargo!; - _descController.text = _cargo.name; + _descController.text = _cargo.name ?? ""; _rateController.text = _cargo.rate.toStringAsFixed(2); } else { _isNew = true; @@ -138,7 +138,7 @@ class _CargoEditorState extends State { try { var shipmentRateModel = Provider.of(context, listen: false); - await shipmentRateModel.deleteCargoType(this._cargo.id); + 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..0fab20a 100644 --- a/lib/pages/rates/cargo_type_list.dart +++ b/lib/pages/rates/cargo_type_list.dart @@ -75,7 +75,7 @@ class _CargoTypeListState extends State { ))); }, child: Container( - child: _row(cargo.name, + 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..bec5ddb 100644 --- a/lib/pages/rates/custom_editor.dart +++ b/lib/pages/rates/custom_editor.dart @@ -33,7 +33,7 @@ class _CustomEditorState extends State { super.initState(); if (widget.custom != null) { _custom = widget.custom!; - _productController.text = _custom.name; + _productController.text = _custom.name??""; _feeController.text = _custom.customDutyFee.toStringAsFixed(2); _shipmentRateController.text = _custom.rate == null ? "" : _custom.rate.toStringAsFixed(2); @@ -154,7 +154,7 @@ class _CustomEditorState extends State { try { var shipmentRateModel = Provider.of(context, listen: false); - await shipmentRateModel.deleteCustomDuty(this._custom.id); + 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..5657815 100644 --- a/lib/pages/rates/custom_list.dart +++ b/lib/pages/rates/custom_list.dart @@ -81,7 +81,7 @@ class _CustomListState extends State { }, child: Container( child: _row( - custom.name, + custom.name??"", "Custom Fee \$ " + custom.customDutyFee.toStringAsFixed(2), custom.rate == null ? "" diff --git a/lib/pages/rates/custom_row.dart b/lib/pages/rates/custom_row.dart index ae14714..359c1b8 100644 --- a/lib/pages/rates/custom_row.dart +++ b/lib/pages/rates/custom_row.dart @@ -1,9 +1,9 @@ import 'package:fcs/domain/entities/custom_duty.dart'; -import 'package:fcs/domain/vo/delivery_address.dart'; 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_icons_null_safety/flutter_icons_null_safety.dart'; typedef SelectionCallback(CustomDuty custom); diff --git a/lib/pages/rates/discount_by_weight_editor.dart b/lib/pages/rates/discount_by_weight_editor.dart index 7227298..11096fd 100644 --- a/lib/pages/rates/discount_by_weight_editor.dart +++ b/lib/pages/rates/discount_by_weight_editor.dart @@ -143,7 +143,7 @@ class _DiscountByWeightEditorState extends State { var shipmentRateModel = Provider.of(context, listen: false); await shipmentRateModel - .deleteDiscountByWeight(this._discountByWeight.id); + .deleteDiscountByWeight(this._discountByWeight.id!); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/rates/model/shipment_rate_model.dart b/lib/pages/rates/model/shipment_rate_model.dart index 4304dc1..83ba871 100644 --- a/lib/pages/rates/model/shipment_rate_model.dart +++ b/lib/pages/rates/model/shipment_rate_model.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'package:fcs/data/services/services.dart'; 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/pages/main/model/base_model.dart'; @@ -11,12 +10,12 @@ import 'package:logging/logging.dart'; class ShipmentRateModel extends BaseModel { final log = Logger('ShipmentRateModel'); - StreamSubscription listener; - Rate rate; + StreamSubscription? listener; + late Rate rate; void initUser(user) { super.initUser(user); - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); listener = Services.instance.rateService.getRateStream().listen((rate) { this.rate = rate; notifyListeners(); @@ -25,7 +24,7 @@ class ShipmentRateModel extends BaseModel { @override logout() async { - if (listener != null) await listener.cancel(); + if (listener != null) await listener!.cancel(); } // Rate @@ -51,12 +50,12 @@ class ShipmentRateModel extends BaseModel { //CustomDuty Future addCustomDuty(CargoType customDuty) { - customDuty.isCutomDuty=true; + customDuty.isCutomDuty = true; return Services.instance.rateService.createCargoType(customDuty); } Future updateCustomDuty(CargoType customDuty) { - customDuty.isCutomDuty=true; + customDuty.isCutomDuty = true; return Services.instance.rateService.updateCargoType(customDuty); } diff --git a/lib/pages/rates/shipment_rates.dart b/lib/pages/rates/shipment_rates.dart index ff4d865..1613d70 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'; @@ -185,8 +184,8 @@ class _ShipmentRatesState extends State { List getCargoWidget(List cargos) { return cargos.map((cargo) { return Container( - child: _row( - cargo.name, "\$ " + cargo.rate.toStringAsFixed(2), 'per pound'), + child: _row(cargo.name ?? "", "\$ " + cargo.rate.toStringAsFixed(2), + 'per pound'), ); }).toList(); } @@ -194,7 +193,8 @@ 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..c722c86 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_icons_null_safety/flutter_icons_null_safety.dart'; import 'package:provider/provider.dart'; class ShipmentRatesCal extends StatefulWidget { diff --git a/lib/pages/rates/shipment_rates_edit.dart b/lib/pages/rates/shipment_rates_edit.dart index 15149ba..c5590c3 100644 --- a/lib/pages/rates/shipment_rates_edit.dart +++ b/lib/pages/rates/shipment_rates_edit.dart @@ -35,12 +35,11 @@ class _ShipmentRatesEditState extends State { Provider.of(context, listen: false); rate = shipmentRateModel.rate; - _minWeight.text = rate.freeDeliveryWeight?.toStringAsFixed(2) ?? ""; - _deliveryFee.text = rate.deliveryFee?.toStringAsFixed(2) ?? ""; - _volumetricRatio.text = rate.volumetricRatio?.toStringAsFixed(2) ?? ""; - _diffDiscountWeight.text = - rate.diffDiscountWeight?.toStringAsFixed(2) ?? ""; - _diffWeightRate.text = rate.diffWeightRate?.toStringAsFixed(2) ?? ""; + _minWeight.text = rate.freeDeliveryWeight.toStringAsFixed(2); + _deliveryFee.text = rate.deliveryFee.toStringAsFixed(2); + _volumetricRatio.text = rate.volumetricRatio.toStringAsFixed(2); + _diffDiscountWeight.text = rate.diffDiscountWeight.toStringAsFixed(2); + _diffWeightRate.text = rate.diffWeightRate.toStringAsFixed(2); } @override diff --git a/lib/pages/signin/signin_logic.dart b/lib/pages/signin/signin_logic.dart index bdde97a..b0d788e 100644 --- a/lib/pages/signin/signin_logic.dart +++ b/lib/pages/signin/signin_logic.dart @@ -3,21 +3,20 @@ import 'package:fcs/domain/entities/user.dart'; import 'package:fcs/pages/main/model/main_model.dart'; import 'package:fcs/pages/signin/invitation_request_page.dart'; import 'package:fcs/pages/signin/signup_page.dart'; -import 'package:fcs/pages/widgets/bottom_up_page_route.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart'; import 'package:provider/provider.dart'; navigateAfterAuthVerified(BuildContext context) async { - User user = Provider.of(context, listen: false).user; - Setting setting = Provider.of(context, listen: false).setting; + User? user = Provider.of(context, listen: false).user; + Setting? setting = Provider.of(context, listen: false).setting; if (setting == null) return; if (user != null && (user.joined || user.requested)) { Navigator.pushNamedAndRemoveUntil(context, "/home", (r) => false); } else { - if (setting.inviteRequired) { + if (setting.inviteRequired ?? false) { bool invited = await Provider.of(context, listen: false).hasInvite(); if (!invited) { diff --git a/lib/pages/signin/signin_page.dart b/lib/pages/signin/signin_page.dart index 8938d3b..6eaeca8 100644 --- a/lib/pages/signin/signin_page.dart +++ b/lib/pages/signin/signin_page.dart @@ -181,7 +181,7 @@ class _SigninPageState extends State { await navigateAfterAuthVerified(context); } if (auth.authStatus == AuthStatus.ERROR) { - showMsgDialog(context, "Error", auth.authErrorMsg); + showMsgDialog(context, "Error", auth.authErrorMsg ?? ""); } } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/user_search/user_list_row.dart b/lib/pages/user_search/user_list_row.dart index da8822f..d7758c7 100644 --- a/lib/pages/user_search/user_list_row.dart +++ b/lib/pages/user_search/user_list_row.dart @@ -3,23 +3,12 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/user_search/user_serach.dart'; import 'package:flutter/material.dart'; -class UserListRow extends StatefulWidget { - final OnUserRowSelect onUserRowSelect; +class UserListRow extends StatelessWidget { + final OnUserRowSelect? onUserRowSelect; final User user; - const UserListRow({this.user, this.onUserRowSelect}); + const UserListRow({required this.user, this.onUserRowSelect}); - @override - _UserListRowState createState() => _UserListRowState(); -} - -class _UserListRowState extends State { final double dotSize = 15.0; - User user; - @override - void initState() { - super.initState(); - this.user = widget.user; - } @override Widget build(BuildContext context) { @@ -30,8 +19,7 @@ class _UserListRowState extends State { color: Colors.white, child: InkWell( onTap: () { - if (widget.onUserRowSelect != null) - widget.onUserRowSelect(widget.user); + if (onUserRowSelect != null) onUserRowSelect!(user); }, child: Row( children: [ @@ -53,17 +41,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/lib/pages/user_search/user_serach.dart b/lib/pages/user_search/user_serach.dart index 0225b62..6dc22e6 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: @@ -20,7 +20,7 @@ class UserSearchDelegate extends SearchDelegate { final OnUserSelect onUserSelect; final bool popPage; - UserSearchDelegate({this.onUserSelect, this.popPage}); + UserSearchDelegate({required 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, new 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 == null || 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), diff --git a/lib/pages/widgets/banner.dart b/lib/pages/widgets/banner.dart index 0b36a16..ef37127 100644 --- a/lib/pages/widgets/banner.dart +++ b/lib/pages/widgets/banner.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; class FlavorBanner extends StatelessWidget { final Widget child; - FlavorBanner({@required this.child}); + FlavorBanner({required this.child}); @override Widget build(BuildContext context) { diff --git a/lib/pages/widgets/barcode_scanner.dart b/lib/pages/widgets/barcode_scanner.dart index 2706a21..a8124b8 100644 --- a/lib/pages/widgets/barcode_scanner.dart +++ b/lib/pages/widgets/barcode_scanner.dart @@ -1,9 +1,9 @@ -import 'package:barcode_scan/barcode_scan.dart'; +import 'package:barcode_scan2/platform_wrapper.dart'; -Future scanBarcode() async { +Future scanBarcode() async { try { - String barcode = await BarcodeScanner.scan(); - if (barcode == null) return null; + var scanResult = await BarcodeScanner.scan(); + String barcode = scanResult.rawContent; String gs = String.fromCharCode(29); if (barcode.contains(gs)) { diff --git a/lib/pages/widgets/bottom_widgets.dart b/lib/pages/widgets/bottom_widgets.dart index 467630c..067a134 100644 --- a/lib/pages/widgets/bottom_widgets.dart +++ b/lib/pages/widgets/bottom_widgets.dart @@ -13,7 +13,7 @@ class BottomWidgets extends StatelessWidget { Widget build(BuildContext context) { var pkgInfo = Provider.of(context).packageInfo; final versionBox = Text( - "v${pkgInfo.version}+${pkgInfo.buildNumber}", + "v${pkgInfo?.version}+${pkgInfo?.buildNumber}", style: TextStyle(color: Colors.white30), ); return Column( From a47f73a9b02ac1ae3fa9f920688bbb0bc03e0b60 Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 10 Sep 2021 16:34:32 +0630 Subject: [PATCH 2/3] check null safety --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 557e00e..34b8173 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -46,7 +46,7 @@ dependencies: flutter_icons_null_safety: ^1.1.0 country_icons: ^2.0.2 timeline_list: ^0.0.5 - # barcode_scan: ^2.0.2 + barcode_scan2: ^4.1.3 barcode_scan2: ^4.1.4 flutter_pdfview: ^1.2.1 flutter_local_notifications: ^8.2.0 From 3dde95f23f9991089dee6c4b939d0cbad4f1629d Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 10 Sep 2021 16:48:24 +0630 Subject: [PATCH 3/3] check image for null safety --- lib/pages/widgets/display_image_source.dart | 19 +++++++++++----- lib/pages/widgets/image_file_picker.dart | 4 ++-- lib/pages/widgets/img_picker.dart | 25 +++++++++++---------- lib/pages/widgets/length_picker.dart | 10 +++++---- lib/pages/widgets/multi_img_controller.dart | 14 ++++++------ 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/lib/pages/widgets/display_image_source.dart b/lib/pages/widgets/display_image_source.dart index 009cde5..b60ad53 100644 --- a/lib/pages/widgets/display_image_source.dart +++ b/lib/pages/widgets/display_image_source.dart @@ -8,17 +8,26 @@ class DisplayImageSource { File? file; DisplayImageSource({this.url, this.file}); - ImageProvider? get imageProvider => - file == null ? CachedNetworkImageProvider(url!) : FileImage(file!); + ImageProvider get imageProvider { + if (file == null) { + return CachedNetworkImageProvider(url!); + } else { + return FileImage(file!); + } + } @override bool operator ==(other) { - if (identical(this, other)) { + if (identical(this, other) && other is DisplayImageSource) { return true; } - return (other.file == this.file && + + return (other is DisplayImageSource && + other.file == this.file && (other.file != null || this.file != null)) || - (other.url == this.url && (other.url != null || this.url != null)); + (other is DisplayImageSource && + other.url == this.url && + (other.url != null || this.url != null)); } @override diff --git a/lib/pages/widgets/image_file_picker.dart b/lib/pages/widgets/image_file_picker.dart index 50dcc98..a495e97 100644 --- a/lib/pages/widgets/image_file_picker.dart +++ b/lib/pages/widgets/image_file_picker.dart @@ -7,7 +7,7 @@ import 'local_text.dart'; typedef OnFile = void Function(File); -modelBottomSheet(BuildContext context, {final OnFile onFile}) { +modelBottomSheet(BuildContext context, {final OnFile? onFile}) { showModalBottomSheet( elevation: 10, backgroundColor: Colors.white, @@ -84,7 +84,7 @@ class _ImageFileState extends State { } pickImage(ImageSource source) async { - var tempImage = await ImagePicker.pickImage(source: source); + var tempImage = await ImagePicker().pickImage(source: source); return tempImage; } } diff --git a/lib/pages/widgets/img_picker.dart b/lib/pages/widgets/img_picker.dart index 71fc9c2..43e2fb1 100644 --- a/lib/pages/widgets/img_picker.dart +++ b/lib/pages/widgets/img_picker.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:fcs/helpers/theme.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -7,19 +8,19 @@ import 'package:image_picker/image_picker.dart'; import 'show_img.dart'; -typedef OnFile = void Function(File); +typedef OnFile = void Function(File?); class LocalImagePicker extends StatefulWidget { - final Color color; + final Color? color; final String title; - final OnFile onFile; + final OnFile? onFile; final bool enabled; - final String initialImgUrl; + final String? initialImgUrl; final ImageSource imageSource; const LocalImagePicker( - {Key key, - this.title, + {Key? key, + required this.title, this.onFile, this.enabled = true, this.initialImgUrl, @@ -31,8 +32,8 @@ class LocalImagePicker extends StatefulWidget { } class _LocalImagePickerState extends State { - String url; - File file; + String? url; + File? file; @override void initState() { @@ -56,16 +57,16 @@ class _LocalImagePickerState extends State { await _dialog( context, () => camera = true, () => gallery = true); if (camera || gallery) { - var selectedFile = await ImagePicker.pickImage( + var selectedFile = await ImagePicker().pickImage( source: camera ? ImageSource.camera : ImageSource.gallery, imageQuality: 80, maxWidth: 1000); if (selectedFile != null) { setState(() { - this.file = selectedFile; + this.file = File(selectedFile.path); }); if (widget.onFile != null) { - widget.onFile(selectedFile); + widget.onFile!(File(selectedFile.path)); } } } @@ -93,7 +94,7 @@ class _LocalImagePickerState extends State { this.file = null; this.url = null; if (widget.onFile != null) { - widget.onFile(null); + widget.onFile!(null); } }); }, diff --git a/lib/pages/widgets/length_picker.dart b/lib/pages/widgets/length_picker.dart index f39ba00..79bbd81 100644 --- a/lib/pages/widgets/length_picker.dart +++ b/lib/pages/widgets/length_picker.dart @@ -144,7 +144,8 @@ class _LengthPickerDialogState extends State { borderSide: BorderSide(color: primaryColor, width: 1.0), ), enabledBorder: OutlineInputBorder( - borderSide: BorderSide(color: Colors.grey.shade400, width: 1.0), + borderSide: + BorderSide(color: Colors.grey.shade400, width: 1.0), ), ), ), @@ -196,7 +197,8 @@ class _LengthPickerDialogState extends State { borderSide: BorderSide(color: primaryColor, width: 1.0), ), enabledBorder: OutlineInputBorder( - borderSide: BorderSide(color: Colors.grey.shade400, width: 1.0), + borderSide: + BorderSide(color: Colors.grey.shade400, width: 1.0), ), ), ), @@ -273,7 +275,7 @@ class _LengthPickerDialogState extends State { min: 0, max: MAX_FEET, divisions: 100, - label: (_valueFeet ?? 0).round().toString(), + label: _valueFeet.round().toString(), onChanged: (double v) { _updateFeet(v); }, @@ -301,7 +303,7 @@ class _LengthPickerDialogState extends State { min: 0, max: widget.displayFeet! ? 11 : MAX_INC, divisions: 100, - label: (_valueInc ?? 0).round().toString(), + label: _valueInc.round().toString(), onChanged: (double v) { _updateInc(v); }, diff --git a/lib/pages/widgets/multi_img_controller.dart b/lib/pages/widgets/multi_img_controller.dart index 794796a..ad0be39 100644 --- a/lib/pages/widgets/multi_img_controller.dart +++ b/lib/pages/widgets/multi_img_controller.dart @@ -5,12 +5,12 @@ import 'display_image_source.dart'; class MultiImgController { List imageUrls = []; - List imageFiles = []; + List imageFiles = []; List addedFiles = []; List removedFiles = []; List fileContainers = []; - CallBack callback; + CallBack? callback; MultiImgController() { fileContainers = []; } @@ -26,7 +26,7 @@ class MultiImgController { fileContainers.add(DisplayImageSource(url: e)); }); if (callback != null) { - callback(); + callback!(); } } @@ -42,7 +42,7 @@ class MultiImgController { fileContainers.add(DisplayImageSource(file: e)); }); if (callback != null) { - callback(); + callback!(); } } @@ -54,7 +54,7 @@ class MultiImgController { // if (fileContainers.contains(fileContainer)) return; addedFiles.add(fileContainer); if (callback != null) { - callback(); + callback!(); } } @@ -74,11 +74,11 @@ class MultiImgController { } if (callback != null) { - callback(); + callback!(); } } - List get getUpdatedFile { + List get getUpdatedFile { List _addfiles = getAddedFile; this.imageFiles.addAll(_addfiles); return this.imageFiles;