diff --git a/lib/domain/entities/cargo_type.dart b/lib/domain/entities/cargo_type.dart index 68ec494..e66fce0 100644 --- a/lib/domain/entities/cargo_type.dart +++ b/lib/domain/entities/cargo_type.dart @@ -1,17 +1,17 @@ class CargoType { - String id; - String name; - double rate; - double weight; - bool isChecked; - int qty; - bool isCutomDuty; - double customDutyFee; + String? id; + String? name; + double? rate; + double? weight; + bool? isChecked; + int? qty; + bool? isCutomDuty; + double? customDutyFee; double get calAmount => (calRate ?? 0) * (calWeight ?? 0); - double calRate; - double calWeight; + double? calRate; + double? calWeight; CargoType( {this.id, this.name, @@ -52,7 +52,7 @@ class CargoType { } CargoType clone() { - return CargoType.fromMap(toMap(), this.id); + return CargoType.fromMap(toMap(), this.id!); } @override @@ -63,7 +63,7 @@ class CargoType { @override String toString() { - return name; + return name!; } bool isChangedForEdit(CargoType cargoType) { diff --git a/lib/pages/buying_instruction/buying_online.dart b/lib/pages/buying_instruction/buying_online.dart index fc7efce..44d3436 100644 --- a/lib/pages/buying_instruction/buying_online.dart +++ b/lib/pages/buying_instruction/buying_online.dart @@ -15,7 +15,7 @@ class BuyingOnlinePage extends StatefulWidget { class _BuyingOnlinePagetate extends State with SingleTickerProviderStateMixin { - TabController _tabController; + late TabController _tabController; @override void initState() { diff --git a/lib/pages/carton/cargo_table.dart b/lib/pages/carton/cargo_table.dart index 1abdf9c..9e85b0f 100644 --- a/lib/pages/carton/cargo_table.dart +++ b/lib/pages/carton/cargo_table.dart @@ -6,10 +6,10 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class CargoTable extends StatefulWidget { - final List cargoTypes; + final List? cargoTypes; const CargoTable({ - Key key, + Key? key, this.cargoTypes, }) : super(key: key); @@ -58,13 +58,13 @@ class _CargoTableState extends State { return []; } double total = 0; - var rows = widget.cargoTypes.map((c) { - total += c.weight; + var rows = widget.cargoTypes!.map((c) { + total += c.weight!; return MyDataRow( onSelectChanged: (bool selected) async {}, cells: [ MyDataCell(new Text( - c.name == null ? "" : c.name, + c.name ?? "", style: textStyle, )), MyDataCell(c.qty == null || c.qty == 0 @@ -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 9cf3e11..c60fa0d 100644 --- a/lib/pages/carton/cargo_type_addtion.dart +++ b/lib/pages/carton/cargo_type_addtion.dart @@ -35,7 +35,7 @@ class _CargoTypeAdditionState extends State { p.isChecked = false; p.isCutomDuty = false; p.weight = 0; - p.qty = null; + p.qty = 0; }); specialCargos.forEach((p) { p.isChecked = false; @@ -61,7 +61,7 @@ class _CargoTypeAdditionState extends State { child: InkWell( onTap: () { setState(() { - c.isChecked = !c.isChecked; + c.isChecked = !c.isChecked!; }); }, child: Row( @@ -69,12 +69,12 @@ class _CargoTypeAdditionState extends State { Checkbox( value: c.isChecked, activeColor: primaryColor, - onChanged: (bool check) { + onChanged: (bool? check) { setState(() { c.isChecked = check; }); }), - new Text(c.name, style: textStyle), + 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 fb6376b..a4eac59 100644 --- a/lib/pages/carton/cargo_type_editor.dart +++ b/lib/pages/carton/cargo_type_editor.dart @@ -12,7 +12,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; class CargoTypeEditor extends StatefulWidget { - final CargoType cargo; + final CargoType? cargo; CargoTypeEditor({this.cargo}); @override @@ -23,14 +23,14 @@ class _CargoTypeEditorState extends State { TextEditingController _weightController = new TextEditingController(); bool _isLoading = false; - CargoType _cargo; + CargoType? _cargo; @override void initState() { super.initState(); if (widget.cargo != null) { _cargo = widget.cargo; - _weightController.text = _cargo.weight.toStringAsFixed(2); + _weightController.text = _cargo!.weight!.toStringAsFixed(2); } else { _loadDefalut(); } @@ -67,7 +67,7 @@ class _CargoTypeEditorState extends State { }, labelKey: "cargo.type", iconData: Icons.text_format, - selectedValue: _cargo, + selectedValue: _cargo!, values: cargos, ); @@ -75,7 +75,7 @@ class _CargoTypeEditorState extends State { context, getLocalString(context, 'box.cargo.save.btn'), callack: () { - _cargo.weight = double.tryParse(_weightController.text) ?? 0; + _cargo!.weight = double.tryParse(_weightController.text) ?? 0; Navigator.pop(context, _cargo); }, ); diff --git a/lib/pages/carton/carton_cargo_table.dart b/lib/pages/carton/carton_cargo_table.dart index d67eda5..6b2c16f 100644 --- a/lib/pages/carton/carton_cargo_table.dart +++ b/lib/pages/carton/carton_cargo_table.dart @@ -11,13 +11,13 @@ typedef OnRemove(CargoType cargoType); typedef OnUpdate(CargoType cargoType); class CargoTable extends StatefulWidget { - final List cargoTypes; - final bool isNew; - final OnRemove onRemove; - final OnUpdate onUpdate; + final List? cargoTypes; + final bool? isNew; + final OnRemove? onRemove; + final OnUpdate? onUpdate; const CargoTable( - {Key key, this.cargoTypes, this.isNew, this.onRemove, this.onUpdate}) + {Key? key, this.cargoTypes, this.isNew, this.onRemove, this.onUpdate}) : super(key: key); @override @@ -26,14 +26,14 @@ class CargoTable extends StatefulWidget { class _CargoTableState extends State { double totalWeight = 0; - List cargoTypes; + List? cargoTypes; @override void initState() { cargoTypes = widget.cargoTypes; - if (!widget.isNew) { + if (!widget.isNew!) { totalWeight = - cargoTypes.fold(0, (previous, current) => previous + current.weight); + cargoTypes!.fold(0, (previous, current) => previous + current.weight!); } super.initState(); @@ -41,7 +41,7 @@ class _CargoTableState extends State { @override Widget build(BuildContext context) { - print("Cargotypes:${cargoTypes.length}"); + print("Cargotypes:${cargoTypes!.length}"); return SingleChildScrollView( scrollDirection: Axis.horizontal, @@ -80,18 +80,18 @@ class _CargoTableState extends State { if (cargoTypes == null) { return []; } - var rows = cargoTypes.map((c) { + var rows = cargoTypes!.map((c) { return MyDataRow( onSelectChanged: (bool selected) async {}, cells: [ MyDataCell( new Text( - c.name == null ? "" : c.name, + c.name ??'', style: textStyle, ), ), MyDataCell( - c.isCutomDuty + c.isCutomDuty! ? GestureDetector( onTap: () async { String _t = await showDialog( @@ -103,7 +103,7 @@ class _CargoTableState extends State { setState(() { c.qty = int.tryParse(_t) ?? 0; }); - if (widget.onUpdate != null) widget.onUpdate(c); + if (widget.onUpdate != null) widget.onUpdate!(c); }, child: Center( child: Container( @@ -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(() { @@ -153,7 +153,7 @@ class _CargoTableState extends State { if (c.weight != 0) { _cal(); } - if (widget.onUpdate != null) widget.onUpdate(c); + if (widget.onUpdate != null) widget.onUpdate!(c); }, child: Container( padding: const EdgeInsets.all(7.0), @@ -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), ), ), @@ -176,7 +176,7 @@ class _CargoTableState extends State { color: primaryColor, ), onPressed: () { - if (widget.onRemove != null) widget.onRemove(c); + if (widget.onRemove != null) widget.onRemove!(c); }) ], ), @@ -237,21 +237,21 @@ class _CargoTableState extends State { } _cal() { - var cargoType = autoCalWeight(cargoTypes, totalWeight); + var cargoType = autoCalWeight(cargoTypes!, totalWeight); if (cargoType == null) return; setState(() { - cargoTypes.remove(cargoType); - cargoTypes.add(cargoType); + cargoTypes!.remove(cargoType); + cargoTypes!.add(cargoType); }); if (widget.onUpdate != null) { - widget.onUpdate(cargoType); + widget.onUpdate!(cargoType); } } } -CargoType autoCalWeight(List cargoTypes, double total) { +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; diff --git a/lib/pages/carton/carton_cargo_table_old.dart b/lib/pages/carton/carton_cargo_table_old.dart index 8e0d6f9..1b0c840 100644 --- a/lib/pages/carton/carton_cargo_table_old.dart +++ b/lib/pages/carton/carton_cargo_table_old.dart @@ -13,11 +13,11 @@ typedef OnAdd(CargoType cargoType); typedef OnRemove(CargoType cargoType); class CargoTable extends StatefulWidget { - final List cargoTypes; - final OnAdd onAdd; - final OnRemove onRemove; + final List? cargoTypes; + final OnAdd? onAdd; + final OnRemove? onRemove; - const CargoTable({Key key, this.cargoTypes, this.onAdd, this.onRemove}) + const CargoTable({Key? key, this.cargoTypes, this.onAdd, this.onRemove}) : super(key: key); @override @@ -67,15 +67,15 @@ class _CargoTableState extends State { List _types = []; double _total = 0; - var rows = widget.cargoTypes.map((c) { - _total += c.weight; + var rows = widget.cargoTypes!.map((c) { + _total += c.weight!; return MyDataRow( onSelectChanged: (bool selected) async {}, cells: [ MyDataCell(Row( children: [ new Text( - c.name == null ? "" : c.name, + c.name ?? "", style: textStyle, ), new Text( @@ -88,7 +88,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, @@ -99,7 +99,7 @@ class _CargoTableState extends State { color: primaryColor, ), onPressed: () { - if (widget.onRemove != null) widget.onRemove(c); + if (widget.onRemove != null) widget.onRemove!(c); }) ], ), @@ -127,7 +127,7 @@ class _CargoTableState extends State { alignment: Alignment.centerRight, child: InkWell( onTap: () async { - double _t = await Navigator.of(context).push( + double? _t = await Navigator.of(context).push( CupertinoPageRoute( builder: (context) => TotalWeightEdit(totalWeight: totalWeight))); @@ -135,21 +135,21 @@ class _CargoTableState extends State { setState(() { totalWeight = _t; this.remainingWeight = this.totalWeight - _total; - widget.cargoTypes.forEach((c) { + widget.cargoTypes!.forEach((c) { if (c.qty == null) { this._cargos.add(c); } }); this._cargos.forEach((c) { - _list.add(c.name); + _list.add(c.name!); }); - widget.cargoTypes.forEach((c) { - _types.add(c.name); + widget.cargoTypes!.forEach((c) { + _types.add(c.name!); }); - if (this._cargos.length == widget.cargoTypes.length - 1) { + if (this._cargos.length == widget.cargoTypes!.length - 1) { _types.forEach((t) { if (!_list.contains(t)) { - widget.cargoTypes.forEach((c) { + widget.cargoTypes!.forEach((c) { if (c.name == t) { c.weight = this.remainingWeight; } diff --git a/lib/pages/carton/carton_editor.dart b/lib/pages/carton/carton_editor.dart index e366bc3..6281b57 100644 --- a/lib/pages/carton/carton_editor.dart +++ b/lib/pages/carton/carton_editor.dart @@ -29,7 +29,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_icons/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; import 'cargo_type_addtion.dart'; import 'carton_cargo_table.dart'; @@ -40,7 +40,7 @@ import 'package_carton_editor.dart'; import 'widgets.dart'; class CartonEditor extends StatefulWidget { - final Carton box; + final Carton? box; CartonEditor({this.box}); @override @@ -54,29 +54,29 @@ class _CartonEditorState extends State { DeliveryAddress _deliveryAddress = new DeliveryAddress(); List _cargoTypes = []; - Carton _carton; + Carton? _carton; bool _isLoading = false; - bool _isNew; - User _user; - String _selectedCartonType; + bool _isNew = false; + User? _user; + String? _selectedCartonType; double volumetricRatio = 0; double shipmentWeight = 0; - FcsShipment _fcsShipment; - List _fcsShipments; + FcsShipment? _fcsShipment; + List? _fcsShipments; List _cartons = []; - CartonSize selectedCatonSize; + CartonSize? selectedCatonSize; //for mix carton List _mixCartons = []; - String _selectedMixBoxType; + String? _selectedMixBoxType; //for carton from cargos - User consignee; - User sender; + User? consignee; + User? sender; List _cartonsFromCartons = []; - double totalWeight; + double? totalWeight; @override void initState() { @@ -92,28 +92,28 @@ class _CartonEditorState extends State { if (widget.box != null) { _carton = widget.box; - _deliveryAddress = _carton.deliveryAddress; - _widthController.text = _carton.width.toString(); - _heightController.text = _carton.height.toString(); - _lengthController.text = _carton.length.toString(); - _selectedCartonType = _carton.cartonType; + _deliveryAddress = _carton!.deliveryAddress; + _widthController.text = _carton!.width.toString(); + _heightController.text = _carton!.height.toString(); + _lengthController.text = _carton!.length.toString(); + _selectedCartonType = _carton!.cartonType; - _cargoTypes = _carton.cargoTypes.map((e) => e.clone()).toList(); + _cargoTypes = _carton!.cargoTypes.map((e) => e.clone()).toList(); _isNew = false; _user = User( - id: _carton.userID, fcsID: _carton.fcsID, name: _carton.userName); + id: _carton!.userID, fcsID: _carton!.fcsID, name: _carton!.userName); consignee = User( - id: _carton.userID, fcsID: _carton.fcsID, name: _carton.userName); + id: _carton!.userID, fcsID: _carton!.fcsID, name: _carton!.userName); sender = User( - id: _carton.senderID, - fcsID: _carton.senderFCSID, - name: _carton.senderName); - _selectedMixBoxType = _carton.mixBoxType ?? ""; + id: _carton!.senderID, + fcsID: _carton!.senderFCSID, + name: _carton!.senderName); + _selectedMixBoxType = _carton!.mixBoxType; this._mixCartons = - _carton.mixCartons == null ? [] : List.from(_carton.mixCartons); - bool isMixBox = _carton.cartonType == carton_mix_box; - bool isFromPackages = _carton.cartonType == carton_from_packages; + _carton!.mixCartons == null ? [] : List.from(_carton!.mixCartons); + bool isMixBox = _carton!.cartonType == carton_mix_box; + bool isFromPackages = _carton!.cartonType == carton_from_packages; if (isFromPackages) _loadPackages(); if (!isMixBox) { @@ -138,8 +138,8 @@ class _CartonEditorState extends State { FcsShipmentModel fcsShipmentModel = Provider.of(context, listen: false); var fcsShipments = await fcsShipmentModel.getActiveFcsShipments(); - var fcsShipment = fcsShipments - .firstWhere((e) => e.id == _carton.fcsShipmentID, orElse: () => null); + var fcsShipment = + fcsShipments.firstWhere((e) => e.id == _carton!.fcsShipmentID); setState(() { _fcsShipments = fcsShipments; _fcsShipment = fcsShipment; @@ -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; + 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 { @@ -169,8 +169,8 @@ class _CartonEditorState extends State { }); } else { packages.forEach((p) { - if (_carton.packages.contains(p)) { - p.isChecked = _carton.packages.firstWhere((cp) => cp == p).isChecked; + if (_carton!.packages.contains(p)) { + p.isChecked = _carton!.packages.firstWhere((cp) => cp == p).isChecked; } else { p.isChecked = false; } @@ -178,7 +178,7 @@ class _CartonEditorState extends State { } setState(() { - _carton.packages = packages; + _carton!.packages = packages; }); // _populateDeliveryAddress(); } @@ -206,9 +206,9 @@ class _CartonEditorState extends State { _getCartonSize() { var cartonSizeModel = Provider.of(context, listen: false); cartonSizeModel.cartonSizes.forEach((c) { - if (c.length == _carton.length && - c.width == _carton.width && - c.height == _carton.height) { + if (c.length == _carton!.length && + c.width == _carton!.width && + c.height == _carton!.height) { selectedCatonSize = CartonSize( id: c.id, name: c.name, @@ -232,7 +232,7 @@ class _CartonEditorState extends State { bool isMixBox = _selectedCartonType == carton_mix_box; final shipmentBox = DisplayText( - text: _carton.fcsShipmentNumber, + text: _carton!.fcsShipmentNumber, labelTextKey: "box.fcs_shipment_num", iconData: Ionicons.ios_airplane, ); @@ -248,8 +248,8 @@ class _CartonEditorState extends State { labelKey: "shipment.pack.fcs.shipment", iconData: Ionicons.ios_airplane, display: (u) => u.shipmentNumber, - selectedValue: _fcsShipment, - values: _fcsShipments, + selectedValue: _fcsShipment!, + values: _fcsShipments!, )); final fcsIDBox = Container( @@ -297,7 +297,7 @@ class _CartonEditorState extends State { readOnly: !_isNew, values: boxModel.cartonTypes, selectedValue: _selectedCartonType, - callback: (v) { + callback: (String? v) { setState(() { _selectedCartonType = v; }); @@ -337,7 +337,7 @@ class _CartonEditorState extends State { value: e, groupValue: _selectedMixBoxType, activeColor: primaryColor, - onChanged: (v) { + onChanged: (String? v) { setState(() { _selectedMixBoxType = v; }); @@ -407,7 +407,7 @@ class _CartonEditorState extends State { color: primaryColor, ), onPressed: () async { - List cargos = await Navigator.push>( + List? cargos = await Navigator.push>( context, CupertinoPageRoute(builder: (context) => CargoTypeAddition())); if (cargos == null) return; @@ -462,7 +462,7 @@ class _CartonEditorState extends State { children: [ Expanded( child: DisplayText( - text: consignee != null ? consignee.fcsID : "", + text: consignee != null ? consignee!.fcsID : "", labelTextKey: "processing.fcs.id", icon: FcsIDIcon(), )), @@ -477,7 +477,7 @@ class _CartonEditorState extends State { ); final consigneeNameBox = DisplayText( - text: consignee != null ? consignee.name : "", + text: consignee != null ? consignee!.name : "", labelTextKey: "processing.consignee.name", maxLines: 2, iconData: Icons.person, @@ -496,7 +496,7 @@ class _CartonEditorState extends State { children: [ Expanded( child: DisplayText( - text: sender != null ? sender.fcsID : "", + text: sender != null ? sender!.fcsID : "", labelTextKey: "processing.fcs.id", icon: FcsIDIcon(), )), @@ -511,7 +511,7 @@ class _CartonEditorState extends State { ); final shipperNamebox = DisplayText( - text: sender != null ? sender.name : "", + text: sender != null ? sender!.name : "", labelTextKey: "processing.shipper.name", maxLines: 2, iconData: Icons.person, @@ -551,7 +551,7 @@ class _CartonEditorState extends State { children: [ _isNew ? Container() - : Center(child: getCartonNumberStatus(context, _carton)), + : Center(child: getCartonNumberStatus(context, _carton!)), LocalTitle(textKey: "box.type.title"), cartonTypeBox, LocalTitle(textKey: "box.shipment_info"), @@ -572,7 +572,7 @@ class _CartonEditorState extends State { isFromPackages ? namebox : Container(), isFromPackages ? CartonPackageTable( - packages: _carton.packages, + packages: _carton!.packages, onSelect: (p, checked) { // if (checked && // _deliveryAddress != null && @@ -623,7 +623,7 @@ class _CartonEditorState extends State { deliveryAddress: _deliveryAddress, labelKey: "box.delivery_address", onTap: () async { - DeliveryAddress d = + DeliveryAddress? d = await Navigator.push( context, CupertinoPageRoute( @@ -631,8 +631,8 @@ class _CartonEditorState extends State { DeliveryAddressSelection( deliveryAddress: _deliveryAddress, user: User( - id: _carton.userID, - name: _carton.userName))), + id: _carton!.userID, + name: _carton!.userName))), ); if (d == null) return; setState(() { @@ -667,7 +667,7 @@ class _CartonEditorState extends State { bool isFromCartons = _selectedCartonType == carton_from_cartons; if (isFromPackages) { _loadPackages(); - c.value.packages = _carton.packages; + c.value.packages = _carton!.packages; Carton _c = await Navigator.push( context, CupertinoPageRoute( @@ -736,20 +736,20 @@ class _CartonEditorState extends State { height: 1, color: Colors.grey, ), - onChanged: (CartonSize newValue) { + onChanged: (CartonSize? newValue) { setState(() { - if (newValue.name == MANAGE_CARTONSIZE) { + if (newValue!.name == MANAGE_CARTONSIZE) { selectedCatonSize = null; _manageCartonSize(); return; } selectedCatonSize = newValue; _widthController.text = - selectedCatonSize.width.toString(); + selectedCatonSize!.width.toString(); _heightController.text = - selectedCatonSize.height.toString(); + selectedCatonSize!.height.toString(); _lengthController.text = - selectedCatonSize.length.toString(); + selectedCatonSize!.length.toString(); }); }, isExpanded: true, @@ -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 @@ -789,8 +789,7 @@ class _CartonEditorState extends State { _updateCargo(CargoType cargo) { setState(() { - var _c = - _cargoTypes.firstWhere((e) => e.id == cargo.id, orElse: () => null); + var _c = _cargoTypes.firstWhere((e) => e.id == cargo.id); if (_c != null) { _c.weight = cargo.weight; _c.qty = cargo.qty; @@ -827,30 +826,30 @@ class _CartonEditorState extends State { double h = double.parse(_heightController.text, (s) => 0); Carton carton = Carton(); - carton.id = _carton.id; - carton.cartonType = _selectedCartonType; - carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID; + carton.id = _carton!.id; + carton.cartonType = _selectedCartonType!; + carton.fcsShipmentID = _isNew ? _fcsShipment!.id : _carton!.fcsShipmentID; if (isFromPackages) { - carton.userID = _user?.id; - carton.fcsID = _user?.fcsID; - carton.userName = _user?.name; - carton.packages = _carton.packages.where((e) => e.isChecked).toList(); + carton.userID = _user?.id ?? ''; + carton.fcsID = _user?.fcsID ?? ''; + carton.userName = _user?.name ?? ''; + carton.packages = _carton!.packages.where((e) => e.isChecked).toList(); } if (isFromCartons) { - carton.userID = consignee?.id; - carton.fcsID = consignee?.fcsID; - carton.userName = consignee?.name; - carton.senderID = sender?.id; - carton.senderFCSID = sender?.fcsID; - carton.senderName = sender?.name; + carton.userID = consignee?.id ?? ""; + carton.fcsID = consignee?.fcsID ?? ""; + carton.userName = consignee?.name ?? ""; + carton.senderID = sender?.id ?? ""; + carton.senderFCSID = sender?.fcsID ?? ""; + carton.senderName = sender?.name ?? ""; } - carton.cargoTypes = _carton.cargoTypes; + carton.cargoTypes = _carton!.cargoTypes; carton.length = l; carton.width = w; carton.height = h; - carton.deliveryAddress = _carton.deliveryAddress; + carton.deliveryAddress = _carton!.deliveryAddress; try { Carton _c = await Navigator.push( @@ -898,15 +897,15 @@ class _CartonEditorState extends State { showMsgDialog(context, "Error", "Please select FCS shipment"); return; } - if ((this._mixCartons?.length ?? 0) == 0) { + if (this._mixCartons.length == 0) { showMsgDialog(context, "Error", "Expect at least one carton"); return; } Carton carton = Carton(); - carton.id = _carton.id; - carton.cartonType = _selectedCartonType; - carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID; - carton.mixBoxType = _selectedMixBoxType; + carton.id = _carton!.id; + carton.cartonType = _selectedCartonType!; + carton.fcsShipmentID = _isNew ? _fcsShipment!.id : _carton!.fcsShipmentID; + carton.mixBoxType = _selectedMixBoxType!; carton.mixCartons = this._mixCartons; setState(() { _isLoading = true; @@ -932,11 +931,11 @@ class _CartonEditorState extends State { _save() async { bool isFromPackages = _selectedCartonType == carton_from_packages; bool isFromCartons = _selectedCartonType == carton_from_cartons; - if ((_cargoTypes?.length ?? 0) == 0 && (isFromPackages || isFromCartons)) { + if (_cargoTypes.length == 0 && (isFromPackages || isFromCartons)) { 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; } @@ -953,16 +952,16 @@ class _CartonEditorState extends State { } Carton carton = Carton(); - carton.id = _carton.id; - carton.cartonType = _selectedCartonType; - carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID; + carton.id = _carton!.id; + carton.cartonType = _selectedCartonType!; + carton.fcsShipmentID = _isNew ? _fcsShipment!.id : _carton!.fcsShipmentID; if (isFromPackages) { - carton.userID = _user?.id; - carton.packages = _carton.packages.where((e) => e.isChecked).toList(); + carton.userID = _user?.id ?? ""; + carton.packages = _carton!.packages.where((e) => e.isChecked).toList(); } if (isFromCartons) { - carton.userID = consignee?.id; - carton.senderID = sender?.id; + carton.userID = consignee?.id ?? ""; + carton.senderID = sender?.id ?? ""; } carton.cargoTypes = _cargoTypes; diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index 522b548..6b6c1de 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -19,7 +19,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_icons/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -33,7 +33,7 @@ import 'widgets.dart'; final DateFormat dateFormat = DateFormat("d MMM yyyy"); class CartonInfo extends StatefulWidget { - final Carton box; + final Carton? box; CartonInfo({this.box}); @override @@ -42,7 +42,7 @@ class CartonInfo extends StatefulWidget { class _CartonInfoState extends State { bool _isLoading = false; - Carton _box; + Carton? _box; DeliveryAddress _deliveryAddress = new DeliveryAddress(); TextEditingController _widthController = new TextEditingController(); TextEditingController _heightController = new TextEditingController(); @@ -50,14 +50,14 @@ class _CartonInfoState extends State { TextEditingController _cartonSizeController = new TextEditingController(); double volumetricRatio = 0; double shipmentWeight = 0; - String selectMixBoxType; + String? selectMixBoxType; - bool isMixBox; - bool isFromShipments; - bool isFromPackages; - bool isSmallBag; - bool isFromCartons; - bool isEdiable; + bool isMixBox = false; + bool isFromShipments = false; + bool isFromPackages = false; + bool isSmallBag = false; + bool isFromCartons = false; + bool isEdiable = false; @override void initState() { @@ -77,29 +77,29 @@ class _CartonInfoState extends State { } _updateBoxData() { - _widthController.text = _box.width.toString(); - _heightController.text = _box.height.toString(); - _lengthController.text = _box.length.toString(); - _cartonSizeController.text = _box.cartonSizeName ?? ""; - _deliveryAddress = _box.deliveryAddress; - isMixBox = _box.cartonType == carton_mix_box; - isFromShipments = _box.cartonType == carton_from_shipments; - isFromPackages = _box.cartonType == carton_from_packages; - isSmallBag = _box.cartonType == carton_small_bag; - isFromCartons = _box.cartonType == carton_from_cartons; + _widthController.text = _box!.width.toString(); + _heightController.text = _box!.height.toString(); + _lengthController.text = _box!.length.toString(); + _cartonSizeController.text = _box!.cartonSizeName; + _deliveryAddress = _box!.deliveryAddress; + isMixBox = _box!.cartonType == carton_mix_box; + isFromShipments = _box!.cartonType == carton_from_shipments; + isFromPackages = _box!.cartonType == carton_from_packages; + isSmallBag = _box!.cartonType == carton_small_bag; + isFromCartons = _box!.cartonType == carton_from_cartons; isEdiable = (isFromPackages || isMixBox || isFromCartons) && - _box.status == carton_packed_status; - selectMixBoxType = _box.mixBoxType ?? ""; + _box!.status == carton_packed_status; + selectMixBoxType = _box!.mixBoxType; getCartonSize(); } getCartonSize() { var cartonSizeModel = Provider.of(context, listen: false); cartonSizeModel.cartonSizes.forEach((c) { - if (c.length == _box.length && - c.width == _box.width && - c.height == _box.height) { + if (c.length == _box!.length && + c.width == _box!.width && + c.height == _box!.height) { setState(() { _cartonSizeController.text = c.name; }); @@ -110,36 +110,37 @@ class _CartonInfoState extends State { _loadPackages() async { if (!isFromPackages && !isSmallBag) return; - if (_box.cartonType == carton_from_packages && _box.userID == null) return; + 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, package_delivered_status ]); - packages = packages.where((p) => _box.packageIDs.contains(p.id)).toList(); + packages = packages.where((p) => _box!.packageIDs.contains(p.id)).toList(); packages.forEach((p) { p.isChecked = true; }); setState(() { - _box.packages = packages; + _box!.packages = packages; }); } _loadMixCartons() async { - if (_box.cartonType != carton_mix_box) return; + if (_box!.cartonType != carton_mix_box) return; CartonModel cartonModel = Provider.of(context, listen: false); List catons = []; - for (var id in _box.mixCartonIDs) { + for (var id in _box!.mixCartonIDs) { Carton c = await cartonModel.getCarton(id); catons.add(c); } setState(() { - _box.mixCartons = catons; + _box!.mixCartons = catons; }); } @@ -167,32 +168,32 @@ class _CartonInfoState extends State { readOnly: true, values: cartonModel.cartonTypesInfo, selectedValue: - _box.isShipmentCarton ? carton_from_shipments : _box.cartonType); + _box!.isShipmentCarton ? carton_from_shipments : _box!.cartonType); final shipmentBox = DisplayText( - text: _box.fcsShipmentNumber, + text: _box!.fcsShipmentNumber, labelTextKey: "box.fcs_shipment_num", iconData: Ionicons.ios_airplane, ); final fcsIDBox = DisplayText( - text: _box.fcsID == null ? "" : _box.fcsID, + text: _box!.fcsID == null ? "" : _box!.fcsID, labelTextKey: "box.fcs.id", icon: FcsIDIcon(), ); final customerNameBox = DisplayText( - text: _box.userName == null ? "" : _box.userName, + text: _box!.userName == null ? "" : _box!.userName, labelTextKey: "box.name", iconData: Icons.person, ); final consigneefcsIDBox = DisplayText( - text: _box.fcsID != null ? _box.fcsID : "", + text: _box!.fcsID != null ? _box!.fcsID : "", labelTextKey: "processing.fcs.id", icon: FcsIDIcon(), ); final consigneeNameBox = DisplayText( - text: _box.userName != null ? _box.userName : "", + text: _box!.userName != null ? _box!.userName : "", labelTextKey: "processing.consignee.name", maxLines: 2, iconData: Icons.person, @@ -211,7 +212,7 @@ class _CartonInfoState extends State { children: [ Expanded( child: DisplayText( - text: _box.senderFCSID != null ? _box.senderFCSID : "", + text: _box!.senderFCSID, labelTextKey: "processing.fcs.id", icon: FcsIDIcon(), )), @@ -219,7 +220,7 @@ class _CartonInfoState extends State { ); final shipperNamebox = DisplayText( - text: _box.senderName != null ? _box.senderName : "", + text: _box!.senderName, labelTextKey: "processing.shipper.name", maxLines: 2, iconData: Icons.person, @@ -269,10 +270,10 @@ class _CartonInfoState extends State { iconData: AntDesign.CodeSandbox, ); final cargoTableBox = CargoTable( - cargoTypes: _box.cargoTypes, + cargoTypes: _box!.cargoTypes, ); final mixCartonNumberBox = DisplayText( - text: _box.mixCartonNumber, + text: _box!.mixCartonNumber, labelTextKey: "box.mix.carton", iconData: MaterialCommunityIcons.package, ); @@ -300,7 +301,7 @@ class _CartonInfoState extends State { color: primaryColor, ), ), - Text(selectMixBoxType) + Text(selectMixBoxType ?? "") ], ) ], @@ -340,7 +341,7 @@ class _CartonInfoState extends State { body: Padding( padding: const EdgeInsets.all(10.0), child: ListView(shrinkWrap: true, children: [ - Center(child: getCartonNumberStatus(context, _box)), + Center(child: getCartonNumberStatus(context, _box!)), LocalTitle(textKey: "box.type.title"), cartonTypeBox, LocalTitle(textKey: "box.shipment_info"), @@ -367,11 +368,11 @@ class _CartonInfoState extends State { isMixBox ? mixTypeBox : Container(), isMixBox ? LocalTitle(textKey: "box.mix_caton_title") : Container(), isMixBox - ? Column(children: _getCartons(context, _box.mixCartons)) + ? Column(children: _getCartons(context, _box!.mixCartons)) : Container(), isFromPackages || isSmallBag ? CartonPackageTable( - packages: _box.packages, + packages: _box!.packages, ) : Container(), isMixBox ? Container() : LocalTitle(textKey: "box.cargo.type"), @@ -408,14 +409,14 @@ class _CartonInfoState extends State { } _gotoEditor() async { - _box.mixCartons = _box.mixCartons; - bool updated = await Navigator.push( + _box!.mixCartons = _box!.mixCartons; + bool? updated = await Navigator.push( context, CupertinoPageRoute(builder: (context) => CartonEditor(box: _box)), ); 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(); @@ -437,7 +438,7 @@ class _CartonInfoState extends State { }); try { var cartonModel = Provider.of(context, listen: false); - await cartonModel.deleteCarton(widget.box); + await cartonModel.deleteCarton(widget.box!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/carton/carton_list_row.dart b/lib/pages/carton/carton_list_row.dart index 9c47368..aada457 100644 --- a/lib/pages/carton/carton_list_row.dart +++ b/lib/pages/carton/carton_list_row.dart @@ -3,13 +3,13 @@ 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:flutter_vector_icons/flutter_vector_icons.dart'; 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, 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 == null ? "" : 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 86daa49..5187c2e 100644 --- a/lib/pages/carton/carton_mix_table.dart +++ b/lib/pages/carton/carton_mix_table.dart @@ -8,10 +8,10 @@ import 'package:flutter/material.dart'; typedef OnSelect = Function(Carton carton, bool checked); class CartonMixTable extends StatelessWidget { - final List cartons; - final OnSelect onSelect; + final List? cartons; + final OnSelect? onSelect; - const CartonMixTable({Key key, this.cartons, this.onSelect}) + const CartonMixTable({Key? key, this.cartons, this.onSelect}) : super(key: key); @override @@ -32,21 +32,21 @@ class CartonMixTable extends StatelessWidget { ); final rows = cartons == null - ? [] - : cartons.asMap().entries.map((p) { + ? [Container()] + : cartons!.asMap().entries.map((p) { return Container( color: p.value.isChecked ? Colors.grey.withOpacity(0.2) - : Colors.grey[50].withOpacity(0.2), + : Colors.grey.shade50.withOpacity(0.2), child: Container( padding: EdgeInsets.only( left: 0.0, right: 10.0, top: 3.0, bottom: 3.0), decoration: BoxDecoration( border: Border( bottom: BorderSide( - color: p.key == cartons.length - 1 + color: p.key == cartons!.length - 1 ? Colors.white - : Colors.grey[350], + : Colors.grey.shade300, width: 1), ), ), @@ -55,16 +55,16 @@ class CartonMixTable extends StatelessWidget { Checkbox( value: p.value.isChecked, activeColor: primaryColor, - onChanged: (bool check) { - if (onSelect != null) onSelect(p.value, check); + onChanged: (bool? check) { + if (onSelect != null) onSelect!(p.value, check!); }), Expanded( child: new Text( - p.value.cartonNumber ?? "", + p.value.cartonNumber, style: textStyle, )), new Text( - p.value?.actualWeight?.toString() ?? "", + p.value.actualWeight.toString(), style: textStyle, ), ], diff --git a/lib/pages/carton/carton_package_table.dart b/lib/pages/carton/carton_package_table.dart index 07eb9f3..0735472 100644 --- a/lib/pages/carton/carton_package_table.dart +++ b/lib/pages/carton/carton_package_table.dart @@ -8,10 +8,10 @@ import 'package:flutter/material.dart'; typedef OnSelect = Function(Package package, bool checked); class CartonPackageTable extends StatelessWidget { - final List packages; - final OnSelect onSelect; + final List? packages; + final OnSelect? onSelect; - const CartonPackageTable({Key key, this.packages, this.onSelect}) + const CartonPackageTable({Key? key, this.packages, this.onSelect}) : super(key: key); @override @@ -34,20 +34,20 @@ class CartonPackageTable extends StatelessWidget { final rows = packages == null ? [Container()] - : packages.asMap().entries.map((p) { + : packages!.asMap().entries.map((p) { return Container( color: p.value.isChecked ? Colors.grey.withOpacity(0.2) - : Colors.grey[50].withOpacity(0.2), + : Colors.grey.shade50.withOpacity(0.2), child: Container( padding: EdgeInsets.only( left: 0.0, right: 10.0, top: 3.0, bottom: 3.0), decoration: BoxDecoration( border: Border( bottom: BorderSide( - color: p.key == packages.length - 1 + color: p.key == packages!.length - 1 ? Colors.white - : Colors.grey[350], + : Colors.grey.shade300, width: 1), ), ), @@ -62,8 +62,8 @@ class CartonPackageTable extends StatelessWidget { : Checkbox( value: p.value.isChecked, activeColor: primaryColor, - onChanged: (bool check) { - if (onSelect != null) onSelect(p.value, check); + onChanged: (bool? check) { + if (onSelect != null) onSelect!(p.value, check!); }), Expanded( child: Column( @@ -74,11 +74,11 @@ class CartonPackageTable extends StatelessWidget { 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,11 +88,11 @@ class CartonPackageTable extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ new Text( - p.value?.desc ?? "", + p.value.desc, style: textStyle, ), new Text( - "(${p.value?.market ?? ""})", + "(${p.value.market})", style: textStyle, ) ], diff --git a/lib/pages/carton/carton_row.dart b/lib/pages/carton/carton_row.dart index 0c8eb21..131afea 100644 --- a/lib/pages/carton/carton_row.dart +++ b/lib/pages/carton/carton_row.dart @@ -2,15 +2,15 @@ import 'package:fcs/domain/entities/carton.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_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; typedef OnRemove(Carton carton); class CartonRow extends StatelessWidget { - final Carton box; - final OnRemove onRemove; - CartonRow({Key key, this.box, this.onRemove}) : super(key: key); + final Carton? box; + final OnRemove? onRemove; + CartonRow({Key? key, this.box, this.onRemove}) : super(key: key); final double dotSize = 15.0; final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); @@ -20,7 +20,7 @@ class CartonRow extends StatelessWidget { return Container( decoration: BoxDecoration( border: Border( - bottom: BorderSide(color: Colors.grey[300]), + bottom: BorderSide(color: Colors.grey.shade300), ), ), child: Row( @@ -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/input_text_border.dart b/lib/pages/carton/input_text_border.dart index 58f2314..4c2eff7 100644 --- a/lib/pages/carton/input_text_border.dart +++ b/lib/pages/carton/input_text_border.dart @@ -3,10 +3,10 @@ import 'package:flutter/material.dart'; typedef OnAdd(String value); class InputTextBorder extends StatelessWidget { - final OnAdd onAdd; - final TextEditingController controller; + final OnAdd? onAdd; + final TextEditingController? controller; - const InputTextBorder({Key key, this.onAdd, this.controller}) + const InputTextBorder({Key? key, this.onAdd, this.controller}) : super(key: key); @override Widget build(BuildContext context) { @@ -14,7 +14,7 @@ class InputTextBorder extends StatelessWidget { textAlign: TextAlign.center, controller: controller, onChanged: (v) { - if (onAdd != null) onAdd(v); + if (onAdd != null) onAdd!(v); }, keyboardType: TextInputType.number, decoration: new InputDecoration( diff --git a/lib/pages/carton/package_carton_editor.dart b/lib/pages/carton/package_carton_editor.dart index 87f48e4..9526e4c 100644 --- a/lib/pages/carton/package_carton_editor.dart +++ b/lib/pages/carton/package_carton_editor.dart @@ -21,7 +21,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_icons/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; import 'cargo_type_addtion.dart'; @@ -29,9 +29,9 @@ import 'carton_cargo_table.dart'; import 'model/carton_model.dart'; class PackageCartonEditor extends StatefulWidget { - final Carton carton; - final bool isNew; - final User consignee; + final Carton? carton; + final bool? isNew; + final User? consignee; PackageCartonEditor({this.carton, this.isNew, this.consignee}); @override @@ -43,13 +43,13 @@ class _PackageCartonEditorState extends State { TextEditingController _widthCtl = new TextEditingController(); TextEditingController _heightCtl = new TextEditingController(); - Carton _carton; + Carton? _carton; bool _isLoading = false; DeliveryAddress _deliveryAddress = new DeliveryAddress(); List _cargoTypes = []; - CartonSize selectedCatonSize; - bool isFromPackages; - bool isFromCartons; + CartonSize? selectedCatonSize; + bool isFromPackages = false; + bool isFromCartons = false; @override void initState() { @@ -59,19 +59,19 @@ class _PackageCartonEditorState extends State { _load() { _carton = widget.carton; - isFromPackages = _carton.cartonType == carton_from_packages; - isFromCartons = _carton.cartonType == carton_from_cartons; + isFromPackages = _carton!.cartonType == carton_from_packages; + isFromCartons = _carton!.cartonType == carton_from_cartons; - if (widget.isNew) { + if (widget.isNew!) { _lengthCtl.text = "0"; _widthCtl.text = "0"; _heightCtl.text = "0"; } else { - _cargoTypes = widget.carton.cargoTypes.map((e) => e.clone()).toList(); - _lengthCtl.text = _carton.length.toString(); - _widthCtl.text = _carton.width.toString(); - _heightCtl.text = _carton.height.toString(); - _deliveryAddress = _carton.deliveryAddress; + _cargoTypes = widget.carton!.cargoTypes.map((e) => e.clone()).toList(); + _lengthCtl.text = _carton!.length.toString(); + _widthCtl.text = _carton!.width.toString(); + _heightCtl.text = _carton!.height.toString(); + _deliveryAddress = _carton!.deliveryAddress; _getCartonSize(); } } @@ -79,9 +79,9 @@ class _PackageCartonEditorState extends State { _getCartonSize() { var cartonSizeModel = Provider.of(context, listen: false); cartonSizeModel.cartonSizes.forEach((c) { - if (c.length == _carton.length && - c.width == _carton.width && - c.height == _carton.height) { + if (c.length == _carton!.length && + c.width == _carton!.width && + c.height == _carton!.height) { selectedCatonSize = CartonSize( id: c.id, name: c.name, @@ -122,7 +122,7 @@ class _PackageCartonEditorState extends State { ], ); final createBtn = LocalButton( - textKey: widget.isNew ? "box.new_carton_btn" : "box.cargo.save.btn", + textKey: widget.isNew! ? "box.new_carton_btn" : "box.cargo.save.btn", callBack: _creatCarton, ); @@ -134,11 +134,10 @@ class _PackageCartonEditorState extends State { color: primaryColor, ), onPressed: () async { - List cargos = await Navigator.push>( + List? cargos = await Navigator.push>( context, CupertinoPageRoute(builder: (context) => CargoTypeAddition())); if (cargos == null) return; - if (cargos == null) return; setState(() { _cargoTypes.addAll( cargos.where((e) => !_cargoTypes.contains(e)).toList()); @@ -168,7 +167,7 @@ class _PackageCartonEditorState extends State { backgroundColor: Colors.white, title: LocalText( context, - widget.isNew ? "boxes.create.title" : "box.edit.title", + widget.isNew! ? "boxes.create.title" : "box.edit.title", fontSize: 20, color: primaryColor, ), @@ -187,13 +186,14 @@ class _PackageCartonEditorState extends State { deliveryAddress: _deliveryAddress, labelKey: "box.delivery_address", onTap: () async { - DeliveryAddress d = await Navigator.push( + DeliveryAddress? d = await Navigator.push( context, CupertinoPageRoute( builder: (context) => DeliveryAddressSelection( deliveryAddress: _deliveryAddress, user: User( - id: _carton.userID, name: _carton.userName), + id: _carton!.userID, + name: _carton!.userName), )), ); if (d == null) return; @@ -245,17 +245,17 @@ class _PackageCartonEditorState extends State { height: 1, color: Colors.grey, ), - onChanged: (CartonSize newValue) { + onChanged: (CartonSize? newValue) { setState(() { - if (newValue.name == MANAGE_CARTONSIZE) { + if (newValue!.name == MANAGE_CARTONSIZE) { selectedCatonSize = null; _manageCartonSize(); return; } selectedCatonSize = newValue; - _widthCtl.text = selectedCatonSize.width.toString(); - _heightCtl.text = selectedCatonSize.height.toString(); - _lengthCtl.text = selectedCatonSize.length.toString(); + _widthCtl.text = selectedCatonSize!.width.toString(); + _heightCtl.text = selectedCatonSize!.height.toString(); + _lengthCtl.text = selectedCatonSize!.length.toString(); }); }, isExpanded: true, @@ -263,7 +263,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 @@ -295,8 +295,7 @@ class _PackageCartonEditorState extends State { _updateCargo(CargoType cargo) { setState(() { - var _c = - _cargoTypes.firstWhere((e) => e.id == cargo.id, orElse: () => null); + var _c = _cargoTypes.firstWhere((e) => e.id == cargo.id); if (_c != null) { _c.weight = cargo.weight; _c.qty = cargo.qty; @@ -305,13 +304,13 @@ class _PackageCartonEditorState extends State { } _creatCarton() async { - if ((_cargoTypes?.length ?? 0) == 0) { + if (_cargoTypes.length == 0) { showMsgDialog(context, "Error", "Expect at least one cargo type"); return; } - double l = double.parse(_lengthCtl.text, (s) => 0); - double w = double.parse(_widthCtl.text, (s) => 0); - double h = double.parse(_heightCtl.text, (s) => 0); + double l = double.parse(_lengthCtl.text); + double w = double.parse(_widthCtl.text); + double h = double.parse(_heightCtl.text); if ((l <= 0 || w <= 0 || h <= 0)) { showMsgDialog(context, "Error", "Invalid dimension"); return; @@ -322,22 +321,22 @@ class _PackageCartonEditorState extends State { } Carton carton = Carton(); - carton.id = _carton.id; - carton.cartonType = _carton.cartonType; - carton.fcsShipmentID = _carton.fcsShipmentID; + carton.id = _carton!.id; + carton.cartonType = _carton!.cartonType; + carton.fcsShipmentID = _carton!.fcsShipmentID; carton.cargoTypes = _cargoTypes; if (isFromPackages) { - carton.userID = _carton.userID; - carton.packages = _carton.packages.where((e) => e.isChecked).toList(); + carton.userID = _carton!.userID; + carton.packages = _carton!.packages.where((e) => e.isChecked).toList(); } if (isFromCartons) { - carton.userID = _carton.userID; - carton.fcsID = _carton.fcsID; - carton.userName = _carton.userName; - carton.senderID = _carton.senderID; - carton.senderFCSID = _carton.senderFCSID; - carton.senderName = _carton.senderName; + carton.userID = _carton!.userID; + carton.fcsID = _carton!.fcsID; + carton.userName = _carton!.userName; + carton.senderID = _carton!.senderID; + carton.senderFCSID = _carton!.senderFCSID; + carton.senderName = _carton!.senderName; } carton.length = l; @@ -350,12 +349,12 @@ class _PackageCartonEditorState extends State { try { CartonModel cartonModel = Provider.of(context, listen: false); - if (widget.isNew) { + if (widget.isNew!) { Carton _c = await cartonModel.createCarton(carton); 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/total_weight_edit.dart b/lib/pages/carton/total_weight_edit.dart index 614e0d5..21632f3 100644 --- a/lib/pages/carton/total_weight_edit.dart +++ b/lib/pages/carton/total_weight_edit.dart @@ -10,9 +10,9 @@ import 'package:fcs/pages/main/util.dart'; typedef void ProfileCallback(); class TotalWeightEdit extends StatefulWidget { - final double totalWeight; + final double? totalWeight; - const TotalWeightEdit({Key key, this.totalWeight}) : super(key: key); + const TotalWeightEdit({Key? key, this.totalWeight}) : super(key: key); @override _TotalWeightEditState createState() => _TotalWeightEditState(); } @@ -24,7 +24,7 @@ class _TotalWeightEditState extends State { @override void initState() { super.initState(); - totalController.text = widget.totalWeight.toStringAsFixed(2); + totalController.text = widget.totalWeight!.toStringAsFixed(2); } @override diff --git a/lib/pages/carton/widgets.dart b/lib/pages/carton/widgets.dart index 3e9a50c..3586d5b 100644 --- a/lib/pages/carton/widgets.dart +++ b/lib/pages/carton/widgets.dart @@ -10,14 +10,14 @@ Widget getCartonNumberStatus(BuildContext context, Carton carton) { LocalText( context, '', - text: carton.cartonNumber ?? "", + text: carton.cartonNumber , color: primaryColor, fontSize: 18, fontWeight: FontWeight.bold, ), 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 427a32e..d522a03 100644 --- a/lib/pages/carton_search/carton_list_row.dart +++ b/lib/pages/carton_search/carton_list_row.dart @@ -1,17 +1,17 @@ import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_icons/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'carton_search.dart'; class CartonListRow extends StatefulWidget { - final CallbackCartonSelect callbackCartonSelect; - final Carton carton; + final CallbackCartonSelect? callbackCartonSelect; + final Carton? carton; // const CartonListRow({this.carton, this.callbackCartonSelect}); CartonListRow( - {Key key, this.carton, this.callbackCartonSelect}) + {Key? key, this.carton, this.callbackCartonSelect}) : super(key: key); @override @@ -20,7 +20,7 @@ class CartonListRow extends StatefulWidget { class _CartonListRowState extends State { final double dotSize = 15.0; - Carton _carton; + Carton? _carton; @override void initState() { super.initState(); @@ -32,14 +32,14 @@ class _CartonListRowState extends State { return Container( decoration: BoxDecoration( border: Border( - bottom: BorderSide(color: Colors.grey[300]), + bottom: BorderSide(color: Colors.grey.shade300), ), ), child: InkWell( onTap: () { Navigator.pop(context); if (widget.callbackCartonSelect != null) - widget.callbackCartonSelect(widget.carton); + widget.callbackCartonSelect!(widget.carton!); }, child: Row( children: [ @@ -64,7 +64,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 +72,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 +86,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_search/carton_search.dart b/lib/pages/carton_search/carton_search.dart index 87cc1c9..5442616 100644 --- a/lib/pages/carton_search/carton_search.dart +++ b/lib/pages/carton_search/carton_search.dart @@ -10,7 +10,7 @@ import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/popupmenu.dart'; import 'package:fcs/pagination/paginator_listview.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_icons/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:provider/provider.dart'; @@ -18,15 +18,15 @@ import 'carton_list_row.dart'; typedef CallbackCartonSelect(Carton carton); -Future searchCarton(BuildContext context, - {CallbackCartonSelect callbackCartonSelect}) async => +Future searchCarton(BuildContext context, + {CallbackCartonSelect? callbackCartonSelect}) async => await showSearch( context: context, delegate: PartSearchDelegate(callbackCartonSelect: callbackCartonSelect), ); class PartSearchDelegate extends SearchDelegate { - final CallbackCartonSelect callbackCartonSelect; + final CallbackCartonSelect? callbackCartonSelect; PartSearchDelegate({this.callbackCartonSelect}); @override @@ -38,10 +38,10 @@ class PartSearchDelegate 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, ); } @@ -85,7 +85,7 @@ class PartSearchDelegate extends SearchDelegate { Widget buildLeading(BuildContext context) { return IconButton( icon: Icon(Icons.arrow_back), - onPressed: () => close(context, null), + onPressed: () => close(context, new Carton()), ); } @@ -96,7 +96,7 @@ class PartSearchDelegate extends SearchDelegate { future: cartonModel.searchCarton(query), builder: (context, AsyncSnapshot> snapshot) { if (snapshot.hasData) { - if (snapshot.data.length == 0) { + if (snapshot.data!.length == 0) { return Container( child: Center( child: Text( @@ -109,7 +109,7 @@ class PartSearchDelegate extends SearchDelegate { return Container( padding: EdgeInsets.only(top: 15), child: ListView( - children: snapshot.data + children: snapshot.data! .map((u) => CartonListRow( key: ValueKey(u.id), carton: u, @@ -158,17 +158,17 @@ class PartSearchDelegate extends SearchDelegate { } _scan(BuildContext context) async { - PermissionStatus permission = - await PermissionHandler().checkPermissionStatus(PermissionGroup.camera); - if (permission != PermissionStatus.granted) { - Map permissions = - await PermissionHandler() - .requestPermissions([PermissionGroup.camera]); - if (permissions[PermissionGroup.camera] != PermissionStatus.granted) { - showMsgDialog(context, "Error", "Camera permission is not granted"); - return null; - } - } + // PermissionStatus permission = + // await PermissionHandler().checkPermissionStatus(PermissionGroup.camera); + // if (permission != PermissionStatus.granted) { + // Map permissions = + // await PermissionHandler() + // .requestPermissions([PermissionGroup.camera]); + // if (permissions[PermissionGroup.camera] != PermissionStatus.granted) { + // showMsgDialog(context, "Error", "Camera permission is not granted"); + // return null; + // } + // } try { String barcode = await scanBarcode(); diff --git a/lib/pages/carton_size/carton_size_editor.dart b/lib/pages/carton_size/carton_size_editor.dart index 0b3662b..6f4f5df 100644 --- a/lib/pages/carton_size/carton_size_editor.dart +++ b/lib/pages/carton_size/carton_size_editor.dart @@ -7,13 +7,13 @@ 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_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; import 'model/carton_size_model.dart'; class CartonSizeEditor extends StatefulWidget { - final CartonSize cartonSize; + final CartonSize? cartonSize; CartonSizeEditor({this.cartonSize}); @override @@ -27,8 +27,8 @@ class _CartonSizeEditorState extends State { TextEditingController _lengthController = new TextEditingController(); bool _isLoading = false; - CartonSize _cartonSize; - bool _isNew; + CartonSize? _cartonSize; + bool _isNew = false; @override void initState() { @@ -36,10 +36,10 @@ class _CartonSizeEditorState extends State { if (widget.cartonSize != null) { _cartonSize = widget.cartonSize; _isNew = false; - _nameController.text = _cartonSize.name; - _widthController.text = _cartonSize.width.toString(); - _heightController.text = _cartonSize.height.toString(); - _lengthController.text = _cartonSize.length.toString(); + _nameController.text = _cartonSize!.name; + _widthController.text = _cartonSize!.width.toString(); + _heightController.text = _cartonSize!.height.toString(); + _lengthController.text = _cartonSize!.length.toString(); } else { _lengthController.text = "12"; _widthController.text = "12"; @@ -110,7 +110,7 @@ class _CartonSizeEditorState extends State { await cartonSizeModel.addCartonSize(_cartonSize); } else { CartonSize _cartonSize = CartonSize( - id: widget.cartonSize.id, + id: widget.cartonSize!.id, name: _nameController.text, length: l, width: w, @@ -184,7 +184,7 @@ class _CartonSizeEditorState extends State { CartonSize _cartonSize = CartonSize( name: _nameController.text, length: l, width: w, height: h); - return widget.cartonSize.isChangedForEdit(_cartonSize); + return widget.cartonSize!.isChangedForEdit(_cartonSize); } } } diff --git a/lib/pages/customer/customer_editor.dart b/lib/pages/customer/customer_editor.dart index e3df283..3176e32 100644 --- a/lib/pages/customer/customer_editor.dart +++ b/lib/pages/customer/customer_editor.dart @@ -14,7 +14,7 @@ import 'package:provider/provider.dart'; typedef void FindCallBack(); class CustomerEditor extends StatefulWidget { - final User customer; + final User? customer; const CustomerEditor({this.customer}); @override _CustomerEditorState createState() => _CustomerEditorState(); @@ -34,17 +34,17 @@ class _CustomerEditorState extends State { children: [ Expanded( child: DisplayText( - text: widget.customer.phoneNumber, + text: widget.customer!.phoneNumber, labelTextKey: "customer.phone", iconData: Icons.phone, )), IconButton( icon: Icon(Icons.open_in_new, color: primaryColor), - onPressed: () => call(context, widget.customer.phoneNumber)), + onPressed: () => call(context, widget.customer!.phoneNumber)), ], ); - final enabled = widget.customer.status != user_disabled_status; + final enabled = widget.customer!.status != user_disabled_status; final enableBox = LocalButton( textKey: enabled ? "customer.disable.btn" : "customer.enable.btn", iconData: enabled ? Icons.lock : Icons.lock_open, @@ -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, @@ -81,26 +81,26 @@ class _CustomerEditorState extends State { children: [ phoneNumberBox, DisplayText( - text: widget.customer.fcsID, + text: widget.customer!.fcsID, labelTextKey: "customer.fcs.id", icon: FcsIDIcon(), ), DisplayText( - text: widget.customer.status, + text: widget.customer!.status, labelTextKey: "customer.status", iconData: Icons.add_alarm, ), SizedBox( height: 20, ), - widget.customer.requested + widget.customer!.requested ? fcsButton( context, getLocalString( context, "customer.invitation.request.confirm"), callack: _add) : Container(), - widget.customer.joined || widget.customer.disabled + widget.customer!.joined || widget.customer!.disabled ? enableBox : Container() ], @@ -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()); @@ -139,7 +139,7 @@ class _CustomerEditorState extends State { CustomerModel customerModel = Provider.of(context, listen: false); try { - await customerModel.enableUser(widget.customer, enabled); + await customerModel.enableUser(widget.customer!, enabled); 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 a1fbd72..2f9031a 100644 --- a/lib/pages/customer/customer_list.dart +++ b/lib/pages/customer/customer_list.dart @@ -233,11 +233,11 @@ class _CustomerListState extends State { _share(User user) async { MainModel mainModel = Provider.of(context, listen: false); String appUrl = mainModel.setting.appUrl; - final RenderBox box = context.findRenderObject(); + final RenderBox? box = context.findRenderObject() as RenderBox; await Share.share( "Join us on FCS Logistics App. Here is the link:\n $appUrl\n" + user.share, subject: "Invitation to FCS Logistics App", - sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size); + sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); } } diff --git a/lib/pages/customer/invitation_create.dart b/lib/pages/customer/invitation_create.dart index af2e2ed..e2bb37a 100644 --- a/lib/pages/customer/invitation_create.dart +++ b/lib/pages/customer/invitation_create.dart @@ -19,7 +19,7 @@ class _InvitationCreateState extends State { TextEditingController _phoneController = new TextEditingController(); bool _isLoading = false; - String dialCode; + late String dialCode; @override void initState() { @@ -85,7 +85,7 @@ class _InvitationCreateState extends State { ), Container( decoration: BoxDecoration( - border: Border.all(color: Colors.grey[400], width: 1), + border: Border.all(color: Colors.grey.shade400, width: 1), borderRadius: BorderRadius.all(Radius.circular(12.0))), child: CountryCodePicker( onChanged: _countryChange, @@ -140,7 +140,7 @@ class _InvitationCreateState extends State { _countryChange(CountryCode countryCode) { setState(() { - dialCode = countryCode.dialCode; + dialCode = countryCode.dialCode!; }); } diff --git a/lib/pages/customer/invitation_editor.dart b/lib/pages/customer/invitation_editor.dart index 837f704..f8b89d6 100644 --- a/lib/pages/customer/invitation_editor.dart +++ b/lib/pages/customer/invitation_editor.dart @@ -11,7 +11,7 @@ import 'package:provider/provider.dart'; typedef void FindCallBack(); class InvitationEditor extends StatefulWidget { - final User customer; + final User? customer; const InvitationEditor({this.customer}); @override _InvitationEditorState createState() => _InvitationEditorState(); @@ -31,13 +31,13 @@ class _InvitationEditorState extends State { children: [ Expanded( child: DisplayText( - text: widget.customer.phoneNumber, + text: widget.customer!.phoneNumber, labelTextKey: getLocalString(context, "customer.phone"), iconData: Icons.phone, )), 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 1413f3a..8dda2f0 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 = []; - StreamSubscription customerListener; - StreamSubscription invitationListener; + late StreamSubscription customerListener; + late StreamSubscription invitationListener; @override void privilegeChanged() { diff --git a/lib/pages/fcs_shipment/fcs_shipment_editor.dart b/lib/pages/fcs_shipment/fcs_shipment_editor.dart index 82feb2e..05bbc72 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_editor.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_editor.dart @@ -12,7 +12,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/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -20,7 +20,7 @@ import 'package:provider/provider.dart'; import '../main/util.dart'; class FcsShipmentEditor extends StatefulWidget { - final FcsShipment shipment; + final FcsShipment? shipment; FcsShipmentEditor({this.shipment}); @override @@ -40,7 +40,7 @@ class _FcsShipmentEditorState extends State { FcsShipment _shipment = new FcsShipment(); bool _isLoading = false; - String _currentShipmentType; + String? _currentShipmentType; bool _isNew = false; @override @@ -48,7 +48,7 @@ class _FcsShipmentEditorState extends State { super.initState(); _isNew = widget.shipment == null; if (widget.shipment != null) { - _shipment = widget.shipment; + _shipment = widget.shipment!; _shipmentNumberController.text = _shipment.shipmentNumber; _cutoffDateController.text = dateFormatter.format(_shipment.cutoffDate); _arrivalDateController.text = dateFormatter.format(_shipment.arrivalDate); @@ -149,7 +149,7 @@ class _FcsShipmentEditorState extends State { items: mainModel.setting.shipmentTypes .map((e) => DropdownMenuItem(child: Text(e), value: e)) .toList(), - onChanged: (selected) => { + onChanged: (String? selected) => { setState(() { _currentShipmentType = selected; }) @@ -188,7 +188,7 @@ class _FcsShipmentEditorState extends State { FcsShipment fcsShipment = FcsShipment(); fcsShipment.id = _shipment.id; fcsShipment.shipmentNumber = _shipmentNumberController.text; - fcsShipment.shipType = _currentShipmentType; + fcsShipment.shipType = _currentShipmentType!; fcsShipment.consignee = _consigneeController.text; fcsShipment.port = _portController.text; fcsShipment.destination = _destinationController.text; @@ -197,9 +197,9 @@ class _FcsShipmentEditorState extends State { var arrivalDate = _arrivalDateController.text; // var depDate = _departureDateControler.text; fcsShipment.cutoffDate = - cutoffDate == "" ? null : dateFormatter.parse(cutoffDate); + (cutoffDate == "" ? null : dateFormatter.parse(cutoffDate))!; fcsShipment.arrivalDate = - arrivalDate == "" ? null : dateFormatter.parse(arrivalDate); + (arrivalDate == "" ? null : dateFormatter.parse(arrivalDate))!; // fcsShipment.departureDate = // depDate == "" ? null : dateFormatter.parse(depDate); } catch (e) { @@ -288,7 +288,7 @@ class _FcsShipmentEditorState extends State { _currentShipmentType != mainModel.setting.shipmentTypes[0]; } else { FcsShipment fcsShipment = _getPayload(); - return widget.shipment.isChangedForEdit(fcsShipment); + return widget.shipment!.isChangedForEdit(fcsShipment); } } } diff --git a/lib/pages/fcs_shipment/fcs_shipment_info.dart b/lib/pages/fcs_shipment/fcs_shipment_info.dart index 091fe30..3635571 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_info.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_info.dart @@ -11,7 +11,7 @@ import 'package:fcs/pages/widgets/popupmenu.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_vector_icons/flutter_vector_icons.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -19,7 +19,7 @@ import 'package:provider/provider.dart'; import 'fcs_shipment_editor.dart'; class FcsShipmentInfo extends StatefulWidget { - final FcsShipment fcsShipment; + final FcsShipment? fcsShipment; FcsShipmentInfo({this.fcsShipment}); @override @@ -28,7 +28,7 @@ class FcsShipmentInfo extends StatefulWidget { class _FcsShipmentInfoState extends State { var dateFormatter = new DateFormat('dd MMM yyyy'); - FcsShipment _fcsShipment; + FcsShipment? _fcsShipment; bool _isLoading = false; TextEditingController _shipmentNumberController = new TextEditingController(); TextEditingController _cutoffDateController = new TextEditingController(); @@ -48,17 +48,17 @@ class _FcsShipmentInfoState extends State { } _load() { - _shipmentNumberController.text = _fcsShipment.shipmentNumber; - _cutoffDateController.text = dateFormatter.format(_fcsShipment.cutoffDate); + _shipmentNumberController.text = _fcsShipment!.shipmentNumber; + _cutoffDateController.text = dateFormatter.format(_fcsShipment!.cutoffDate); _arrivalDateController.text = - dateFormatter.format(_fcsShipment.arrivalDate); + dateFormatter.format(_fcsShipment!.arrivalDate); _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 @@ -166,7 +166,7 @@ class _FcsShipmentInfoState extends State { portBox, destinationBox, statusBox, - _fcsShipment.status == fcs_shipment_confirmed_status + _fcsShipment!.status == fcs_shipment_confirmed_status ? shipBtn : Container(), SizedBox( @@ -182,14 +182,14 @@ class _FcsShipmentInfoState extends State { } _edit() async { - bool updated = await Navigator.push( + bool? updated = await Navigator.push( context, CupertinoPageRoute( builder: (context) => FcsShipmentEditor(shipment: _fcsShipment)), ); if (updated ?? false) { var shipmentModel = Provider.of(context, listen: false); - var f = await shipmentModel.getFcsShipment(_fcsShipment.id); + var f = await shipmentModel.getFcsShipment(_fcsShipment!.id); setState(() { _fcsShipment = f; }); @@ -238,7 +238,7 @@ class _FcsShipmentInfoState extends State { try { FcsShipmentModel fcsShipmentModel = Provider.of(context, listen: false); - await fcsShipmentModel.ship(_fcsShipment); + await fcsShipmentModel.ship(_fcsShipment!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); @@ -264,11 +264,11 @@ class _FcsShipmentInfoState extends State { } else if (id == 4) { reportName = "manifest"; } - _fcsShipment.reportName = reportName; + _fcsShipment!.reportName = reportName; FcsShipmentModel fcsShipmentModel = Provider.of(context, listen: false); - String url = await fcsShipmentModel.report(_fcsShipment); + String url = await fcsShipmentModel.report(_fcsShipment!); Navigator.of(context).push(CupertinoPageRoute( builder: (context) => PDFScreen( title: "", diff --git a/lib/pages/fcs_shipment/fcs_shipment_list_row.dart b/lib/pages/fcs_shipment/fcs_shipment_list_row.dart index 020b304..3a6da34 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_list_row.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_list_row.dart @@ -3,14 +3,14 @@ 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:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'fcs_shipment_info.dart'; class FcsShipmentListRow extends StatelessWidget { - final FcsShipment shipment; + final FcsShipment? shipment; final dateFormatter = new DateFormat('dd MMM yyyy'); - FcsShipmentListRow({Key key, this.shipment}) : super(key: key); + FcsShipmentListRow({Key? key, this.shipment}) : super(key: key); @override Widget build(BuildContext context) { @@ -43,9 +43,9 @@ class FcsShipmentListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - shipment.shipmentNumber == null + shipment!.shipmentNumber == null ? '' - : shipment.shipmentNumber, + : shipment!.shipmentNumber, style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -53,7 +53,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 +67,7 @@ class FcsShipmentListRow extends StatelessWidget { ), Padding( padding: const EdgeInsets.all(0), - child: getStatus(shipment.status), + child: getStatus(shipment!.status), ), ], ), diff --git a/lib/pages/invoice/box_addition.dart b/lib/pages/invoice/box_addition.dart index 5429589..2bf0698 100644 --- a/lib/pages/invoice/box_addition.dart +++ b/lib/pages/invoice/box_addition.dart @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class BoxAddition extends StatefulWidget { - final Carton box; + final Carton? box; BoxAddition({this.box}); @override @@ -23,7 +23,7 @@ class _BoxAdditionState extends State { void initState() { super.initState(); if (widget.box != null) { - _box = widget.box; + _box = widget.box!; } } @@ -54,7 +54,7 @@ class _BoxAdditionState extends State { child: Padding( padding: const EdgeInsets.all(10.0), child: ListView(children: [ - DropdownButtonFormField( + DropdownButtonFormField( decoration: InputDecoration( fillColor: Colors.white, labelText: 'Box Number', diff --git a/lib/pages/invoice/editor/invoice_carton_table.dart b/lib/pages/invoice/editor/invoice_carton_table.dart index 77f05ec..8af98b8 100644 --- a/lib/pages/invoice/editor/invoice_carton_table.dart +++ b/lib/pages/invoice/editor/invoice_carton_table.dart @@ -9,11 +9,11 @@ import 'package:flutter/material.dart'; typedef OnSelect = Function(Carton carton, bool checked); class InvoiceCartonTable extends StatelessWidget { - final List cartons; - final OnSelect onSelect; - final Rate rate; + final List? cartons; + final OnSelect? onSelect; + final Rate? rate; - const InvoiceCartonTable({Key key, this.cartons, this.onSelect, this.rate}) + const InvoiceCartonTable({Key? key, this.cartons, this.onSelect, this.rate}) : super(key: key); @override @@ -36,20 +36,20 @@ class InvoiceCartonTable extends StatelessWidget { final rows = cartons == null ? [Container()] - : cartons.asMap().entries.map((p) { + : cartons!.asMap().entries.map((p) { return Container( color: p.value.isChecked ? Colors.grey.withOpacity(0.2) - : Colors.grey[50].withOpacity(0.2), + : Colors.grey.shade50.withOpacity(0.2), child: Container( padding: EdgeInsets.only( left: 0.0, right: 10.0, top: 3.0, bottom: 3.0), decoration: BoxDecoration( border: Border( bottom: BorderSide( - color: p.key == cartons.length - 1 + color: p.key == cartons!.length - 1 ? Colors.white - : Colors.grey[350], + : Colors.grey.shade300, width: 1), ), ), @@ -64,8 +64,8 @@ class InvoiceCartonTable extends StatelessWidget { : Checkbox( value: p.value.isChecked, activeColor: primaryColor, - onChanged: (bool check) { - if (onSelect != null) onSelect(p.value, check); + onChanged: (bool? check) { + if (onSelect != null) onSelect!(p.value, check!); }), Expanded( child: Column( @@ -82,15 +82,15 @@ class InvoiceCartonTable extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ new Text( - "${p.value?.length ?? ""} x ${p.value?.width ?? ""} x ${p.value?.height ?? ""}", + "${p.value.length} x ${p.value.width} x ${p.value.height}", style: textStyle, ), new Text( - "${p.value?.getShipmentWeight(rate.volumetricRatio)?.toStringAsFixed(2) ?? "0"} lb", + "${p.value.getShipmentWeight(rate!.volumetricRatio).toStringAsFixed(2)} lb", style: textStyle, ), new Text( - "${p.value?.actualWeight?.toStringAsFixed(2) ?? "0"} lb (Actual)", + "${p.value.actualWeight.toStringAsFixed(2)} lb (Actual)", style: textStyle, ), ], diff --git a/lib/pages/invoice/editor/invoice_discount_list.dart b/lib/pages/invoice/editor/invoice_discount_list.dart index 13ad897..75a348f 100644 --- a/lib/pages/invoice/editor/invoice_discount_list.dart +++ b/lib/pages/invoice/editor/invoice_discount_list.dart @@ -6,10 +6,10 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class InvoiceDiscountList extends StatelessWidget { - final List discounts; + final List? discounts; const InvoiceDiscountList({ - Key key, + Key? key, this.discounts, }) : super(key: key); @@ -63,19 +63,19 @@ class InvoiceDiscountList extends StatelessWidget { if (discounts == null) { return []; } - var rows = discounts.map((c) { + var rows = discounts!.map((c) { return MyDataRow( 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) ?? "0", 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 16f3420..32ddbd3 100644 --- a/lib/pages/invoice/editor/invoice_editor.dart +++ b/lib/pages/invoice/editor/invoice_editor.dart @@ -31,15 +31,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_vector_icons/flutter_vector_icons.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; class InvoiceEditor extends StatefulWidget { - final Invoice invoice; - final User customer; - final FcsShipment fcsShipment; + final Invoice? invoice; + final User? customer; + final FcsShipment? fcsShipment; InvoiceEditor({this.invoice, this.customer, this.fcsShipment}); @override @@ -49,10 +49,10 @@ class InvoiceEditor extends StatefulWidget { class _InvoiceEditorState extends State { var dateFormatter = new DateFormat('dd MMM yyyy'); - Invoice _invoice; + Invoice? _invoice; bool _isLoading = false; - bool _isNew; - User _user; + bool _isNew = false; + User? _user; bool _showCartons = false; @override @@ -91,12 +91,12 @@ class _InvoiceEditorState extends State { _loadCartons() async { CartonModel cartonModel = Provider.of(context, listen: false); List cartons = await cartonModel.getCartonsForInvoice( - widget.fcsShipment.id, widget.customer.id); + widget.fcsShipment!.id, widget.customer!.id); cartons.forEach((c) { c.isChecked = true; }); setState(() { - _invoice.cartons = cartons; + _invoice!.cartons = cartons; }); } @@ -104,12 +104,12 @@ class _InvoiceEditorState extends State { ShipmentModel shipmentModel = Provider.of(context, listen: false); List shipments = await shipmentModel.getShipmentWithHandlingFee( - widget.fcsShipment.id, widget.customer.id); + widget.fcsShipment!.id, widget.customer!.id); shipments.forEach((s) { s.isSelected = true; }); setState(() { - _invoice.shipments = shipments; + _invoice!.shipments = shipments; }); } @@ -117,10 +117,10 @@ class _InvoiceEditorState extends State { _loadDiscount() async { DiscountModel discountModel = Provider.of(context, listen: false); - discounts = await discountModel.getDiscount(widget.customer.id); + discounts = await discountModel.getDiscount(widget.customer!.id); if (discounts != null && discounts.length > 0) { setState(() { - _invoice.discount = discounts.first; + _invoice!.discount = discounts.first; }); } } @@ -146,7 +146,7 @@ class _InvoiceEditorState extends State { iconData: Icons.av_timer, labelTextKey: 'invoice.status'); final cartonTable = InvoiceCartonTable( - cartons: _invoice.cartons, + cartons: _invoice!.cartons, rate: rate, onSelect: (c, checked) { setState(() { @@ -157,30 +157,30 @@ class _InvoiceEditorState extends State { final paymentTypesBox = LocalDropdown( callback: (v) { setState(() { - _invoice.paymentMethod = v; + _invoice!.paymentMethod = v; }); }, labelKey: "invoice.payment_method", iconData: FontAwesome.money, display: (u) => u.name, - selectedValue: _invoice.paymentMethod, + selectedValue: _invoice!.paymentMethod, values: paymentMethodModel.paymentMethods, ); final invoiceTableBox = InvoiceTable( - invoice: _invoice, + invoice: _invoice!, rate: rate, deliveryFeeSelected: (selected) { setState(() { if (selected) { - _invoice.deliveryFee = rate.deliveryFee; + _invoice!.deliveryFee = rate.deliveryFee; } else { - _invoice.deliveryFee = 0; + _invoice!.deliveryFee = 0; } }); }, discountSelected: (discount) { setState(() { - _invoice.discount = discount; + _invoice!.discount = discount; }); }, onRemove: (i) { @@ -189,12 +189,12 @@ class _InvoiceEditorState extends State { } if (i.invoiceDataType == InvoiceDataType.DiscountDataType) { setState(() { - _invoice.discount = null; + _invoice!.discount = new Discount(); }); } if (i.invoiceDataType == InvoiceDataType.DeliveryFeeType) { setState(() { - _invoice.deliveryFee = 0; + _invoice!.deliveryFee = 0; }); } if (i.invoiceDataType == InvoiceDataType.HandlingFeeType) { @@ -254,7 +254,7 @@ class _InvoiceEditorState extends State { Shipment shipment = await Navigator.of(context).push( CupertinoPageRoute( builder: (context) => - InvoiceHandlingFeeList(shipments: _invoice.shipments))); + InvoiceHandlingFeeList(shipments: _invoice!.shipments))); _addShipment(shipment); } else if (p.id == 3) { Discount discount = @@ -264,12 +264,12 @@ class _InvoiceEditorState extends State { ))); if (discount != null) { setState(() { - _invoice.discount = discount; + _invoice!.discount = discount; }); } } else if (p.id == 4) { setState(() { - _invoice.deliveryFee = rate.deliveryFee; + _invoice!.deliveryFee = rate.deliveryFee; }); } }, @@ -281,7 +281,7 @@ class _InvoiceEditorState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(dateFormatter.format(_invoice.invoiceDate)), + Text(dateFormatter.format(_invoice!.invoiceDate)), SizedBox( height: 10, ), @@ -371,8 +371,8 @@ class _InvoiceEditorState extends State { _addCustom(CustomDuty customDuty) { if (customDuty == null) return; setState(() { - _invoice.customDuties.remove(customDuty); - _invoice.customDuties.add(customDuty); + _invoice!.customDuties.remove(customDuty); + _invoice!.customDuties.add(customDuty); }); } @@ -380,8 +380,8 @@ class _InvoiceEditorState extends State { if (shipment == null) return; shipment.isSelected = true; setState(() { - _invoice.shipments.remove(shipment); - _invoice.shipments.add(shipment); + _invoice!.shipments.remove(shipment); + _invoice!.shipments.add(shipment); }); } @@ -389,30 +389,30 @@ class _InvoiceEditorState extends State { if (shipment == null) return; shipment.isSelected = false; setState(() { - _invoice.shipments.remove(shipment); - _invoice.shipments.add(shipment); + _invoice!.shipments.remove(shipment); + _invoice!.shipments.add(shipment); }); } _removeCustom(CustomDuty customDuty) { setState(() { - _invoice.customDuties.remove(customDuty); + _invoice!.customDuties.remove(customDuty); }); } _save() async { var rateModel = Provider.of(context, listen: false); - double amount = _invoice.getNetAmount(rateModel.rate); - if (_invoice.paymentMethod == null) { + double amount = _invoice!.getNetAmount(rateModel.rate); + if (_invoice!.paymentMethod == null) { showMsgDialog(context, "Error", "Payment method required"); return; } - List cargoTypes = _invoice.getCargoTypes(rateModel.rate); + List cargoTypes = _invoice!.getCargoTypes(rateModel.rate); if (cargoTypes == null || cargoTypes.length == 0) { showMsgDialog(context, "Error", "Expected at least one cargo type"); return; } - if ((amount ?? 0) <= 0) { + if ((amount ) <= 0) { showMsgDialog(context, "Error", "Expected positive amount"); return; } @@ -428,18 +428,18 @@ class _InvoiceEditorState extends State { Invoice invoice = Invoice(); invoice.cargoTypes = cargoTypes; invoice.amount = amount; - invoice.handlingFee = _invoice.getHandlingFee(); - invoice.cartons = _invoice.cartons.where((c) => c.isChecked).toList(); + invoice.handlingFee = _invoice!.getHandlingFee(); + invoice.cartons = _invoice!.cartons.where((c) => c.isChecked).toList(); invoice.shipments = - _invoice.shipments.where((s) => s.isSelected).toList(); - invoice.discount = _invoice.discount; - invoice.deliveryFee = _invoice.deliveryFee; + _invoice!.shipments.where((s) => s.isSelected).toList(); + invoice.discount = _invoice!.discount; + invoice.deliveryFee = _invoice!.deliveryFee; - invoice.userID = widget.customer.id; - invoice.fcsShipmentID = widget.fcsShipment.id; - invoice.invoiceDate = _invoice.invoiceDate; - invoice.paymentMethod = _invoice.paymentMethod; - invoice.customDuties = _invoice.customDuties; + invoice.userID = widget.customer!.id; + invoice.fcsShipmentID = widget.fcsShipment!.id; + invoice.invoiceDate = _invoice!.invoiceDate; + invoice.paymentMethod = _invoice!.paymentMethod; + invoice.customDuties = _invoice!.customDuties; await invoiceModel.createInvoice(invoice); Navigator.pop(context, true); diff --git a/lib/pages/invoice/editor/invoice_handling_fee_list.dart b/lib/pages/invoice/editor/invoice_handling_fee_list.dart index 9e1af8b..8f771c4 100644 --- a/lib/pages/invoice/editor/invoice_handling_fee_list.dart +++ b/lib/pages/invoice/editor/invoice_handling_fee_list.dart @@ -9,12 +9,12 @@ typedef OnAdd(Shipment shipment); typedef OnRemove(Shipment shipment); class InvoiceHandlingFeeList extends StatelessWidget { - final List shipments; - final OnAdd onAdd; - final OnRemove onRemove; + final List? shipments; + final OnAdd? onAdd; + final OnRemove? onRemove; const InvoiceHandlingFeeList( - {Key key, this.shipments, this.onAdd, this.onRemove}) + {Key? key, this.shipments, this.onAdd, this.onRemove}) : super(key: key); @override @@ -67,20 +67,19 @@ class InvoiceHandlingFeeList extends StatelessWidget { if (shipments == null) { return []; } - var rows = shipments.map((c) { + var rows = shipments!.map((c) { return MyDataRow( onSelectChanged: (value) => Navigator.pop(context, c), cells: [ MyDataCell(new Text( - c.shipmentNumber ?? "", + c.shipmentNumber, style: textStyle, )), MyDataCell( Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - Text(c.handlingFee?.toStringAsFixed(2) ?? "0", - style: textStyle), + Text(c.handlingFee.toStringAsFixed(2), style: textStyle), onRemove == null ? SizedBox( width: 50, @@ -91,7 +90,7 @@ class InvoiceHandlingFeeList extends StatelessWidget { color: primaryColor, ), onPressed: () { - if (onRemove != null) onRemove(c); + if (onRemove != null) onRemove!(c); }) ], ), diff --git a/lib/pages/invoice/invoice_customer_list.dart b/lib/pages/invoice/invoice_customer_list.dart index dfa7a61..8feee77 100644 --- a/lib/pages/invoice/invoice_customer_list.dart +++ b/lib/pages/invoice/invoice_customer_list.dart @@ -11,9 +11,9 @@ import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; class InvoiceCustomerList extends StatefulWidget { - final FcsShipment fcsShipment; + final FcsShipment? fcsShipment; - const InvoiceCustomerList({Key key, this.fcsShipment}) : super(key: key); + const InvoiceCustomerList({Key? key, this.fcsShipment}) : super(key: key); @override _InvoiceCustomerListState createState() => _InvoiceCustomerListState(); @@ -33,7 +33,7 @@ class _InvoiceCustomerListState extends State { _load() async { CustomerModel customerModel = Provider.of(context, listen: false); - var users = await customerModel.getInvoiceUsers(widget.fcsShipment.id); + var users = await customerModel.getInvoiceUsers(widget.fcsShipment!.id); setState(() { _users = users; }); @@ -88,7 +88,7 @@ class _InvoiceCustomerListState extends State { customer: customer, fcsShipment: widget.fcsShipment, ))); - if (created ?? false) { + if (created) { _load(); } }, diff --git a/lib/pages/invoice/invoice_info.dart b/lib/pages/invoice/invoice_info.dart index 8681798..e4f8777 100644 --- a/lib/pages/invoice/invoice_info.dart +++ b/lib/pages/invoice/invoice_info.dart @@ -20,8 +20,8 @@ import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; class InvoiceInfo extends StatefulWidget { - final Invoice invoice; - final bool forCustomer; + final Invoice? invoice; + final bool? forCustomer; InvoiceInfo({this.invoice, this.forCustomer}); @override @@ -31,15 +31,15 @@ class InvoiceInfo extends StatefulWidget { class _InvoiceInfoState extends State { var dateFormatter = new DateFormat('dd MMM yyyy'); - Invoice _invoice; + Invoice? _invoice; bool _isLoading = false; bool _showCartons = false; @override void initState() { super.initState(); - _invoice = widget.invoice; - _invoice.shipments?.forEach((s) { + _invoice = widget.invoice!; + _invoice!.shipments.forEach((s) { s.isSelected = true; }); _loadCartons(); @@ -54,7 +54,7 @@ class _InvoiceInfoState extends State { cartons.add(_carton); } setState(() { - _invoice.cartons = cartons; + _invoice!.cartons = cartons; }); } @@ -65,31 +65,31 @@ class _InvoiceInfoState extends State { @override Widget build(BuildContext context) { - bool isCanceled = _invoice.status == invoice_cancel_status; - bool isPaid = _invoice.status == invoice_paid_status; + bool isCanceled = _invoice!.status == invoice_cancel_status; + bool isPaid = _invoice!.status == invoice_paid_status; var rateModel = Provider.of(context); var rate = rateModel.rate; final cartonTable = InvoiceCartonTable( - cartons: _invoice.cartons, + cartons: _invoice!.cartons, rate: rate, ); final invoiceTableBox = InvoiceTable( - invoice: _invoice, + invoice: _invoice!, rate: rate, deliveryFeeSelected: (selected) { setState(() { if (selected) { - _invoice.deliveryFee = rate.deliveryFee; + _invoice!.deliveryFee = rate.deliveryFee; } else { - _invoice.deliveryFee = 0; + _invoice!.deliveryFee = 0; } }); }, discountSelected: (discount) { setState(() { - _invoice.discount = discount; + _invoice!.discount = discount; }); }, ); @@ -118,7 +118,7 @@ class _InvoiceInfoState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(dateFormatter.format(_invoice.invoiceDate)), + Text(dateFormatter.format(_invoice!.invoiceDate)), SizedBox( height: 5, ), @@ -140,7 +140,7 @@ class _InvoiceInfoState extends State { ); final paymentMethodBox = DisplayText( labelTextKey: "invoice.payment_method", - text: _invoice.paymentMethod.name, + text: _invoice!.paymentMethod.name, ); final cancelBtn = LocalButton( @@ -166,7 +166,7 @@ class _InvoiceInfoState extends State { padding: const EdgeInsets.all(8.0), child: ListView( children: [ - getInvoiceStatus(context, _invoice), + getInvoiceStatus(context, _invoice!), headerBox, _showCartons ? cartonTable : Container(), _showCartons @@ -183,7 +183,7 @@ class _InvoiceInfoState extends State { SizedBox( height: 10, ), - isCanceled || isPaid || widget.forCustomer + isCanceled || isPaid || widget.forCustomer! ? Container() : cancelBtn, ], @@ -206,7 +206,7 @@ class _InvoiceInfoState extends State { InvoiceModel invoiceModel = Provider.of(context, listen: false); - await invoiceModel.cancelInvoice(_invoice); + await invoiceModel.cancelInvoice(_invoice!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/invoice/invoice_list.dart b/lib/pages/invoice/invoice_list.dart index 6222180..cbb5ce3 100644 --- a/lib/pages/invoice/invoice_list.dart +++ b/lib/pages/invoice/invoice_list.dart @@ -12,9 +12,9 @@ import 'package:provider/provider.dart'; import 'invoice_list_row.dart'; class InvoiceList extends StatefulWidget { - final bool forCustomer; + final bool? forCustomer; - const InvoiceList({Key key, this.forCustomer}) : super(key: key); + const InvoiceList({Key? key, this.forCustomer}) : super(key: key); @override _InvoiceListState createState() => _InvoiceListState(); } @@ -29,13 +29,13 @@ class _InvoiceListState extends State { _controller.addListener(() async { if (_controller.position.pixels == _controller.position.maxScrollExtent) { Provider.of(context, listen: false) - .loadMore(isCustomer: widget.forCustomer); + .loadMore(isCustomer: widget.forCustomer!); } }); InvoiceModel invoiceModel = Provider.of(context, listen: false); - invoiceModel.initData(widget.forCustomer, true, false); + invoiceModel.initData(widget.forCustomer!, true, false); } @override @@ -66,13 +66,13 @@ class _InvoiceListState extends State { invoiceModel.selectedIndex = p.id; if (p.id == 2) { Provider.of(context, listen: false) - .initData(widget.forCustomer, false, true); + .initData(widget.forCustomer!, false, true); } else if (p.id == 3) { Provider.of(context, listen: false) - .initData(widget.forCustomer, true, false); + .initData(widget.forCustomer!, true, false); } else { Provider.of(context, listen: false) - .initData(widget.forCustomer, true, false); + .initData(widget.forCustomer!, true, false); } }), ); @@ -93,7 +93,7 @@ class _InvoiceListState extends State { color: Colors.white, fontSize: 20), actions: [popupMenu], ), - floatingActionButton: widget.forCustomer + floatingActionButton: widget.forCustomer! ? null : FloatingActionButton.extended( onPressed: () { diff --git a/lib/pages/invoice/invoice_list_row.dart b/lib/pages/invoice/invoice_list_row.dart index bc68360..3009c0d 100644 --- a/lib/pages/invoice/invoice_list_row.dart +++ b/lib/pages/invoice/invoice_list_row.dart @@ -12,9 +12,9 @@ import '../widgets/pdf_screen.dart'; class InvoiceListRow extends StatelessWidget { final dateFormatter = new DateFormat('dd MMM yyyy'); - final Invoice invoice; - final bool forCustomer; - InvoiceListRow({Key key, this.invoice, this.forCustomer}) : super(key: key); + final Invoice? invoice; + final bool? forCustomer; + InvoiceListRow({Key? key, this.invoice, this.forCustomer}) : super(key: key); @override Widget build(BuildContext context) { @@ -22,8 +22,8 @@ class InvoiceListRow extends StatelessWidget { onTap: () { Navigator.of(context).push(CupertinoPageRoute( builder: (context) => PDFScreen( - title: invoice.invoiceNumber, - url: invoice.invoiceURL, + title: invoice!.invoiceNumber, + url: invoice!.invoiceURL, ))); }, child: Row( @@ -48,17 +48,17 @@ class InvoiceListRow extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ new Text( - invoice.invoiceNumber ?? "", + invoice!.invoiceNumber ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.black), ), new Text( - invoice.status ?? "", + invoice!.status ?? "", style: new TextStyle( fontSize: 13.0, color: primaryColor), ), new Text( - dateFormatter.format(invoice.invoiceDate), + dateFormatter.format(invoice!.invoiceDate), style: new TextStyle( fontSize: 15.0, color: Colors.grey), ) @@ -70,7 +70,7 @@ class InvoiceListRow extends StatelessWidget { ), ), ), - invoice.status == invoice_issued_status + invoice!.status == invoice_issued_status ? Padding( padding: const EdgeInsets.only(left: 10.0), child: InkWell( diff --git a/lib/pages/invoice/invoice_shipment_list_row.dart b/lib/pages/invoice/invoice_shipment_list_row.dart index eb66ce6..21cf4aa 100644 --- a/lib/pages/invoice/invoice_shipment_list_row.dart +++ b/lib/pages/invoice/invoice_shipment_list_row.dart @@ -2,7 +2,7 @@ import 'package:fcs/domain/entities/fcs_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_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import '../main/util.dart'; @@ -11,8 +11,8 @@ import 'invoice_customer_list.dart'; typedef OnSelect(FcsShipment fcsShipment); class InvoiceShipmentListRow extends StatefulWidget { - final OnSelect onSelect; - final FcsShipment fcsShipment; + final OnSelect? onSelect; + final FcsShipment? fcsShipment; const InvoiceShipmentListRow({this.fcsShipment, this.onSelect}); @override @@ -28,7 +28,7 @@ class _InvoiceShipmentListRowState extends State { void initState() { super.initState(); if (widget.fcsShipment != null) { - _fcsShipment = widget.fcsShipment; + _fcsShipment = widget.fcsShipment!; } } @@ -38,7 +38,7 @@ class _InvoiceShipmentListRowState extends State { padding: EdgeInsets.only(left: 15, right: 15), child: InkWell( onTap: () { - if (widget.onSelect != null) widget.onSelect(widget.fcsShipment); + if (widget.onSelect != null) widget.onSelect!(widget.fcsShipment!); }, child: Row( children: [ diff --git a/lib/pages/invoice/invoice_table.dart b/lib/pages/invoice/invoice_table.dart index b25c222..c7b1cc7 100644 --- a/lib/pages/invoice/invoice_table.dart +++ b/lib/pages/invoice/invoice_table.dart @@ -23,11 +23,11 @@ enum InvoiceDataType { class InvoiceTableRow { final dynamic data; - final String id; - final InvoiceDataType invoiceDataType; - final String desc; - final String rate; - final String amount; + final String? id; + final InvoiceDataType? invoiceDataType; + final String? desc; + final String? rate; + final String? amount; InvoiceTableRow( {this.id, @@ -39,14 +39,14 @@ class InvoiceTableRow { } class InvoiceTable extends StatelessWidget { - final Invoice invoice; - final Rate rate; - final OnDiscountSelected discountSelected; - final OnDeliveryFeeSelected deliveryFeeSelected; - final OnRemove onRemove; + final Invoice? invoice; + final Rate? rate; + final OnDiscountSelected? discountSelected; + final OnDeliveryFeeSelected? deliveryFeeSelected; + final OnRemove? onRemove; const InvoiceTable( - {Key key, + {Key? key, this.invoice, this.discountSelected, this.deliveryFeeSelected, @@ -61,16 +61,16 @@ class InvoiceTable extends StatelessWidget { List getTableRows() { List tableRows = []; // add cargo types - List _cargoTypes = invoice.getCargoTypes(rate) ?? []; + List _cargoTypes = invoice!.getCargoTypes(rate!) ?? []; _cargoTypes.forEach((c) { tableRows.add(InvoiceTableRow( invoiceDataType: InvoiceDataType.CargoDataType, desc: c.name, rate: - "${c.calWeight.toStringAsFixed(2)} x ${c.calRate.toStringAsFixed(2)}", + "${c.calWeight!.toStringAsFixed(2)} x ${c.calRate!.toStringAsFixed(2)}", amount: "${c.calAmount.toStringAsFixed(2)}")); }); - invoice.shipments.where((ss) => (ss.isSelected ?? false)).forEach((s) { + invoice!.shipments.where((ss) => (ss.isSelected ?? false)).forEach((s) { tableRows.add(InvoiceTableRow( data: s, invoiceDataType: InvoiceDataType.HandlingFeeType, @@ -79,7 +79,7 @@ class InvoiceTable extends StatelessWidget { amount: "${s.handlingFee.toStringAsFixed(2)}")); }); // // add custom fee - invoice.customDuties.forEach((c) { + invoice!.customDuties.forEach((c) { tableRows.add(InvoiceTableRow( data: c, invoiceDataType: InvoiceDataType.CustomFeeDataType, @@ -89,18 +89,18 @@ class InvoiceTable extends StatelessWidget { }); // // add delivery fee tableRows.add(InvoiceTableRow( - data: invoice.deliveryFee == null || invoice.deliveryFee == 0 + data: invoice!.deliveryFee == null || invoice!.deliveryFee == 0 ? null - : invoice.deliveryFee, + : invoice!.deliveryFee, invoiceDataType: InvoiceDataType.DeliveryFeeType, desc: "Delivery fee", rate: "", amount: "${invoice?.deliveryFee?.toStringAsFixed(2) ?? '0'}")); // // add discounts - if (invoice.discount != null) { + if (invoice!.discount != null) { tableRows.add(InvoiceTableRow( - data: invoice.discount, + data: invoice!.discount, invoiceDataType: InvoiceDataType.DiscountDataType, desc: "Discount\n${invoice?.discount?.code ?? ""}", rate: "", @@ -132,7 +132,7 @@ class InvoiceTable extends StatelessWidget { r.data == null || onRemove == null ? Container() : InkWell( - onTap: () => onRemove(r), + onTap: () => onRemove!(r), child: Icon( Icons.remove_circle, color: Colors.black45, @@ -217,7 +217,7 @@ class InvoiceTable extends StatelessWidget { ), SizedBox(width: 20), Text( - '\$ ${invoice.getNetAmount(rate).toStringAsFixed(2)}', + '\$ ${invoice!.getNetAmount(rate!).toStringAsFixed(2)}', style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold), textAlign: TextAlign.end, ) diff --git a/lib/pages/invoice/payment/payment_page.dart b/lib/pages/invoice/payment/payment_page.dart index 680bec1..641de33 100644 --- a/lib/pages/invoice/payment/payment_page.dart +++ b/lib/pages/invoice/payment/payment_page.dart @@ -20,8 +20,8 @@ import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; class PaymentPage extends StatefulWidget { - final Invoice invoice; - final bool forCustomer; + final Invoice? invoice; + final bool? forCustomer; PaymentPage({this.invoice, this.forCustomer}); @override @@ -35,15 +35,15 @@ class _PaymentPageState extends State { Invoice _invoice = new Invoice(); bool _isLoading = false; - bool isNew; - File _file; - bool _hasBalance; + bool isNew = false; + File? _file; + bool _hasBalance = false; @override void initState() { super.initState(); - _invoice = widget.invoice; - _hasBalance = widget.invoice.balance > 0; + _invoice = widget.invoice!; + _hasBalance = widget.invoice!.balance > 0; _loadInvoice(); } @@ -129,7 +129,7 @@ class _PaymentPageState extends State { getCustomFeeRows(BuildContext context) { List dataRow = []; - dataRow = _invoice?.payments?.map((p) { + dataRow = _invoice.payments.map((p) { return Container( decoration: BoxDecoration( border: Border(bottom: BorderSide(color: Colors.grey))), @@ -165,7 +165,7 @@ class _PaymentPageState extends State { child: Column( children: [Text('\$ ${p.amount}'), Text('${p.status}')], ))), - widget.forCustomer + widget.forCustomer! ? Container() : Expanded( flex: 1, @@ -197,8 +197,7 @@ class _PaymentPageState extends State { ], ), ); - })?.toList() ?? - []; + }).toList() ; dataRow.insert( 0, @@ -217,7 +216,7 @@ class _PaymentPageState extends State { child: Text('Amount', textAlign: TextAlign.center, style: TextStyle(color: Colors.grey))), - widget.forCustomer + widget.forCustomer! ? Container() : Expanded( flex: 1, @@ -250,11 +249,11 @@ class _PaymentPageState extends State { flex: 1, child: Center( child: Text( - '\$ ${widget.invoice.balance.toStringAsFixed(2)}', + '\$ ${widget.invoice!.balance.toStringAsFixed(2)}', textAlign: TextAlign.center, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 16.0)))), - widget.forCustomer + widget.forCustomer! ? Container() : Expanded( flex: 1, @@ -279,7 +278,7 @@ class _PaymentPageState extends State { } _updatePayment(Payment payment) async { - payment.invoiceID = widget.invoice.id; + payment.invoiceID = widget.invoice!.id; setState(() { _isLoading = true; }); @@ -314,7 +313,7 @@ class _PaymentPageState extends State { try { InvoiceModel invoiceModel = Provider.of(context, listen: false); - await invoiceModel.pay(payment, _file); + await invoiceModel.pay(payment, _file!); Navigator.pop(context, true); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/invoice/payment/payment_page_edit.dart b/lib/pages/invoice/payment/payment_page_edit.dart index f751dc3..19aa12c 100644 --- a/lib/pages/invoice/payment/payment_page_edit.dart +++ b/lib/pages/invoice/payment/payment_page_edit.dart @@ -20,7 +20,7 @@ import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; class PaymentPageEdit extends StatefulWidget { - final Receipt receipt; + final Receipt? receipt; PaymentPageEdit({this.receipt}); @override @@ -33,14 +33,14 @@ class _PaymentPageEditState extends State { Receipt _receipt = new Receipt(); bool _isLoading = false; - File _file; + File? _file; - bool isNew; + bool isNew = false; @override void initState() { if (widget.receipt != null) { - _receipt = widget.receipt; + _receipt = widget.receipt!; } super.initState(); } @@ -185,11 +185,11 @@ class _PaymentPageEditState extends State { return initialImage(); } else { Widget _widget; - if (widget.receipt.fileUrl == null) { + if (widget.receipt!.fileUrl == null) { _widget = initialImage(); } else { _widget = InkWell( - child: Image.asset(widget.receipt.fileUrl, fit: BoxFit.cover), + child: Image.asset(widget.receipt!.fileUrl, fit: BoxFit.cover), onTap: () {}, ); } @@ -209,13 +209,13 @@ class _PaymentPageEditState extends State { Widget enableUpload(BuildContext context) { return InkWell( - child: Image.file(_file, fit: BoxFit.cover), + child: Image.file(_file!, fit: BoxFit.cover), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => - ShowImage(imageFile: _file, url: null, fileName: 'image'))); + ShowImage(imageFile: _file!, url: '', fileName: 'image'))); }, ); } diff --git a/lib/pages/main/home_page.dart b/lib/pages/main/home_page.dart index 48080c8..d1dcf98 100644 --- a/lib/pages/main/home_page.dart +++ b/lib/pages/main/home_page.dart @@ -36,7 +36,7 @@ import 'package:fcs/pages/widgets/right_left_page_rout.dart'; import 'package:fcs/pages/widgets/task_button.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_icons/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:logging/logging.dart'; @@ -94,7 +94,7 @@ class _HomePageState extends State { }); } - String notiUserID, notiUserName; + late String notiUserID, notiUserName; _showNotiContent(Map message) { try { Map map = Map.from(message["data"]); @@ -291,7 +291,7 @@ class _HomePageState extends State { final staffBtn = TaskButton( "staff.title", - icon: MaterialCommunityIcons.worker, + icon: MaterialCommunityIcons.account_tie, btnCallback: () => Navigator.of(context).push(CupertinoPageRoute( builder: (context) => StaffList(), )), @@ -350,7 +350,7 @@ class _HomePageState extends State { selectedColor: Colors.white, color: Colors.blue, children: [ - Icon(MaterialCommunityIcons.worker), + Icon(MaterialCommunityIcons.account_tie), ], onPressed: (i) => this.setState(() { isFcs[0] = !isFcs[0]; diff --git a/lib/pages/main/initial_language_selection.dart b/lib/pages/main/initial_language_selection.dart index 7d6a018..35389db 100644 --- a/lib/pages/main/initial_language_selection.dart +++ b/lib/pages/main/initial_language_selection.dart @@ -27,9 +27,9 @@ class _InitialLanguageSelectionPageState languagesList[1]: languageCodesList[1], }; - String selectedLanguage; - int selectedIndex; - bool _isLoading; + late String selectedLanguage; + late int selectedIndex; + bool _isLoading = false; @override void initState() { @@ -102,8 +102,8 @@ class _InitialLanguageSelectionPageState ? BoxDecoration() : BoxDecoration( border: Border( - bottom: - BorderSide(color: Colors.grey[300]), + bottom: BorderSide( + color: Colors.grey.shade300), ), ), child: ListTile( @@ -134,7 +134,7 @@ class _InitialLanguageSelectionPageState child: Radio( value: key, groupValue: selectedIndex, - onChanged: (int i) => + onChanged: (int? i) => _select(key, language), activeColor: primaryColor, ), @@ -178,7 +178,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/main/splash_page.dart b/lib/pages/main/splash_page.dart index eb5edfb..e719e5b 100644 --- a/lib/pages/main/splash_page.dart +++ b/lib/pages/main/splash_page.dart @@ -18,7 +18,7 @@ class _SplashScreenState extends State { bool _loaded = false; bool _isSupport = false; bool _isOnline = true; - Timer timer; + late Timer timer; startTime() async { var _duration = new Duration(milliseconds: 3000); diff --git a/lib/pages/main/util.dart b/lib/pages/main/util.dart index a6ccd3f..ca1cb18 100644 --- a/lib/pages/main/util.dart +++ b/lib/pages/main/util.dart @@ -33,7 +33,7 @@ Future showMsgDialog(BuildContext context, String title, String msg) { Future showConfirmDialog( BuildContext context, String translationKey, ok(), - {List translationVariables}) async { + {List? translationVariables}) async { await showDialog( context: context, builder: (_) { @@ -42,7 +42,7 @@ Future showConfirmDialog( child: LocalText( context, translationKey, - translationVariables: translationVariables, + translationVariables: translationVariables!, color: primaryColor, ), ), @@ -188,7 +188,7 @@ Widget getStatus(String status) { ], ) : Text( - status ?? "", + status, style: TextStyle( color: primaryColor, fontSize: 18, @@ -230,10 +230,10 @@ Widget phoneWidget(BuildContext context, String phone) { } Widget fcsInput(String label, IconData iconData, - {TextEditingController controller, - String value, + {required TextEditingController controller, + required String value, bool autoFocus = false, - TextInputType textInputType}) { + TextInputType? textInputType}) { return TextFormField( initialValue: value, controller: controller, @@ -257,7 +257,7 @@ Widget fcsInput(String label, IconData iconData, } Widget fcsInputReadOnly(String label, IconData iconData, - {TextEditingController controller, String value}) { + {required TextEditingController controller, required String value}) { return TextFormField( initialValue: value, controller: controller, @@ -279,7 +279,7 @@ Widget fcsInputReadOnly(String label, IconData iconData, } Widget fcsDropDown(String label, IconData iconData, - {TextEditingController controller}) { + {required TextEditingController controller}) { return Row( children: [ Padding( @@ -308,7 +308,7 @@ Widget _dropDown() { height: 2, color: primaryColor, ), - onChanged: (String newValue) {}, + onChanged: (String? newValue) {}, items: ['Ko Nge', 'Two', 'Free', 'Four'] .map>((String value) { return DropdownMenuItem( @@ -320,7 +320,7 @@ Widget _dropDown() { } Widget fcsButton(BuildContext context, String text, - {Function callack, IconData iconData}) { + {Function? callack, IconData? iconData}) { var languageModel = Provider.of(context); var style = languageModel.isEng @@ -344,7 +344,7 @@ Widget fcsButton(BuildContext context, String text, minWidth: 900.0, height: 100.0, child: FlatButton( - onPressed: callack, + onPressed: callack == null ? null : () => callack(), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -371,7 +371,7 @@ String getLocalString(BuildContext context, String key) { } void showToast(GlobalKey key, String text) { - final ScaffoldState scaffold = key.currentState; + final ScaffoldState scaffold = key.currentState as ScaffoldState; scaffold.showSnackBar( SnackBar( content: Text(text), diff --git a/lib/pages/main/welcome_page.dart b/lib/pages/main/welcome_page.dart index df39162..c7ca5e5 100644 --- a/lib/pages/main/welcome_page.dart +++ b/lib/pages/main/welcome_page.dart @@ -24,7 +24,7 @@ typedef BtnCallback(); class _WelcomePageState extends State { final log = Logger('_HomePageWelcomeState'); - String pin; + late String pin; List isSelected = [true, false]; @override diff --git a/lib/pages/market/market_editor.dart b/lib/pages/market/market_editor.dart index 9ab9717..92f4483 100644 --- a/lib/pages/market/market_editor.dart +++ b/lib/pages/market/market_editor.dart @@ -61,7 +61,8 @@ class _MarketEditorState extends State { appBar: AppBar( centerTitle: true, leading: new IconButton( - icon: new Icon(CupertinoIcons.back, color: primaryColor, size: 30), + icon: + new Icon(CupertinoIcons.back, color: primaryColor, size: 30), onPressed: () => Navigator.of(context).pop(), ), shadowColor: Colors.transparent, @@ -150,37 +151,39 @@ class _MarketEditorState extends State { _showDialog(BuildContext context) async { await showDialog( context: context, - child: new AlertDialog( - contentPadding: const EdgeInsets.all(16.0), - content: new Row( - children: [ - new Expanded( - child: InputText( - labelTextKey: "market.edit.name", - controller: _marketNameCtl, - autoFocus: true, - ), - ) + builder: (BuildContext context) { + return new AlertDialog( + contentPadding: const EdgeInsets.all(16.0), + content: new Row( + children: [ + new Expanded( + child: InputText( + labelTextKey: "market.edit.name", + controller: _marketNameCtl, + autoFocus: true, + ), + ) + ], + ), + actions: [ + new FlatButton( + child: LocalText(context, "btn.cancel", color: primaryColor), + onPressed: () { + Navigator.pop(context); + }), + new FlatButton( + child: LocalText( + context, + "btn.save", + color: primaryColor, + ), + onPressed: () { + Navigator.pop(context); + _add(); + }) ], - ), - actions: [ - new FlatButton( - child: LocalText(context, "btn.cancel", color: primaryColor), - onPressed: () { - Navigator.pop(context); - }), - new FlatButton( - child: LocalText( - context, - "btn.save", - color: primaryColor, - ), - onPressed: () { - Navigator.pop(context); - _add(); - }) - ], - ), + ); + }, ); } } diff --git a/lib/pages/package/package_editor.dart b/lib/pages/package/package_editor.dart index 0f488f3..231e04a 100644 --- a/lib/pages/package/package_editor.dart +++ b/lib/pages/package/package_editor.dart @@ -14,12 +14,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_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; class PackageEditorPage extends StatefulWidget { - final Package package; + final Package? package; PackageEditorPage({this.package}); @override @@ -30,17 +30,17 @@ class _PackageEditorPageState extends State { TextEditingController _remarkCtl = new TextEditingController(); TextEditingController _descCtl = new TextEditingController(); - Package _package; + Package? _package; 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; + _package = widget.package!; + selectedMarket = _package!.market; + _descCtl.text = _package!.desc; + _remarkCtl.text = _package!.remark; + multiImgController.setImageUrls = _package!.photoUrls; } final DateFormat dateFormat = DateFormat("d MMM yyyy"); @@ -51,17 +51,17 @@ class _PackageEditorPageState extends State { @override Widget build(BuildContext context) { final trackingIdBox = DisplayText( - text: _package.trackingID, + text: _package != null ? _package!.trackingID : "", labelTextKey: "package.tracking.id", iconData: MaterialCommunityIcons.barcode_scan, ); final statusBox = DisplayText( - text: _package.status, + text: _package != null ? _package!.status : "", labelTextKey: "package.edit.status", iconData: AntDesign.exclamationcircleo, ); final customerNameBox = DisplayText( - text: _package.userName, + text: _package != null ? _package!.userName : "", labelTextKey: "package.create.name", iconData: Icons.perm_identity, ); @@ -154,13 +154,13 @@ class _PackageEditorPageState extends State { ); } - String selectedMarket; + String? selectedMarket; Widget marketDropdown() { List _markets = Provider.of(context).markets; 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 Row( @@ -183,7 +183,7 @@ class _PackageEditorPageState extends State { height: 1, color: Colors.grey, ), - onChanged: (String newValue) { + onChanged: (String? newValue) { setState(() { if (newValue == MANAGE_MARKET) { selectedMarket = null; @@ -197,7 +197,7 @@ class _PackageEditorPageState extends State { items: markets.map>((String value) { return DropdownMenuItem( value: value, - child: Text(value ?? "", + child: Text(value, overflow: TextOverflow.ellipsis, style: TextStyle( color: value == MANAGE_MARKET @@ -229,9 +229,9 @@ class _PackageEditorPageState extends State { PackageModel packageModel = Provider.of(context, listen: false); try { - _package.desc = _descCtl.text; - _package.remark = _remarkCtl.text; - _package.market = selectedMarket; + _package!.desc = _descCtl.text; + _package!.remark = _remarkCtl.text; + _package!.market = selectedMarket!; // await packageModel.completeProcessing(_package, // multiImgController.getAddedFile, multiImgController.getDeletedUrl); Navigator.pop(context); diff --git a/lib/pages/package/package_info.dart b/lib/pages/package/package_info.dart index 3e32a2d..658059b 100644 --- a/lib/pages/package/package_info.dart +++ b/lib/pages/package/package_info.dart @@ -18,7 +18,7 @@ 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_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -27,7 +27,7 @@ final DateFormat dateFormat = DateFormat("d MMM yyyy"); class PackageInfo extends StatefulWidget { final isCustomer; final isSearchResult; - final Package package; + final Package? package; PackageInfo( {this.package, this.isSearchResult = false, this.isCustomer = false}); @@ -38,14 +38,14 @@ class PackageInfo extends StatefulWidget { class _PackageInfoState 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 pkg) async { @@ -113,21 +113,21 @@ class _PackageInfoState extends State { callBack: _return, ); final deliveryAddressBox = DefaultDeliveryAddress( - deliveryAddress: _package?.deliveryAddress, + deliveryAddress: _package!.deliveryAddress, labelKey: "package.delivery.address", onTap: owner && canChangeDeliveryAddress ? () async { - DeliveryAddress d = await Navigator.push( + DeliveryAddress? d = await Navigator.push( context, CupertinoPageRoute( builder: (context) => DeliveryAddressSelection( - deliveryAddress: _package.deliveryAddress, + deliveryAddress: _package!.deliveryAddress, user: mainModel.user)), ); if (d == null) return; _changeDeliverayAddress(d); } - : null, + : () {}, ); return LocalProgress( @@ -159,7 +159,7 @@ class _PackageInfoState extends State { widget.isSearchResult ? Container() : fcsIDBox, widget.isSearchResult ? Container() : customerNameBox, widget.isSearchResult ? Container() : marketBox, - _package == null || _package.photoUrls.length == 0 + _package == null || _package!.photoUrls.length == 0 ? Container() : img, widget.isSearchResult ? Container() : descBox, @@ -172,8 +172,8 @@ class _PackageInfoState extends State { widget.isSearchResult ? Container() : StatusTree( - shipmentHistory: _package?.shipmentHistory, - currentStatus: _package?.status), + shipmentHistory: _package!.shipmentHistory, + currentStatus: _package!.status), SizedBox( height: 20, ) @@ -197,11 +197,11 @@ class _PackageInfoState extends State { Provider.of(context, listen: false); try { - await packageModel.changeDeliveryAddress(_package, deliveryAddress); + await packageModel.changeDeliveryAddress(_package!, deliveryAddress); var da = await deliveryAddressModel.getDeliveryAddress(deliveryAddress.id); setState(() { - _package.deliveryAddress = da; + _package!.deliveryAddress = da; }); } catch (e) { showMsgDialog(context, "Error", e.toString()); @@ -223,7 +223,7 @@ class _PackageInfoState extends State { try { PackageModel packageModel = Provider.of(context, listen: false); - await packageModel.packageReturn(_package); + await packageModel.packageReturn(_package!); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/package/package_list.dart b/lib/pages/package/package_list.dart index c28ce22..d98fbcc 100644 --- a/lib/pages/package/package_list.dart +++ b/lib/pages/package/package_list.dart @@ -16,7 +16,7 @@ import 'package:provider/provider.dart'; class PackageList extends StatefulWidget { final bool forCustomer; - const PackageList({Key key, this.forCustomer = true}) : super(key: key); + const PackageList({Key? key, this.forCustomer = true}) : super(key: key); @override _PackageListState createState() => _PackageListState(); } diff --git a/lib/pages/package/package_list_row.dart b/lib/pages/package/package_list_row.dart index 76c8297..067287c 100644 --- a/lib/pages/package/package_list_row.dart +++ b/lib/pages/package/package_list_row.dart @@ -4,28 +4,31 @@ import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/package/package_info.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_icons/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; typedef CallbackPackageSelect(Package package); class PackageListRow extends StatelessWidget { final bool isCustomer; - 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"); PackageListRow( - {Key key, this.package, this.callbackPackageSelect, this.isCustomer}) + {Key? key, + this.package, + this.callbackPackageSelect, + this.isCustomer = false}) : super(key: key); @override Widget build(BuildContext context) { return InkWell( - onTap: () { + onTap: () { if (callbackPackageSelect != null) { - callbackPackageSelect(package); + callbackPackageSelect!(package!); return; } Navigator.push( @@ -57,7 +60,7 @@ 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), ), @@ -65,7 +68,7 @@ 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), ), @@ -81,12 +84,12 @@ 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), + 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 54360eb..4fe53fd 100644 --- a/lib/pages/package/package_new.dart +++ b/lib/pages/package/package_new.dart @@ -26,7 +26,7 @@ class PackageNew extends StatefulWidget { class _PackageNewState extends State { bool _isLoading = false; - User user; + User? user; List packages = []; @@ -41,7 +41,7 @@ class _PackageNewState extends State { children: [ Expanded( child: DisplayText( - text: user != null ? user.fcsID : "", + text: user != null ? user!.fcsID : "", labelTextKey: "package.create.fcs.id", icon: FcsIDIcon(), )), @@ -55,12 +55,12 @@ class _PackageNewState extends State { ], ); final namebox = DisplayText( - text: user != null ? user.name : "", + text: user != null ? user!.name : "", labelTextKey: "package.create.name", iconData: Icons.person, ); final phoneNumberBox = DisplayText( - text: user != null ? user.phoneNumber : "", + text: user != null ? user!.phoneNumber : "", labelTextKey: "package.create.phone", iconData: Icons.phone, ); @@ -144,7 +144,7 @@ class _PackageNewState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(packages[index].market ?? ""), + Text(packages[index].market), Text(packages[index].trackingID), // DisplayText( // labelText: "Tracking ID", @@ -170,7 +170,7 @@ class _PackageNewState extends State { } _addPackage() async { - Package package = await Navigator.push( + Package? package = await Navigator.push( context, CupertinoPageRoute(builder: (context) => TrackingIDPage()), ); @@ -197,7 +197,7 @@ class _PackageNewState extends State { PackageModel packageModel = Provider.of(context, listen: false); try { - await packageModel.createPackages(user, packages); + await packageModel.createPackages(user!, packages); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/package/tracking_id_page.dart b/lib/pages/package/tracking_id_page.dart index 26db8ae..b4c6644 100644 --- a/lib/pages/package/tracking_id_page.dart +++ b/lib/pages/package/tracking_id_page.dart @@ -1,4 +1,3 @@ -import 'package:barcode_scan/barcode_scan.dart'; import 'package:fcs/domain/entities/market.dart'; import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/helpers/theme.dart'; @@ -12,7 +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/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:provider/provider.dart'; @@ -20,7 +19,7 @@ const MANAGE_MARKET = "Manage Market"; const SELECT_MARKET = "Select Market"; class TrackingIDPage extends StatefulWidget { - const TrackingIDPage({Key key}) : super(key: key); + const TrackingIDPage({Key? key}) : super(key: key); @override _TrackingIDPageState createState() => _TrackingIDPageState(); } @@ -85,7 +84,7 @@ class _TrackingIDPageState extends State { ); } - String selectedMarket; + String? selectedMarket; Widget dropDown() { List _markets = Provider.of(context).markets; List markets = _markets.map((e) => e.name).toList(); @@ -112,7 +111,7 @@ class _TrackingIDPageState extends State { height: 1, color: Colors.grey, ), - onChanged: (String newValue) { + onChanged: (String? newValue) { setState(() { if (newValue == MANAGE_MARKET) { selectedMarket = null; @@ -152,17 +151,17 @@ class _TrackingIDPageState extends State { } _scan() async { - PermissionStatus permission = - await PermissionHandler().checkPermissionStatus(PermissionGroup.camera); - if (permission != PermissionStatus.granted) { - Map permissions = - await PermissionHandler() - .requestPermissions([PermissionGroup.camera]); - if (permissions[PermissionGroup.camera] != PermissionStatus.granted) { - showMsgDialog(context, "Error", "Camera permission is not granted"); - return null; - } - } + // PermissionStatus permission = + // await PermissionHandler().checkPermissionStatus(PermissionGroup.camera); + // if (permission != PermissionStatus.granted) { + // Map permissions = + // await PermissionHandler() + // .requestPermissions([PermissionGroup.camera]); + // if (permissions[PermissionGroup.camera] != PermissionStatus.granted) { + // showMsgDialog(context, "Error", "Camera permission is not granted"); + // return null; + // } + // } try { String barcode = await scanBarcode(); @@ -179,6 +178,6 @@ class _TrackingIDPageState extends State { _select() { if (_transcationIDCtl.text == "" && selectedMarket == null) return; Navigator.pop(context, - Package(trackingID: _transcationIDCtl.text, market: selectedMarket)); + Package(trackingID: _transcationIDCtl.text, market: selectedMarket!)); } } diff --git a/lib/pages/package_search/package_serach.dart b/lib/pages/package_search/package_serach.dart index 2ee5ccf..18b57ef 100644 --- a/lib/pages/package_search/package_serach.dart +++ b/lib/pages/package_search/package_serach.dart @@ -1,4 +1,3 @@ -import 'package:barcode_scan/barcode_scan.dart'; import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/main/util.dart'; @@ -6,12 +5,12 @@ import 'package:fcs/pages/package/model/package_model.dart'; import 'package:fcs/pages/package/package_list_row.dart'; import 'package:fcs/pages/widgets/barcode_scanner.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_icons/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:provider/provider.dart'; -Future searchPackage(BuildContext context, - {CallbackPackageSelect callbackPackageSelect}) async => +Future searchPackage(BuildContext context, + {CallbackPackageSelect? callbackPackageSelect}) async => await showSearch( context: context, delegate: @@ -19,7 +18,7 @@ Future searchPackage(BuildContext context, ); class PackageSearchDelegate extends SearchDelegate { - final CallbackPackageSelect callbackPackageSelect; + final CallbackPackageSelect? callbackPackageSelect; PackageSearchDelegate({this.callbackPackageSelect}); @@ -32,10 +31,10 @@ class PackageSearchDelegate 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, ); } @@ -59,7 +58,7 @@ class PackageSearchDelegate extends SearchDelegate { Widget buildLeading(BuildContext context) { return IconButton( icon: Icon(Icons.arrow_back), - onPressed: () => close(context, null), + onPressed: () => close(context, new Package()), ); } @@ -70,7 +69,7 @@ class PackageSearchDelegate extends SearchDelegate { future: packageModel.searchPackage(query), builder: (context, AsyncSnapshot> snapshot) { if (snapshot.hasData) { - if (snapshot.data.length == 0) { + if (snapshot.data!.length == 0) { return Container( child: Center( child: Text( @@ -83,7 +82,7 @@ class PackageSearchDelegate extends SearchDelegate { return Container( padding: EdgeInsets.only(top: 15), child: ListView( - children: snapshot.data + children: snapshot.data! .map((u) => PackageListRow( package: u, callbackPackageSelect: callbackPackageSelect, @@ -124,17 +123,17 @@ class PackageSearchDelegate extends SearchDelegate { } _scan(BuildContext context) async { - PermissionStatus permission = - await PermissionHandler().checkPermissionStatus(PermissionGroup.camera); - if (permission != PermissionStatus.granted) { - Map permissions = - await PermissionHandler() - .requestPermissions([PermissionGroup.camera]); - if (permissions[PermissionGroup.camera] != PermissionStatus.granted) { - showMsgDialog(context, "Error", "Camera permission is not granted"); - return null; - } - } + // PermissionStatus permission = + // await PermissionHandler().checkPermissionStatus(PermissionGroup.camera); + // if (permission != PermissionStatus.granted) { + // Map permissions = + // await PermissionHandler() + // .requestPermissions([PermissionGroup.camera]); + // if (permissions[PermissionGroup.camera] != PermissionStatus.granted) { + // showMsgDialog(context, "Error", "Camera permission is not granted"); + // return null; + // } + // } try { // PickedFile pickedFile = diff --git a/lib/pages/payment_methods/payment_method_editor.dart b/lib/pages/payment_methods/payment_method_editor.dart index 9118cdf..77cf8cb 100644 --- a/lib/pages/payment_methods/payment_method_editor.dart +++ b/lib/pages/payment_methods/payment_method_editor.dart @@ -8,20 +8,20 @@ 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_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; class PaymentMethodEditor extends StatefulWidget { - final PaymentMethod paymentMethod; + final PaymentMethod? paymentMethod; - const PaymentMethodEditor({Key key, this.paymentMethod}) : super(key: key); + const PaymentMethodEditor({Key? key, this.paymentMethod}) : super(key: key); @override _PaymentMethodEditorState createState() => _PaymentMethodEditorState(); } class _PaymentMethodEditorState extends State { bool _isLoading = false; - PaymentMethod _paymentMethod; + PaymentMethod? _paymentMethod; TextEditingController _nameController = new TextEditingController(); TextEditingController _accountNameController = new TextEditingController(); TextEditingController _accountNumberController = new TextEditingController(); @@ -29,7 +29,7 @@ class _PaymentMethodEditorState extends State { TextEditingController _phoneController = new TextEditingController(); TextEditingController _linkController = new TextEditingController(); - bool isNew; + late bool isNew; @override void initState() { @@ -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 = ''; @@ -179,7 +179,7 @@ class _PaymentMethodEditorState extends State { }); try { PaymentMethod pm = PaymentMethod( - id: _paymentMethod.id, + id: _paymentMethod!.id, name: _nameController.text, accountName: _accountNameController.text, account: _accountNumberController.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 b03e94a..4c91d3c 100644 --- a/lib/pages/payment_methods/payment_method_page.dart +++ b/lib/pages/payment_methods/payment_method_page.dart @@ -12,7 +12,7 @@ import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_icons/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; class PaymentMethodPage extends StatefulWidget { @@ -127,7 +127,7 @@ class _PaymentMethodPageState extends State { ); } - _itemRow(String text, String labelKey, {IconData iconData}) { + _itemRow(String text, String labelKey, {IconData? iconData}) { return text == null || text == "" ? Container() : Row( @@ -153,7 +153,7 @@ class _PaymentMethodPageState extends State { } void _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/processing/package_editor.dart b/lib/pages/processing/package_editor.dart index 17a7292..86da544 100644 --- a/lib/pages/processing/package_editor.dart +++ b/lib/pages/processing/package_editor.dart @@ -18,14 +18,14 @@ 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_vector_icons/flutter_vector_icons.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:provider/provider.dart'; class PackageEditor extends StatefulWidget { - final Package package; - final User consignee; - final User sender; + final Package? package; + final User? consignee; + final User? sender; PackageEditor({this.package, this.consignee, this.sender}); @override @@ -38,13 +38,13 @@ class _PackageEditorState extends State { bool _isLoading = false; MultiImgController multiImgController = MultiImgController(); - Package _package; + Package? _package; @override void initState() { super.initState(); _package = Package(); - _loadPackageData(null); + _loadPackageData(widget.package!.id); } _loadPackageData(String id) async { @@ -64,10 +64,10 @@ class _PackageEditorState extends State { } } setState(() { - 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; }); } @@ -77,7 +77,7 @@ class _PackageEditorState extends State { children: [ Expanded( child: DisplayText( - text: _package.trackingID, + text: _package!.trackingID != null ? _package!.trackingID : "", labelTextKey: "processing.tracking.id", iconData: MaterialCommunityIcons.barcode_scan, )), @@ -174,13 +174,13 @@ class _PackageEditorState extends State { ); } - String selectedMarket; + String? selectedMarket; Widget marketDropdown() { List _markets = Provider.of(context).markets; 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 Row( @@ -210,7 +210,7 @@ class _PackageEditorState extends State { height: 1, color: Colors.grey, ), - onChanged: (String newValue) { + onChanged: (String? newValue) { setState(() { if (newValue == MANAGE_MARKET) { selectedMarket = null; @@ -254,14 +254,15 @@ class _PackageEditorState extends State { PackageModel packageModel = Provider.of(context, listen: false); try { - _package.market = selectedMarket; - _package.desc = _descCtl.text; - _package.remark = _remarkCtl.text; - _package.photoFiles = multiImgController.getUpdatedFile; - _package.fcsID = widget.consignee.fcsID; - _package.senderFCSID = widget.sender?.fcsID; + _package!.market = selectedMarket!; + _package!.desc = _descCtl.text; + _package!.remark = _remarkCtl.text; + _package!.photoFiles = multiImgController.getUpdatedFile; + _package!.fcsID = widget.consignee!.fcsID; + _package!.senderFCSID = + widget.sender!.fcsID != null ? widget.sender!.fcsID : ""; - await packageModel.updateProcessing(_package, + await packageModel.updateProcessing(_package!, multiImgController.getAddedFile, multiImgController.getDeletedUrl); Navigator.pop(context, _package); diff --git a/lib/pages/processing/processing_edit_editor.dart b/lib/pages/processing/processing_edit_editor.dart index 9c3678f..c096f0b 100644 --- a/lib/pages/processing/processing_edit_editor.dart +++ b/lib/pages/processing/processing_edit_editor.dart @@ -17,12 +17,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_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; class ProcessingEditEditor extends StatefulWidget { - final Package package; + final Package? package; ProcessingEditEditor({this.package}); @override @@ -33,22 +33,22 @@ class _ProcessingEditEditorState 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"); @@ -62,7 +62,7 @@ class _ProcessingEditEditorState extends State { children: [ Expanded( child: DisplayText( - text: _user.fcsID, + text: _user!.fcsID, labelTextKey: "processing.fcs.id", icon: FcsIDIcon(), )), @@ -76,18 +76,18 @@ class _ProcessingEditEditorState 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, ); @@ -159,13 +159,13 @@ class _ProcessingEditEditorState extends State { ); } - String selectedMarket; + String? selectedMarket; Widget marketDropdown() { List _markets = Provider.of(context).markets; 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( @@ -197,7 +197,7 @@ class _ProcessingEditEditorState extends State { height: 1, color: Colors.grey, ), - onChanged: (String newValue) { + onChanged: (String? newValue) { setState(() { if (newValue == MANAGE_MARKET) { selectedMarket = null; @@ -236,7 +236,7 @@ class _ProcessingEditEditorState extends State { } _completeProcessing() async { - if (_user.fcsID == null || _user.fcsID == "") { + if (_user!.fcsID == null || _user!.fcsID == "") { showMsgDialog(context, "Error", "Expected FCS-ID"); return; } @@ -246,11 +246,11 @@ class _ProcessingEditEditorState extends State { PackageModel packageModel = Provider.of(context, listen: false); try { - _package.fcsID = _user.fcsID; - _package.desc = _descCtl.text; - _package.remark = _remarkCtl.text; - _package.market = selectedMarket; - await packageModel.updateProcessing(_package, + _package!.fcsID = _user!.fcsID; + _package!.desc = _descCtl.text; + _package!.remark = _remarkCtl.text; + _package!.market = selectedMarket!; + await packageModel.updateProcessing(_package!, multiImgController.getAddedFile, multiImgController.getDeletedUrl); Navigator.pop(context); } catch (e) { @@ -264,20 +264,20 @@ class _ProcessingEditEditorState extends State { isDataChanged() { if (isNew) { - return _user.fcsID != "" || + return _user!.fcsID != "" || selectedMarket != null || _descCtl.text != "" || _remarkCtl.text != "" || multiImgController.getAddedFile.isNotEmpty; } else { var _package = Package( - trackingID: widget.package.trackingID, - fcsID: _user.fcsID, - market: selectedMarket, + trackingID: widget.package!.trackingID, + fcsID: _user!.fcsID, + market: selectedMarket!, desc: _descCtl.text, remark: _remarkCtl.text, - photoUrls: widget.package.photoUrls); - return widget.package.isChangedForEditProcessing(_package) || + photoUrls: widget.package!.photoUrls); + return widget.package!.isChangedForEditProcessing(_package) || multiImgController.getAddedFile.isNotEmpty || multiImgController.getDeletedUrl.isNotEmpty; } diff --git a/lib/pages/processing/processing_editor.dart b/lib/pages/processing/processing_editor.dart index 3618af4..3ae2505 100644 --- a/lib/pages/processing/processing_editor.dart +++ b/lib/pages/processing/processing_editor.dart @@ -11,14 +11,14 @@ 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_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; import 'model/processing_model.dart'; import 'package_editor.dart'; class ProcesingEditor extends StatefulWidget { - final Processing processing; + final Processing? processing; const ProcesingEditor({this.processing}); @override _ProcesingEditorState createState() => _ProcesingEditorState(); @@ -27,9 +27,9 @@ class ProcesingEditor extends StatefulWidget { class _ProcesingEditorState extends State { Processing processing = Processing(); bool _isLoading = false; - bool _isNew; - User consignee; - User sender; + late bool _isNew; + User? consignee; + User? sender; List packages = []; @override @@ -37,7 +37,7 @@ class _ProcesingEditorState extends State { super.initState(); _isNew = widget.processing == null; if (!_isNew) { - processing = widget.processing; + processing = widget.processing!; consignee = User( fcsID: processing.userID, name: processing.userName, @@ -56,7 +56,7 @@ class _ProcesingEditorState extends State { children: [ Expanded( child: DisplayText( - text: consignee != null ? consignee.fcsID : "", + text: consignee != null ? consignee!.fcsID : "", labelTextKey: "processing.fcs.id", icon: FcsIDIcon(), )), @@ -71,14 +71,14 @@ class _ProcesingEditorState extends State { ); final phoneNumberBox = DisplayText( - text: consignee != null ? consignee.phoneNumber : "", + text: consignee != null ? consignee!.phoneNumber : "", labelTextKey: "processing.phone", maxLines: 2, iconData: Icons.phone, ); final namebox = DisplayText( - text: consignee != null ? consignee.name : "", + text: consignee != null ? consignee!.name : "", labelTextKey: "processing.consignee.name", maxLines: 2, iconData: Icons.person, @@ -98,7 +98,7 @@ class _ProcesingEditorState extends State { children: [ Expanded( child: DisplayText( - text: sender != null ? sender.fcsID : "", + text: sender != null ? sender!.fcsID : "", labelTextKey: "processing.fcs.id", icon: FcsIDIcon(), )), @@ -113,14 +113,14 @@ class _ProcesingEditorState extends State { ); final shipperPhoneNumberBox = DisplayText( - text: sender != null ? sender.phoneNumber : "", + text: sender != null ? sender!.phoneNumber : "", labelTextKey: "processing.phone", maxLines: 2, iconData: Icons.phone, ); final shipperNamebox = DisplayText( - text: sender != null ? sender.name : "", + text: sender != null ? sender!.name : "", labelTextKey: "processing.shipper.name", maxLines: 2, iconData: Icons.person, @@ -152,7 +152,7 @@ class _ProcesingEditorState extends State { context, "Warning", "Please select 'Consignee'"); return; } - Package _package = await Navigator.push( + Package? _package = await Navigator.push( context, CupertinoPageRoute( builder: (context) => PackageEditor( @@ -160,7 +160,7 @@ class _ProcesingEditorState extends State { consignee: this.consignee, )), ); - _addPackage(_package); + _addPackage(_package!); // _savePackage(_package); }), ], @@ -230,10 +230,10 @@ class _ProcesingEditorState extends State { return packages.map((p) { return InkWell( onTap: () async { - Package _package = await Navigator.of(context).push( + Package? _package = await Navigator.of(context).push( CupertinoPageRoute( builder: (context) => PackageInfo(package: p))); - _savePackage(_package); + _savePackage(_package!); }, child: DisplayText( labelTextKey: "processing.tracking.id", @@ -273,7 +273,7 @@ class _ProcesingEditorState extends State { if (_isNew) { await processingModel.createProcessing(processing); } else { - processing.id = widget.processing.id; + processing.id = widget.processing!.id; await processingModel.updateProcessing(processing); } Navigator.pop(context); diff --git a/lib/pages/processing/processing_info.dart b/lib/pages/processing/processing_info.dart index 735de59..39e2014 100644 --- a/lib/pages/processing/processing_info.dart +++ b/lib/pages/processing/processing_info.dart @@ -11,7 +11,7 @@ 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_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -20,7 +20,7 @@ import 'processing_edit_editor.dart'; final DateFormat dateFormat = DateFormat("d MMM yyyy"); class ProcessingInfo extends StatefulWidget { - final Package package; + final Package? package; ProcessingInfo({this.package}); @override @@ -29,14 +29,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) { @@ -54,52 +54,52 @@ class _ProcessingInfoState extends State { @override Widget build(BuildContext context) { final trackingIdBox = DisplayText( - text: _package.trackingID, + text: _package != null ? _package!.trackingID : '', labelTextKey: "processing.tracking.id", iconData: MaterialCommunityIcons.barcode_scan, ); var fcsIDBox = DisplayText( - text: _package.fcsID, + text: _package != null ? _package!.fcsID : "", labelTextKey: "processing.fcs.id", icon: FcsIDIcon(), ); final phoneNumberBox = DisplayText( - text: _package.phoneNumber, + text: _package != null ? _package!.phoneNumber : "", labelTextKey: "processing.phone", iconData: Icons.phone, ); final customerNameBox = DisplayText( - text: _package.userName, + text:_package!=null? _package!.userName:"", labelTextKey: "processing.consignee.name", iconData: Icons.perm_identity, ); var senderFcsIDBox = DisplayText( - text: _package.senderFCSID, + text:_package!=null? _package!.senderFCSID:"", labelTextKey: "processing.fcs.id", icon: FcsIDIcon(), ); final senderPhoneNumberBox = DisplayText( - text: _package.senderPhoneNumber, + text: _package!=null?_package!.senderPhoneNumber:"", labelTextKey: "processing.phone", iconData: Icons.phone, ); final senderNameBox = DisplayText( - text: _package.senderName, + text:_package!=null? _package!.senderName:"", labelTextKey: "processing.shipper.name", iconData: Icons.perm_identity, ); final marketBox = DisplayText( - text: _package.market ?? "-", + text:_package!=null? _package!.market : "-", labelTextKey: "processing.market", iconData: Icons.store, ); final descBox = DisplayText( - text: _package.desc ?? "-", + text:_package!=null? _package!.desc : "-", labelTextKey: "processing.desc", iconData: MaterialCommunityIcons.message_text_outline, ); final remarkBox = DisplayText( - text: _package.remark ?? "-", + text:_package!=null? _package!.remark : "-", labelTextKey: "processing.remark", iconData: Entypo.new_message, ); @@ -172,10 +172,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, ) @@ -199,7 +199,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()); @@ -211,7 +211,7 @@ class _ProcessingInfoState extends State { } _gotoEditor() async { - bool deleted = await Navigator.push( + bool? deleted = await Navigator.push( context, CupertinoPageRoute( builder: (context) => ProcessingEditEditor( @@ -222,7 +222,7 @@ class _ProcessingInfoState extends State { } else { PackageModel packageModel = Provider.of(context, listen: false); - Package p = await packageModel.getPackage(_package.id); + Package p = await packageModel.getPackage(_package!.id); initPackage(p); } } diff --git a/lib/pages/processing/processing_list_row.dart b/lib/pages/processing/processing_list_row.dart index cc06c16..527c621 100644 --- a/lib/pages/processing/processing_list_row.dart +++ b/lib/pages/processing/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:flutter_vector_icons/flutter_vector_icons.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( @@ -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,12 @@ 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), + 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 92fe1c8..6bf1c6f 100644 --- a/lib/pages/profile/profile_currency_edit.dart +++ b/lib/pages/profile/profile_currency_edit.dart @@ -76,9 +76,9 @@ class _ProfileCurrencyEditState extends State { activeColor: primaryColor, value: Currency.USD, groupValue: _currency, - onChanged: (Currency value) { + onChanged: (Currency? value) { setState(() { - _currency = value; + _currency = value!; }); }, ), @@ -94,9 +94,9 @@ class _ProfileCurrencyEditState extends State { activeColor: primaryColor, value: Currency.MMK, groupValue: _currency, - onChanged: (Currency value) { + onChanged: (Currency? value) { setState(() { - _currency = value; + _currency = value!; }); }, ), diff --git a/lib/pages/receiving/receiving_editor.dart b/lib/pages/receiving/receiving_editor.dart index b8ccc7a..4b0b84a 100644 --- a/lib/pages/receiving/receiving_editor.dart +++ b/lib/pages/receiving/receiving_editor.dart @@ -14,14 +14,14 @@ 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_vector_icons/flutter_vector_icons.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:provider/provider.dart'; typedef void FindCallBack(); class ReceivingEditor extends StatefulWidget { - final Package package; + final Package? package; const ReceivingEditor({this.package}); @override _ReceivingEditorState createState() => _ReceivingEditorState(); @@ -30,8 +30,8 @@ class ReceivingEditor extends StatefulWidget { class _ReceivingEditorState extends State { Package package = Package(); bool _isLoading = false; - bool _isNew; - User user; + late bool _isNew; + User? user; TextEditingController _trackingIDCtl = new TextEditingController(); TextEditingController _remarkCtl = new TextEditingController(); MultiImgController _multiImgController = MultiImgController(); @@ -41,7 +41,7 @@ class _ReceivingEditorState extends State { super.initState(); _isNew = widget.package == null; if (!_isNew) { - package = widget.package; + package = widget.package!; _trackingIDCtl.text = package.trackingID; _remarkCtl.text = package.remark; _multiImgController.setImageUrls = package.photoUrls; @@ -71,7 +71,7 @@ class _ReceivingEditorState extends State { children: [ Expanded( child: DisplayText( - text: user != null ? user.fcsID : "", + text: user != null ? user!.fcsID : "", labelTextKey: "receiving.fcs.id", icon: FcsIDIcon(), )), @@ -124,7 +124,7 @@ class _ReceivingEditorState extends State { title: "Receiving", ); final namebox = DisplayText( - text: user != null ? user.name : "", + text: user != null ? user!.name : "", labelTextKey: "receiving.consignee.name", iconData: Icons.person, ); @@ -199,17 +199,17 @@ class _ReceivingEditorState extends State { } _scan() async { - PermissionStatus permission = - await PermissionHandler().checkPermissionStatus(PermissionGroup.camera); - if (permission != PermissionStatus.granted) { - Map permissions = - await PermissionHandler() - .requestPermissions([PermissionGroup.camera]); - if (permissions[PermissionGroup.camera] != PermissionStatus.granted) { - showMsgDialog(context, "Error", "Camera permission is not granted"); - return null; - } - } + // PermissionStatus permission = + // await PermissionHandler().checkPermissionStatus(PermissionGroup.camera); + // if (permission != PermissionStatus.granted) { + // Map permissions = + // await PermissionHandler() + // .requestPermissions([PermissionGroup.camera]); + // if (permissions[PermissionGroup.camera] != PermissionStatus.granted) { + // showMsgDialog(context, "Error", "Camera permission is not granted"); + // return null; + // } + // } try { String barcode = await scanBarcode(); @@ -239,12 +239,12 @@ class _ReceivingEditorState extends State { try { if (_isNew) { await packageModel.createReceiving( - user, _p, _multiImgController.getAddedFile); + user!, _p, _multiImgController.getAddedFile); } else { - _p.id = widget.package.id; + _p.id = widget.package!.id; _p.photoUrls = package.photoUrls; await packageModel.updateReceiving( - user, + user!, _p, _multiImgController.getAddedFile, _multiImgController.getDeletedUrl); @@ -269,9 +269,9 @@ class _ReceivingEditorState extends State { var _package = Package( trackingID: _trackingIDCtl.text, remark: _remarkCtl.text, - fcsID: user.fcsID, - photoUrls: widget.package.photoUrls); - return widget.package.isChangedForEdit(_package) || + fcsID: user!.fcsID, + photoUrls: widget.package!.photoUrls); + return widget.package!.isChangedForEdit(_package) || _multiImgController.getAddedFile.isNotEmpty || _multiImgController.getDeletedUrl.isNotEmpty; } diff --git a/lib/pages/receiving/receiving_info.dart b/lib/pages/receiving/receiving_info.dart index ff5c12a..08938df 100644 --- a/lib/pages/receiving/receiving_info.dart +++ b/lib/pages/receiving/receiving_info.dart @@ -13,7 +13,7 @@ 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_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -22,7 +22,7 @@ import 'receiving_editor.dart'; final DateFormat dateFormat = DateFormat("d MMM yyyy"); class ReceivingInfo extends StatefulWidget { - final Package package; + final Package? package; ReceivingInfo({this.package}); @override @@ -30,14 +30,14 @@ class ReceivingInfo extends StatefulWidget { } class _ReceivingInfoState extends State { - Package _package; + Package? _package; bool _isLoading = false; MultiImgController multiImgController = MultiImgController(); @override void initState() { super.initState(); - initPackage(widget.package); + initPackage(widget.package!); } initPackage(Package package) { @@ -57,22 +57,22 @@ class _ReceivingInfoState extends State { bool isCustomer = Provider.of(context).isCustomer(); final trackingIdBox = DisplayText( - text: _package.trackingID, + text: _package!.trackingID, labelTextKey: "package.tracking.id", iconData: MaterialCommunityIcons.barcode_scan, ); var fcsIDBox = DisplayText( - text: _package.fcsID, + text: _package!.fcsID, labelTextKey: "processing.fcs.id", icon: FcsIDIcon(), ); final customerNameBox = DisplayText( - text: _package.userName, + text: _package!.userName, labelTextKey: "package.create.name", iconData: Icons.perm_identity, ); final remarkBox = DisplayText( - text: _package.remark ?? "-", + text: _package!.remark ?? "-", labelTextKey: "package.edit.remark", iconData: Entypo.new_message, ); @@ -123,10 +123,10 @@ class _ReceivingInfoState extends State { fcsIDBox, customerNameBox, 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, ) @@ -149,7 +149,7 @@ class _ReceivingInfoState extends State { ); PackageModel packageModel = Provider.of(context, listen: false); - var pkg = await packageModel.getPackage(widget.package.id); + var pkg = await packageModel.getPackage(widget.package!.id); initPackage(pkg); } @@ -164,7 +164,7 @@ class _ReceivingInfoState extends State { try { PackageModel packageModel = Provider.of(context, listen: false); - await packageModel.deleteReceiving(_package); + await packageModel.deleteReceiving(_package!); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); diff --git a/lib/pages/receiving/receiving_list_row.dart b/lib/pages/receiving/receiving_list_row.dart index d7a4393..fd65134 100644 --- a/lib/pages/receiving/receiving_list_row.dart +++ b/lib/pages/receiving/receiving_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:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'receiving_info.dart'; @@ -11,12 +11,12 @@ import 'receiving_info.dart'; typedef CallbackPackageSelect(Package package); class ReceivingListRow 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"); - ReceivingListRow({Key key, this.package, this.callbackPackageSelect}) + ReceivingListRow({Key? key, this.package, this.callbackPackageSelect}) : super(key: key); @override @@ -24,7 +24,7 @@ class ReceivingListRow extends StatelessWidget { return InkWell( onTap: () { if (callbackPackageSelect != null) { - callbackPackageSelect(package); + callbackPackageSelect!(package!); return; } Navigator.push( @@ -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,12 @@ 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), + dateFormat.format(package!.currentStatusDate), style: new TextStyle(fontSize: 15.0, color: Colors.grey), ), ), diff --git a/lib/pages/widgets/display_text.dart b/lib/pages/widgets/display_text.dart index 8d36a9f..1e96c08 100644 --- a/lib/pages/widgets/display_text.dart +++ b/lib/pages/widgets/display_text.dart @@ -6,16 +6,16 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class DisplayText extends StatelessWidget { - final String text; - final String labelTextKey; - final IconData iconData; - final int maxLines; - final bool withBorder; - final Color borderColor; - final Widget icon; + final String? text; + final String? labelTextKey; + final IconData? iconData; + final int? maxLines; + final bool? withBorder; + final Color? borderColor; + final Widget? icon; const DisplayText({ - Key key, + Key? key, this.text, this.labelTextKey, this.iconData, @@ -44,7 +44,9 @@ class DisplayText extends StatelessWidget { child: Row( children: [ iconData == null - ? icon == null ? Container() : icon + ? icon == null + ? Container() + : icon! : Padding( padding: const EdgeInsets.only( left: .0, right: 15.0, top: 8.0, bottom: 8.0), @@ -60,13 +62,13 @@ class DisplayText extends StatelessWidget { labelTextKey == null ? Container() : Text( - AppTranslations.of(context).text(labelTextKey), + AppTranslations.of(context).text(labelTextKey!), style: labelStyle, ), text == null ? Container() : Text( - text, + text!, style: textStyle, ), ], diff --git a/pubspec.yaml b/pubspec.yaml index 6d589fb..4eb6c3a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -49,10 +49,11 @@ dependencies: # barcode_scan: ^2.0.2 barcode_scan2: ^4.1.4 flutter_pdfview: ^1.2.1 - # flutter_local_notifications: ^8.1.1+1 + flutter_local_notifications: ^8.2.0 share: ^2.0.4 cached_network_image: ^3.1.0 flutter_cache_manager: ^3.1.2 + flutter_vector_icons: ^1.0.0 dev_dependencies: flutter_test: