From 079c9a135d836979616dd3c86b0f2847a706af12 Mon Sep 17 00:00:00 2001 From: phyothandar Date: Fri, 10 Sep 2021 14:25:37 +0630 Subject: [PATCH 1/2] null safety --- lib/pages/main/util.dart | 6 +- lib/pages/widgets/bottom_widgets.dart | 2 +- .../widgets/defalut_delivery_address.dart | 18 +++--- .../widgets/delivery_address_selection.dart | 10 ++-- lib/pages/widgets/dialog_input.dart | 12 ++-- lib/pages/widgets/discount_dropdown.dart | 16 ++--- lib/pages/widgets/display_image_source.dart | 8 +-- lib/pages/widgets/display_text.dart | 2 +- lib/pages/widgets/fcs_expansion_tile.dart | 20 +++---- lib/pages/widgets/fcs_icons.dart | 2 +- lib/pages/widgets/image_file_picker.dart | 14 ++--- lib/pages/widgets/img_url.dart | 10 ++-- lib/pages/widgets/input_date.dart | 16 ++--- lib/pages/widgets/input_text.dart | 20 +++---- lib/pages/widgets/input_time.dart | 22 +++---- lib/pages/widgets/length_picker.dart | 58 +++++++++---------- lib/pages/widgets/local_button.dart | 14 ++--- lib/pages/widgets/local_dropdown.dart | 24 ++++---- .../widgets/local_popup_menu_button.dart | 14 ++--- lib/pages/widgets/local_popupmenu.dart | 4 +- lib/pages/widgets/local_radio_buttons.dart | 20 +++---- lib/pages/widgets/local_text.dart | 32 +++++----- lib/pages/widgets/local_title.dart | 10 ++-- lib/pages/widgets/multi_img_controller.dart | 6 +- lib/pages/widgets/multi_img_file.dart | 34 +++++------ lib/pages/widgets/number_cell.dart | 4 +- lib/pages/widgets/offline_redirect.dart | 8 +-- lib/pages/widgets/pdf_screen.dart | 24 ++++---- lib/pages/widgets/popupmenu.dart | 2 +- lib/pages/widgets/progress.dart | 2 +- lib/pages/widgets/show_img.dart | 23 ++++---- 31 files changed, 230 insertions(+), 227 deletions(-) diff --git a/lib/pages/main/util.dart b/lib/pages/main/util.dart index ca1cb18..277bfe1 100644 --- a/lib/pages/main/util.dart +++ b/lib/pages/main/util.dart @@ -54,7 +54,7 @@ Future showConfirmDialog( FlatButton( color: Colors.grey[300], child: Text( - AppTranslations.of(context).text('btn.cancel'), + AppTranslations.of(context)!.text('btn.cancel'), style: Provider.of(context).isEng ? TextStyle() : TextStyle(fontFamily: 'Myanmar3'), @@ -67,7 +67,7 @@ Future showConfirmDialog( ), FlatButton( color: primaryColor, - child: Text(AppTranslations.of(context).text('btn.ok'), + child: Text(AppTranslations.of(context)!.text('btn.ok'), style: Provider.of(context).isEng ? TextStyle( color: Colors.white, @@ -367,7 +367,7 @@ Widget fcsButton(BuildContext context, String text, } String getLocalString(BuildContext context, String key) { - return AppTranslations.of(context).text(key); + return AppTranslations.of(context)!.text(key); } void showToast(GlobalKey key, String text) { diff --git a/lib/pages/widgets/bottom_widgets.dart b/lib/pages/widgets/bottom_widgets.dart index c64ff11..467630c 100644 --- a/lib/pages/widgets/bottom_widgets.dart +++ b/lib/pages/widgets/bottom_widgets.dart @@ -5,7 +5,7 @@ import 'package:fcs/pages/widgets/local_text.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; -import 'package:flutter_icons/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; class BottomWidgets extends StatelessWidget { diff --git a/lib/pages/widgets/defalut_delivery_address.dart b/lib/pages/widgets/defalut_delivery_address.dart index 649abcf..3610701 100644 --- a/lib/pages/widgets/defalut_delivery_address.dart +++ b/lib/pages/widgets/defalut_delivery_address.dart @@ -3,20 +3,20 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/delivery_address/delivery_address_row.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 'callbacks.dart'; import 'display_text.dart'; import 'local_text.dart'; class DefaultDeliveryAddress extends StatelessWidget { - final DeliveryAddress deliveryAddress; - final String labelKey; - final OnTap onTap; - final IconData iconData; + final DeliveryAddress? deliveryAddress; + final String? labelKey; + final OnTap? onTap; + final IconData? iconData; const DefaultDeliveryAddress( - {Key key, this.deliveryAddress, this.onTap, this.labelKey, this.iconData}) + {Key? key, this.deliveryAddress, this.onTap, this.labelKey, this.iconData}) : super(key: key); @override @@ -37,7 +37,7 @@ class DefaultDeliveryAddress extends StatelessWidget { onTap == null ? Container() : GestureDetector( - onTap: () => onTap(), + onTap: () => onTap!(), child: Chip( label: LocalText( context, "delivery_address.change_address", @@ -50,8 +50,8 @@ class DefaultDeliveryAddress extends StatelessWidget { child: deliveryAddress == null ? Container() : DeliveryAddressRow( - key: ValueKey(deliveryAddress.id), - deliveryAddress: deliveryAddress), + key: ValueKey(deliveryAddress!.id), + deliveryAddress: deliveryAddress!), ), ], ); diff --git a/lib/pages/widgets/delivery_address_selection.dart b/lib/pages/widgets/delivery_address_selection.dart index 08ee77f..c21a376 100644 --- a/lib/pages/widgets/delivery_address_selection.dart +++ b/lib/pages/widgets/delivery_address_selection.dart @@ -10,11 +10,11 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class DeliveryAddressSelection extends StatefulWidget { - final DeliveryAddress deliveryAddress; - final User user; + final DeliveryAddress? deliveryAddress; + final User? user; const DeliveryAddressSelection({ - Key key, + Key? key, this.deliveryAddress, this.user, }) : super(key: key); @@ -38,7 +38,7 @@ class _DeliveryAddressSelectionState extends State { Provider.of(context, listen: false); var deliveryAddresses = - await addressModel.getDeliveryAddresses(widget.user.id); + await addressModel.getDeliveryAddresses(widget.user!.id); setState(() { this._deliveryAddresses = deliveryAddresses; }); @@ -95,7 +95,7 @@ class _DeliveryAddressSelectionState extends State { padding: const EdgeInsets.all(10.0), child: Icon(Icons.check, color: widget.deliveryAddress != null && - _deliveryAddress.id == widget.deliveryAddress.id + _deliveryAddress.id == widget.deliveryAddress!.id ? primaryColor : Colors.black26), ), diff --git a/lib/pages/widgets/dialog_input.dart b/lib/pages/widgets/dialog_input.dart index 249e3a1..c1c0a4a 100644 --- a/lib/pages/widgets/dialog_input.dart +++ b/lib/pages/widgets/dialog_input.dart @@ -5,10 +5,10 @@ import 'package:flutter/material.dart'; import 'local_text.dart'; class DialogInput extends StatefulWidget { - final String value; - final String label; + final String? value; + final String? label; - const DialogInput({Key key, this.label, this.value}) : super(key: key); + const DialogInput({Key? key, this.label, this.value}) : super(key: key); @override _DialogInputState createState() => _DialogInputState(); } @@ -24,7 +24,7 @@ class _DialogInputState extends State { void initState() { super.initState(); if (widget.value != null) { - _controller.text = widget.value; + _controller.text = widget.value!; _focusNode.addListener(() { if (_focusNode.hasFocus) { _controller.selection = TextSelection( @@ -41,7 +41,7 @@ class _DialogInputState extends State { child: AlertDialog( title: LocalText( context, - widget.label, + widget.label!, fontSize: 20, color: primaryColor, ), @@ -77,7 +77,7 @@ class _DialogInputState extends State { fontWeight: FontWeight.bold, ), onPressed: () async { - if (!_formKey.currentState.validate()) return; + if (!_formKey.currentState!.validate()) return; _save(); }) ], diff --git a/lib/pages/widgets/discount_dropdown.dart b/lib/pages/widgets/discount_dropdown.dart index 63bf769..b4be510 100644 --- a/lib/pages/widgets/discount_dropdown.dart +++ b/lib/pages/widgets/discount_dropdown.dart @@ -6,13 +6,13 @@ import 'package:flutter/material.dart'; import 'local_text.dart'; class DiscountDropdown extends StatelessWidget { - final Function(T) callback; - final IconData iconData; - final T selectedValue; - final List values; + final Function(T)? callback; + final IconData? iconData; + final T? selectedValue; + final List? values; const DiscountDropdown( - {Key key, this.callback, this.iconData, this.selectedValue, this.values}) + {Key? key, this.callback, this.iconData, this.selectedValue, this.values}) : super(key: key); @override @@ -46,11 +46,11 @@ class DiscountDropdown extends StatelessWidget { height: 1, color: primaryColor, ), - onChanged: (T newValue) { - callback(newValue); + onChanged: (T? newValue) { + callback!(newValue!); }, isExpanded: true, - items: values.map>((T value) { + items: values!.map>((T value) { return DropdownMenuItem( value: value, child: Text(value == null ? "" : (value as Discount).code, diff --git a/lib/pages/widgets/display_image_source.dart b/lib/pages/widgets/display_image_source.dart index 444586d..009cde5 100644 --- a/lib/pages/widgets/display_image_source.dart +++ b/lib/pages/widgets/display_image_source.dart @@ -4,12 +4,12 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/widgets.dart'; class DisplayImageSource { - String url; - File file; + String? url; + File? file; DisplayImageSource({this.url, this.file}); - ImageProvider get imageProvider => - file == null ? CachedNetworkImageProvider(url) : FileImage(file); + ImageProvider? get imageProvider => + file == null ? CachedNetworkImageProvider(url!) : FileImage(file!); @override bool operator ==(other) { diff --git a/lib/pages/widgets/display_text.dart b/lib/pages/widgets/display_text.dart index 1e96c08..c8f8801 100644 --- a/lib/pages/widgets/display_text.dart +++ b/lib/pages/widgets/display_text.dart @@ -62,7 +62,7 @@ class DisplayText extends StatelessWidget { labelTextKey == null ? Container() : Text( - AppTranslations.of(context).text(labelTextKey!), + AppTranslations.of(context)!.text(labelTextKey!), style: labelStyle, ), text == null diff --git a/lib/pages/widgets/fcs_expansion_tile.dart b/lib/pages/widgets/fcs_expansion_tile.dart index f74365e..e1d31eb 100644 --- a/lib/pages/widgets/fcs_expansion_tile.dart +++ b/lib/pages/widgets/fcs_expansion_tile.dart @@ -5,10 +5,10 @@ import 'package:flutter/material.dart'; import 'callbacks.dart'; class FcsExpansionTile extends StatefulWidget { - final ValueChanged onExpansionChanged; - final CallBack onEditPress; - final List children; - final Widget title; + final ValueChanged? onExpansionChanged; + final CallBack? onEditPress; + final List? children; + final Widget? title; final bool isEdit; const FcsExpansionTile( {this.onExpansionChanged, @@ -21,7 +21,7 @@ class FcsExpansionTile extends StatefulWidget { } class _FcsExpansionTileState extends State { - bool expanded; + bool? expanded; @override void initState() { this.expanded = false; @@ -39,22 +39,22 @@ class _FcsExpansionTileState extends State { expanded = value; }); if (widget.onExpansionChanged != null) - widget.onExpansionChanged(value); + widget.onExpansionChanged!(value); }, - title: widget.title, - children: widget.children, + title: widget.title != null ? widget.title! : Container(), + children: widget.children != null ? widget.children! : [Container()], trailing: widget.isEdit ? IconButton( padding: EdgeInsets.all(0), iconSize: 20, onPressed: () => - widget.onEditPress != null ? widget.onEditPress() : {}, + widget.onEditPress != null ? widget.onEditPress!() : {}, icon: Icon( Icons.edit, color: primaryColor, )) : AnimatedSwitcher( - child: expanded + child: expanded! ? Icon( Icons.remove, color: primaryColor, diff --git a/lib/pages/widgets/fcs_icons.dart b/lib/pages/widgets/fcs_icons.dart index 19c844e..8f7e95b 100644 --- a/lib/pages/widgets/fcs_icons.dart +++ b/lib/pages/widgets/fcs_icons.dart @@ -1,4 +1,4 @@ -import 'package:flutter_icons/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; const cartonIconData = MaterialCommunityIcons.package; const customFeeIconData = MaterialCommunityIcons.security; diff --git a/lib/pages/widgets/image_file_picker.dart b/lib/pages/widgets/image_file_picker.dart index 8efc2f6..50dcc98 100644 --- a/lib/pages/widgets/image_file_picker.dart +++ b/lib/pages/widgets/image_file_picker.dart @@ -1,7 +1,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:flutter_icons/flutter_icons.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:image_picker/image_picker.dart'; import 'local_text.dart'; @@ -18,15 +18,15 @@ modelBottomSheet(BuildContext context, {final OnFile onFile}) { } class ImageFile extends StatefulWidget { - final OnFile onFile; + final OnFile? onFile; - const ImageFile({Key key, this.onFile}) : super(key: key); + const ImageFile({Key? key, this.onFile}) : super(key: key); @override _ImageFileState createState() => _ImageFileState(); } class _ImageFileState extends State { - File selectedFile; + File? selectedFile; @override Widget build(BuildContext context) { return Container( @@ -44,7 +44,7 @@ class _ImageFileState extends State { onTap: () async { Navigator.pop(context); selectedFile = await pickImage(ImageSource.gallery); - if (widget.onFile != null) widget.onFile(selectedFile); + if (widget.onFile != null) widget.onFile!(selectedFile!); }), new ListTile( leading: CircleAvatar( @@ -58,7 +58,7 @@ class _ImageFileState extends State { Navigator.pop(context); selectedFile = await pickImage(ImageSource.camera); - if (widget.onFile != null) widget.onFile(selectedFile); + if (widget.onFile != null) widget.onFile!(selectedFile!); }, ), new ListTile( @@ -75,7 +75,7 @@ class _ImageFileState extends State { selectedFile = null; }); - if (widget.onFile != null) widget.onFile(selectedFile); + if (widget.onFile != null) widget.onFile!(selectedFile!); }, ), ], diff --git a/lib/pages/widgets/img_url.dart b/lib/pages/widgets/img_url.dart index 5747a5e..6cdb69e 100644 --- a/lib/pages/widgets/img_url.dart +++ b/lib/pages/widgets/img_url.dart @@ -8,10 +8,10 @@ import 'show_img.dart'; typedef OnFile = void Function(File); class ImageUrl extends StatefulWidget { - final String title; - final String url; + final String? title; + final String? url; - const ImageUrl({Key key, this.title, this.url}) : super(key: key); + const ImageUrl({Key? key, this.title, this.url}) : super(key: key); @override _ImageUrlState createState() => _ImageUrlState(); } @@ -25,12 +25,12 @@ class _ImageUrlState extends State { context, MaterialPageRoute( builder: (context) => - ShowImage(url: widget.url, fileName: widget.title)), + ShowImage(url: widget.url!, fileName: widget.title!)), ) }, child: Chip( avatar: Icon(Icons.image), - label: Text(widget.title), + label: Text(widget.title!), ), ); } diff --git a/lib/pages/widgets/input_date.dart b/lib/pages/widgets/input_date.dart index c490584..4ee726a 100644 --- a/lib/pages/widgets/input_date.dart +++ b/lib/pages/widgets/input_date.dart @@ -10,19 +10,19 @@ class InputDate extends StatelessWidget { final String labelTextKey; final IconData iconData; final TextEditingController controller; - final FormFieldValidator validator; + final FormFieldValidator? validator; final int maxLines; final bool withBorder; - final Color borderColor; - final TextInputType textInputType; + final Color? borderColor; + final TextInputType? textInputType; final bool autoFocus; final String dateFormatString; const InputDate( - {Key key, - this.labelTextKey, - this.iconData, - this.controller, + {Key? key, + required this.labelTextKey, + required this.iconData, + required this.controller, this.validator, this.maxLines = 1, this.withBorder = false, @@ -72,7 +72,7 @@ class InputDate extends StatelessWidget { ), labelText: labelTextKey == null ? null - : AppTranslations.of(context).text(labelTextKey), + : AppTranslations.of(context)!.text(labelTextKey), labelStyle: languageModel.isEng ? newLabelStyle(color: Colors.black54, fontSize: 20) : newLabelStyleMM(color: Colors.black54, fontSize: 20), diff --git a/lib/pages/widgets/input_text.dart b/lib/pages/widgets/input_text.dart index c94d3ab..639d4b0 100644 --- a/lib/pages/widgets/input_text.dart +++ b/lib/pages/widgets/input_text.dart @@ -6,20 +6,20 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class InputText extends StatelessWidget { - final String labelTextKey; - final IconData iconData; - final TextEditingController controller; - final FormFieldValidator validator; + final String? labelTextKey; + final IconData? iconData; + final TextEditingController? controller; + final FormFieldValidator? validator; final int maxLines; final bool withBorder; - final Color borderColor; - final TextInputType textInputType; + final Color? borderColor; + final TextInputType? textInputType; final bool autoFocus; final TextAlign textAlign; final bool enabled; const InputText( - {Key key, + {Key? key, this.labelTextKey, this.iconData, this.controller, @@ -30,7 +30,7 @@ class InputText extends StatelessWidget { this.autoFocus = false, this.textInputType, this.enabled = true, - this.textAlign}) + this.textAlign = TextAlign.start}) : super(key: key); @override Widget build(BuildContext context) { @@ -46,7 +46,7 @@ class InputText extends StatelessWidget { style: textStyle, maxLines: maxLines, keyboardType: textInputType, - textAlign: textAlign ?? TextAlign.start, + textAlign: textAlign, decoration: new InputDecoration( // hintText: '', hintStyle: TextStyle( @@ -54,7 +54,7 @@ class InputText extends StatelessWidget { ), labelText: labelTextKey == null ? null - : AppTranslations.of(context).text(labelTextKey), + : AppTranslations.of(context)!.text(labelTextKey!), labelStyle: languageModel.isEng ? newLabelStyle(color: Colors.black54, fontSize: 20) : newLabelStyleMM(color: Colors.black54, fontSize: 20), diff --git a/lib/pages/widgets/input_time.dart b/lib/pages/widgets/input_time.dart index 1311bf6..8c283a1 100644 --- a/lib/pages/widgets/input_time.dart +++ b/lib/pages/widgets/input_time.dart @@ -7,18 +7,18 @@ import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; class InputTime extends StatelessWidget { - final String labelTextKey; - final IconData iconData; - final TextEditingController controller; - final FormFieldValidator validator; + final String? labelTextKey; + final IconData? iconData; + final TextEditingController? controller; + final FormFieldValidator? validator; final int maxLines; final bool withBorder; - final Color borderColor; - final TextInputType textInputType; + final Color? borderColor; + final TextInputType? textInputType; final bool autoFocus; const InputTime( - {Key key, + {Key? key, this.labelTextKey, this.iconData, this.controller, @@ -45,14 +45,14 @@ class InputTime extends StatelessWidget { try { final format = DateFormat.jm(); //"6:00 AM" initialDate = - TimeOfDay.fromDateTime(format.parse(controller.text)); + TimeOfDay.fromDateTime(format.parse(controller!.text)); // var values = controller.text.split(":"); // initialDate = TimeOfDay( // hour: int.parse(values[0]), minute: int.parse(values[1])); } catch (e) {} // ignore error } - TimeOfDay t = await showTimePicker( + TimeOfDay? t = await showTimePicker( initialTime: initialDate, context: context, ); @@ -61,7 +61,7 @@ class InputTime extends StatelessWidget { final now = new DateTime.now(); final dt = DateTime(now.year, now.month, now.day, t.hour, t.minute); - controller.text = "${format.format(dt)}"; + controller!.text = "${format.format(dt)}"; } }, controller: controller, @@ -77,7 +77,7 @@ class InputTime extends StatelessWidget { ), labelText: labelTextKey == null ? null - : AppTranslations.of(context).text(labelTextKey), + : AppTranslations.of(context)!.text(labelTextKey!), labelStyle: languageModel.isEng ? newLabelStyle(color: Colors.black54, fontSize: 20) : newLabelStyleMM(color: Colors.black54, fontSize: 20), diff --git a/lib/pages/widgets/length_picker.dart b/lib/pages/widgets/length_picker.dart index fe298c8..f39ba00 100644 --- a/lib/pages/widgets/length_picker.dart +++ b/lib/pages/widgets/length_picker.dart @@ -10,13 +10,13 @@ const MAX_INC = 50.0; const MAX_FEET = 25.0; class LengthPicker extends StatefulWidget { - final TextEditingController controller; - final String lableKey; + final TextEditingController? controller; + final String? lableKey; final bool isReadOnly; final bool displayFeet; const LengthPicker( - {Key key, + {Key? key, this.controller, this.lableKey, this.isReadOnly = false, @@ -35,14 +35,14 @@ class _LengthPickerState extends State { super.initState(); if (widget.controller != null) { _setText(); - widget.controller.addListener(() { + widget.controller!.addListener(() { _setText(); }); } } _setText() { - double v = double.parse(widget.controller.text, (s) => 0); + double v = double.parse(widget.controller!.text, (s) => 0); int _v = v.toInt(); int f = (v / 12).floor(); @@ -72,8 +72,8 @@ class _LengthPickerState extends State { context: context, builder: (BuildContext context) { return LengthPickerDialog( - controller: widget.controller, - labelKey: widget.lableKey, + controller: widget.controller!, + labelKey: widget.lableKey!, displayFeet: widget.displayFeet, ); }, @@ -82,12 +82,12 @@ class _LengthPickerState extends State { } class LengthPickerDialog extends StatefulWidget { - final TextEditingController controller; - final String labelKey; - final bool displayFeet; + final TextEditingController? controller; + final String? labelKey; + final bool? displayFeet; const LengthPickerDialog( - {Key key, this.controller, this.labelKey, this.displayFeet}) + {Key? key, this.controller, this.labelKey, this.displayFeet}) : super(key: key); @override @@ -95,8 +95,8 @@ class LengthPickerDialog extends StatefulWidget { } class _LengthPickerDialogState extends State { - int _valueFeet; - int _valueInc; + late int _valueFeet; + late int _valueInc; TextEditingController inchInputController = TextEditingController(); TextEditingController feetInputController = TextEditingController(); final _focusNode = FocusNode(); @@ -107,9 +107,9 @@ class _LengthPickerDialogState extends State { _valueFeet = 0; _valueInc = 0; if (widget.controller != null) { - double v = double.parse(widget.controller.text, (s) => 0); + double v = double.parse(widget.controller!.text, (s) => 0); _valueFeet = (v / 12).floor(); - _valueInc = widget.displayFeet ? (v % 12).toInt() : v.toInt(); + _valueInc = widget.displayFeet! ? (v % 12).toInt() : v.toInt(); inchInputController.text = _valueInc.toString(); feetInputController.text = _valueFeet.toString(); } @@ -144,7 +144,7 @@ class _LengthPickerDialogState extends State { borderSide: BorderSide(color: primaryColor, width: 1.0), ), enabledBorder: OutlineInputBorder( - borderSide: BorderSide(color: Colors.grey[400], width: 1.0), + borderSide: BorderSide(color: Colors.grey.shade400, width: 1.0), ), ), ), @@ -196,7 +196,7 @@ class _LengthPickerDialogState extends State { borderSide: BorderSide(color: primaryColor, width: 1.0), ), enabledBorder: OutlineInputBorder( - borderSide: BorderSide(color: Colors.grey[400], width: 1.0), + borderSide: BorderSide(color: Colors.grey.shade400, width: 1.0), ), ), ), @@ -233,14 +233,14 @@ class _LengthPickerDialogState extends State { title: Center( child: LocalText( context, - widget.labelKey, + widget.labelKey!, color: primaryColor, fontSize: 16, )), children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceAround, - children: widget.displayFeet + children: widget.displayFeet! ? [ Container(width: 100, child: feetBox), Container(width: 100, child: inchBox), @@ -252,7 +252,7 @@ class _LengthPickerDialogState extends State { SizedBox( height: 10, ), - widget.displayFeet + widget.displayFeet! ? Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -295,11 +295,11 @@ class _LengthPickerDialogState extends State { ), Slider( activeColor: primaryColor, - value: _valueInc.toDouble() > (widget.displayFeet ? 11 : MAX_INC) + value: _valueInc.toDouble() > (widget.displayFeet! ? 11 : MAX_INC) ? 0 : _valueInc.toDouble(), min: 0, - max: widget.displayFeet ? 11 : MAX_INC, + max: widget.displayFeet! ? 11 : MAX_INC, divisions: 100, label: (_valueInc ?? 0).round().toString(), onChanged: (double v) { @@ -318,10 +318,10 @@ class _LengthPickerDialogState extends State { }); int _v = _valueInc.round() + _valueFeet.round() * 12; if (widget.controller != null) { - widget.controller.text = _v.toString(); + widget.controller!.text = _v.toString(); } feetInputController.text = - widget.displayFeet ? _valueFeet.round().toString() : _v.toString(); + widget.displayFeet! ? _valueFeet.round().toString() : _v.toString(); } _updateInc(double v) { @@ -330,8 +330,8 @@ class _LengthPickerDialogState extends State { }); int _v = _valueInc.round() + _valueFeet.round() * 12; if (widget.controller != null) { - widget.controller.text = - widget.displayFeet ? _v.toString() : _valueInc.toString(); + widget.controller!.text = + widget.displayFeet! ? _v.toString() : _valueInc.toString(); } inchInputController.text = _valueInc.toString(); } @@ -343,8 +343,8 @@ class _LengthPickerDialogState extends State { }); int _v = _valueInc.round() + _valueFeet.round() * 12; if (widget.controller != null) { - widget.controller.text = - widget.displayFeet ? _v.toString() : _valueInc.toString(); + widget.controller!.text = + widget.displayFeet! ? _v.toString() : _valueInc.toString(); } } @@ -355,7 +355,7 @@ class _LengthPickerDialogState extends State { }); int _v = _valueInc.round() + _valueFeet.round() * 12; if (widget.controller != null) { - widget.controller.text = _v.toString(); + widget.controller!.text = _v.toString(); } } diff --git a/lib/pages/widgets/local_button.dart b/lib/pages/widgets/local_button.dart index e7d4edf..8c52eb2 100644 --- a/lib/pages/widgets/local_button.dart +++ b/lib/pages/widgets/local_button.dart @@ -6,13 +6,13 @@ import 'package:flutter/material.dart'; import 'callbacks.dart'; class LocalButton extends StatelessWidget { - final CallBack callBack; - final IconData iconData; - final String textKey; - final Color color; + final CallBack? callBack; + final IconData? iconData; + final String? textKey; + final Color? color; const LocalButton( - {Key key, + {Key? key, this.callBack, this.iconData, this.textKey, @@ -33,7 +33,7 @@ class LocalButton extends StatelessWidget { minWidth: 900.0, height: 100.0, child: FlatButton( - onPressed: callBack == null ? null : () => callBack(), + onPressed: callBack == null ? null : () => callBack!(), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -48,7 +48,7 @@ class LocalButton extends StatelessWidget { ), LocalText( context, - textKey, + textKey!, color: Colors.white, fontSize: 16, ), diff --git a/lib/pages/widgets/local_dropdown.dart b/lib/pages/widgets/local_dropdown.dart index b61c3b8..aa6eb8e 100644 --- a/lib/pages/widgets/local_dropdown.dart +++ b/lib/pages/widgets/local_dropdown.dart @@ -5,15 +5,15 @@ import 'package:flutter/material.dart'; import 'local_text.dart'; class LocalDropdown extends StatelessWidget { - final Function(T) callback; - final IconData iconData; - final T selectedValue; - final List values; - final Function(T) display; - final String labelKey; + final Function(T)? callback; + final IconData? iconData; + final T? selectedValue; + final List? values; + final Function(T)? display; + final String? labelKey; const LocalDropdown( - {Key key, + {Key? key, this.callback, this.iconData, this.selectedValue, @@ -40,7 +40,7 @@ class LocalDropdown extends StatelessWidget { padding: const EdgeInsets.only(right: 18.0), child: LocalText( context, - labelKey, + labelKey!, color: Colors.black54, fontSize: 16, ), @@ -53,20 +53,20 @@ class LocalDropdown extends StatelessWidget { height: 1, color: Colors.grey, ), - onChanged: (T newValue) { - callback(newValue); + onChanged: (T? newValue) { + callback!(newValue!); }, isExpanded: true, items: values == null ? [] - : values.map>((T value) { + : values!.map>((T value) { return DropdownMenuItem( value: value, child: Text( value == null ? "" : display != null - ? display(value) + ? display!(value) : value.toString(), overflow: TextOverflow.ellipsis, style: TextStyle(color: primaryColor)), diff --git a/lib/pages/widgets/local_popup_menu_button.dart b/lib/pages/widgets/local_popup_menu_button.dart index 53701e7..a73bb86 100644 --- a/lib/pages/widgets/local_popup_menu_button.dart +++ b/lib/pages/widgets/local_popup_menu_button.dart @@ -7,15 +7,15 @@ import 'local_popupmenu.dart'; typedef PopupMenuCallback = Function(LocalPopupMenu popupMenu); class LocalPopupMenuButton extends StatefulWidget { - final PopupMenuCallback popupMenuCallback; - final List popmenus; + final PopupMenuCallback? popupMenuCallback; + final List? popmenus; final bool multiSelect; final bool selectable; - final IconData buttonIcon; + final IconData? buttonIcon; final Color buttonColor; const LocalPopupMenuButton( - {Key key, + {Key? key, this.popupMenuCallback, this.popmenus, this.buttonIcon, @@ -29,11 +29,11 @@ class LocalPopupMenuButton extends StatefulWidget { } class _LocalPopupMenuButtonState extends State { - List popmenus; + late List popmenus; @override void initState() { - popmenus = widget.popmenus; + popmenus = widget.popmenus!; super.initState(); } @@ -64,7 +64,7 @@ class _LocalPopupMenuButtonState extends State { } } if (selected.enabled && widget.popupMenuCallback != null) - widget.popupMenuCallback(selected); + widget.popupMenuCallback!(selected); }, icon: Container( width: 30, diff --git a/lib/pages/widgets/local_popupmenu.dart b/lib/pages/widgets/local_popupmenu.dart index d3778ee..d5931b1 100644 --- a/lib/pages/widgets/local_popupmenu.dart +++ b/lib/pages/widgets/local_popupmenu.dart @@ -1,11 +1,11 @@ class LocalPopupMenu { int id; - String textKey; + String? textKey; bool selected; bool highlight; bool enabled; LocalPopupMenu( - {this.id, + {required this.id, this.textKey, this.selected = false, this.highlight = false, diff --git a/lib/pages/widgets/local_radio_buttons.dart b/lib/pages/widgets/local_radio_buttons.dart index e2b2f96..11c72ad 100644 --- a/lib/pages/widgets/local_radio_buttons.dart +++ b/lib/pages/widgets/local_radio_buttons.dart @@ -3,15 +3,15 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class LocalRadioButtons extends StatelessWidget { - final Function(T) callback; - final IconData iconData; - final T selectedValue; - final List values; + final Function(T)? callback; + final IconData? iconData; + final T? selectedValue; + final List? values; final bool readOnly; final bool hideUnselected; const LocalRadioButtons( - {Key key, + {Key? key, this.callback, this.iconData, this.selectedValue, @@ -26,19 +26,19 @@ class LocalRadioButtons extends StatelessWidget { } List getChildren() { - return values + return values! .toList() .map((e) => SizedBox( height: 30, child: InkWell( - onTap: () => callback(e), + onTap: () => callback!(e), child: Row(children: [ Radio( activeColor: primaryColor, groupValue: selectedValue, value: e, - onChanged: (T value) { - callback(value); + onChanged: (T? value) { + callback!(value!); }, ), Text(e.toString()), @@ -48,7 +48,7 @@ class LocalRadioButtons extends StatelessWidget { } List getReadonlyChildren() { - return values + return values! .toList() .map((e) => hideUnselected && e == selectedValue ? SizedBox( diff --git a/lib/pages/widgets/local_text.dart b/lib/pages/widgets/local_text.dart index c302796..92fbff8 100644 --- a/lib/pages/widgets/local_text.dart +++ b/lib/pages/widgets/local_text.dart @@ -7,26 +7,26 @@ import 'package:fcs/helpers/theme.dart'; class LocalText extends Text { final BuildContext context; LocalText(this.context, String translationKey, - {Color color, - double fontSize, - FontWeight fontWeight, - List translationVariables, - String text, + {Color? color, + double? fontSize, + FontWeight? fontWeight, + List? translationVariables, + String? text, bool underline = false}) : super( text ?? - AppTranslations.of(context).text(translationKey, + AppTranslations.of(context)!.text(translationKey, translationVariables: translationVariables), style: Provider.of(context, listen: false).isEng ? newLabelStyle( - color: color, - fontSize: fontSize, - fontWeight: fontWeight, + color: color!, + fontSize: fontSize!, + fontWeight: fontWeight!, underline: underline) : newLabelStyleMM( - color: color, - fontSize: fontSize, - fontWeight: fontWeight, + color: color!, + fontSize: fontSize!, + fontWeight: fontWeight!, underline: underline)); } @@ -35,10 +35,10 @@ class LocalLargeTitle extends Text { LocalLargeTitle( this.context, String translationKey, { - Color color, - List translationVariables, + Color? color, + List? translationVariables, }) : super( - AppTranslations.of(context).text(translationKey, + AppTranslations.of(context)!.text(translationKey, translationVariables: translationVariables), style: Provider.of(context).isEng ? TextStyle(color: color) @@ -48,7 +48,7 @@ class LocalLargeTitle extends Text { class TextLocalStyle extends Text { final BuildContext context; TextLocalStyle(this.context, String text, - {Color color, double fontSize, FontWeight fontWeight}) + {Color? color, double? fontSize, FontWeight? fontWeight}) : super(text, style: Provider.of(context).isEng ? TextStyle( diff --git a/lib/pages/widgets/local_title.dart b/lib/pages/widgets/local_title.dart index 8fc8c72..80397d3 100644 --- a/lib/pages/widgets/local_title.dart +++ b/lib/pages/widgets/local_title.dart @@ -4,10 +4,10 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class LocalTitle extends StatelessWidget { - final String textKey; - final Widget trailing; + final String? textKey; + final Widget? trailing; - const LocalTitle({Key key, this.textKey, this.trailing}) : super(key: key); + const LocalTitle({Key? key, this.textKey, this.trailing}) : super(key: key); @override Widget build(BuildContext context) { @@ -20,13 +20,13 @@ class LocalTitle extends StatelessWidget { children: [ LocalText( context, - textKey, + textKey!, fontSize: 20, fontWeight: FontWeight.bold, color: primaryColor, ), trailing != null ? Spacer() : Container(), - trailing != null ? trailing : Container() + trailing != null ? trailing! : Container() ], ), ), diff --git a/lib/pages/widgets/multi_img_controller.dart b/lib/pages/widgets/multi_img_controller.dart index 84654da..794796a 100644 --- a/lib/pages/widgets/multi_img_controller.dart +++ b/lib/pages/widgets/multi_img_controller.dart @@ -79,16 +79,16 @@ class MultiImgController { } List get getUpdatedFile { - List _addfiles = getAddedFile; + List _addfiles = getAddedFile; this.imageFiles.addAll(_addfiles); return this.imageFiles; } - List get getAddedFile { + List get getAddedFile { return addedFiles.map((e) => e.file).toList(); } - List get getDeletedUrl { + List get getDeletedUrl { return removedFiles.map((e) => e.url).toList(); } } diff --git a/lib/pages/widgets/multi_img_file.dart b/lib/pages/widgets/multi_img_file.dart index 70d7cb4..057869b 100644 --- a/lib/pages/widgets/multi_img_file.dart +++ b/lib/pages/widgets/multi_img_file.dart @@ -8,7 +8,7 @@ import 'package:fcs/pages/widgets/show_img.dart'; import 'package:fcs/pages/widgets/show_multiple_img.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:image_picker/image_picker.dart'; @@ -18,13 +18,13 @@ import 'multi_img_controller.dart'; typedef OnFile = void Function(File); class MultiImageFile extends StatefulWidget { - final String title; + final String? title; final bool enabled; final ImageSource imageSource; - final MultiImgController controller; + final MultiImgController? controller; const MultiImageFile( - {Key key, + {Key? key, this.title, this.enabled = true, this.controller, @@ -39,10 +39,10 @@ class _MultiImageFileState extends State { @override void initState() { super.initState(); - fileContainers = widget.controller.fileContainers; - widget.controller.onChange(() { + fileContainers = widget.controller!.fileContainers; + widget.controller!.onChange(() { setState(() { - this.fileContainers = widget.controller.fileContainers; + this.fileContainers = widget.controller!.fileContainers; }); }); } @@ -133,7 +133,7 @@ class _MultiImageFileState extends State { fit: BoxFit.cover, width: 50, height: 50, - imageUrl: fileContainers[index].url, + imageUrl: fileContainers[index].url!, placeholder: (context, url) => Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, @@ -150,7 +150,7 @@ class _MultiImageFileState extends State { : FittedBox( fit: BoxFit.cover, child: Image.file( - fileContainers[index].file, + fileContainers[index].file!, ), ), ), @@ -189,13 +189,13 @@ class _MultiImageFileState extends State { fileContainer.file = selectedFile; setState(() { fileContainers.add(fileContainer); - widget.controller.addFile = fileContainer; + widget.controller!.addFile = fileContainer; }); } _fileRemove(DisplayImageSource fileContainer) { setState(() { - widget.controller.removeFile = fileContainer; + widget.controller!.removeFile = fileContainer; }); } @@ -232,11 +232,11 @@ class _MultiImageFileState extends State { context, MaterialPageRoute( builder: (context) => ShowImage( - imageFile: fileContainer.file, + imageFile: fileContainer.file!, url: fileContainer.file == null - ? fileContainer.url - : null, - fileName: widget.title)), + ? fileContainer.url! + : '', + fileName: widget.title!)), ) }, child: Chip( @@ -249,7 +249,7 @@ class _MultiImageFileState extends State { deleteIcon: Icon( Icons.close, ), - label: Text(widget.title + " - ${index + 1}"), + label: Text("${widget.title}" + " - ${index + 1}"), ), ), ), @@ -308,7 +308,7 @@ class _MultiImageFileState extends State { ); } - Widget actionIcon({OnTap onTap, Color color, IconData iconData}) { + Widget actionIcon({OnTap? onTap, Color? color, IconData? iconData}) { return InkWell( onTap: onTap, child: ClipOval( diff --git a/lib/pages/widgets/number_cell.dart b/lib/pages/widgets/number_cell.dart index ec3efeb..9ec16c2 100644 --- a/lib/pages/widgets/number_cell.dart +++ b/lib/pages/widgets/number_cell.dart @@ -5,9 +5,9 @@ import 'package:fcs/helpers/theme.dart' as theme; class NumberCell extends StatelessWidget { final int number; final numberFormatter; - final TextStyle textStyle; + final TextStyle? textStyle; - NumberCell(this.number, {Key key, this.textStyle}) + NumberCell(this.number, {Key? key, this.textStyle}) : numberFormatter = new NumberFormat("#,###"), super(key: key); diff --git a/lib/pages/widgets/offline_redirect.dart b/lib/pages/widgets/offline_redirect.dart index 9e4609d..df7ec32 100644 --- a/lib/pages/widgets/offline_redirect.dart +++ b/lib/pages/widgets/offline_redirect.dart @@ -6,14 +6,14 @@ import 'package:provider/provider.dart'; class OfflineRedirect extends StatefulWidget { final Widget child; - OfflineRedirect({@required this.child}); + OfflineRedirect({required this.child}); @override _OfflineRedirectState createState() => _OfflineRedirectState(); } class _OfflineRedirectState extends State { - Timer offlineTimer; + Timer? offlineTimer; @override void initState() { @@ -27,7 +27,7 @@ class _OfflineRedirectState extends State { } _startOfflineTimer() async { - if (offlineTimer != null && offlineTimer.isActive) return; + if (offlineTimer != null && offlineTimer!.isActive) return; var _duration = new Duration(milliseconds: 500); this.offlineTimer = new Timer.periodic(_duration, offlineNav); } @@ -41,7 +41,7 @@ class _OfflineRedirectState extends State { } void dispose() { - offlineTimer.cancel(); + offlineTimer!.cancel(); super.dispose(); } diff --git a/lib/pages/widgets/pdf_screen.dart b/lib/pages/widgets/pdf_screen.dart index e9a1397..d0490c3 100644 --- a/lib/pages/widgets/pdf_screen.dart +++ b/lib/pages/widgets/pdf_screen.dart @@ -11,10 +11,10 @@ import 'package:flutter_pdfview/flutter_pdfview.dart'; import 'package:share/share.dart'; class PDFScreen extends StatefulWidget { - final String title; - final String url; + final String? title; + final String? url; - PDFScreen({Key key, this.url, this.title}) : super(key: key); + PDFScreen({Key? key, this.url, this.title}) : super(key: key); _PDFScreenState createState() => _PDFScreenState(); } @@ -33,10 +33,10 @@ class _PDFScreenState extends State with WidgetsBindingObserver { download(); } - File file; + File? file; Future download() async { try { - File f = await PdfCacheMgr.pdfs.getSingleFile(widget.url); + File f = await PdfCacheMgr.pdfs.getSingleFile(widget.url!); setState(() { file = f; }); @@ -89,23 +89,23 @@ class _PDFScreenState extends State with WidgetsBindingObserver { fitPolicy: FitPolicy.BOTH, preventLinkNavigation: false, // if set to true the link is handled in flutter - onRender: (_pages) { + onRender: (int?_pages) { print(('pages => $pages')); setState(() { - pages = _pages; + pages = _pages!; isReady = true; }); }, onViewCreated: (PDFViewController pdfViewController) { _controller.complete(pdfViewController); }, - onLinkHandler: (String uri) { + onLinkHandler: (String? uri) { print('goto uri: $uri'); }, - onPageChanged: (int page, int total) { + onPageChanged: (int? page, int? total) { print('page change: $page/$total'); setState(() { - currentPage = page; + currentPage = page!; }); }, ), @@ -116,8 +116,8 @@ class _PDFScreenState extends State with WidgetsBindingObserver { } _share() async { - final RenderBox box = context.findRenderObject(); - await Share.shareFiles([file.path], + final RenderBox box = context.findRenderObject() as RenderBox; + await Share.shareFiles([file!.path], mimeTypes: ["application/pdf"], subject: "File", sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size); diff --git a/lib/pages/widgets/popupmenu.dart b/lib/pages/widgets/popupmenu.dart index 3587571..d4092f9 100644 --- a/lib/pages/widgets/popupmenu.dart +++ b/lib/pages/widgets/popupmenu.dart @@ -1,7 +1,7 @@ class PopupMenu { int id; String status; - PopupMenu({this.id, this.status}); + PopupMenu({required this.id, required this.status}); } List menuPopup = [ diff --git a/lib/pages/widgets/progress.dart b/lib/pages/widgets/progress.dart index 9608049..df0c18d 100644 --- a/lib/pages/widgets/progress.dart +++ b/lib/pages/widgets/progress.dart @@ -4,7 +4,7 @@ import 'package:provider/provider.dart'; import 'package:fcs/helpers/theme.dart'; class LocalProgress extends Progress { - LocalProgress({bool inAsyncCall, Widget child}) + LocalProgress({required bool inAsyncCall, required Widget child}) : super( inAsyncCall: inAsyncCall, child: child, diff --git a/lib/pages/widgets/show_img.dart b/lib/pages/widgets/show_img.dart index 130cdad..191096a 100644 --- a/lib/pages/widgets/show_img.dart +++ b/lib/pages/widgets/show_img.dart @@ -6,12 +6,12 @@ import 'package:flutter/material.dart'; import 'package:photo_view/photo_view.dart'; class ShowImage extends StatefulWidget { - final String url; - final File imageFile; - final String fileName; - final String localImage; + final String? url; + final File? imageFile; + final String? fileName; + final String? localImage; const ShowImage( - {Key key, this.imageFile, this.fileName, this.url, this.localImage}) + {Key? key, this.imageFile, this.fileName, this.url, this.localImage}) : super(key: key); @override _ShowImageState createState() => _ShowImageState(); @@ -20,6 +20,13 @@ class ShowImage extends StatefulWidget { class _ShowImageState extends State { @override Widget build(BuildContext context) { + final ImageProvider? p; + if (widget.imageFile != null) { + p = FileImage(widget.imageFile!); + } else { + p = AssetImage(widget.localImage!); + } + return Scaffold( appBar: AppBar( leading: new IconButton( @@ -35,11 +42,7 @@ class _ShowImageState extends State { backgroundDecoration: const BoxDecoration( color: primaryColor, ), - imageProvider: widget.url != null - ? NetworkImage(widget.url) - : widget.imageFile != null - ? FileImage(widget.imageFile) - : AssetImage(widget.localImage), + imageProvider: widget.url != null ? NetworkImage(widget.url!) : p, minScale: PhotoViewComputedScale.contained * 1)), ); } From 7670779b03492e51e9bbefb1f27d8d8a369ff111 Mon Sep 17 00:00:00 2001 From: tzw Date: Fri, 10 Sep 2021 14:27:38 +0630 Subject: [PATCH 2/2] check null safety --- lib/data/provider/auth_fb.dart | 98 +++++++-------- lib/data/provider/carton_data_provider.dart | 13 +- lib/data/provider/package_data_provider.dart | 8 +- lib/data/provider/rate_data_provider.dart | 41 +++---- lib/data/provider/user_data_provider.dart | 18 +-- lib/data/services/auth_imp.dart | 9 +- lib/data/services/auth_service.dart | 2 +- lib/data/services/carton_imp.dart | 7 +- lib/data/services/common_imp.dart | 3 +- lib/data/services/delivery_address_imp.dart | 7 +- lib/data/services/fcs_shipment_imp.dart | 7 +- lib/data/services/invoice_imp.dart | 10 +- lib/data/services/package_imp.dart | 9 +- lib/data/services/package_service.dart | 2 +- lib/data/services/rate_imp.dart | 7 +- lib/data/services/services.dart | 23 ++-- lib/data/services/shipment_imp.dart | 7 +- lib/data/services/user_imp.dart | 9 +- lib/data/services/user_service.dart | 2 +- lib/domain/entities/auth_result.dart | 6 +- lib/domain/entities/cargo_type.dart | 26 ++-- lib/domain/entities/carton.dart | 113 +++++++++--------- lib/domain/entities/carton_size.dart | 20 +--- lib/domain/entities/custom_duty.dart | 12 +- lib/domain/entities/customer.dart | 10 +- lib/domain/entities/discount.dart | 12 +- lib/domain/entities/discount_by_weight.dart | 4 +- lib/domain/entities/faq.dart | 23 ++-- lib/domain/entities/fcs_shipment.dart | 29 ++--- lib/domain/entities/invoice.dart | 70 +++++------ lib/domain/entities/market.dart | 9 +- lib/domain/entities/package.dart | 105 ++++++++-------- lib/domain/entities/payment.dart | 18 +-- lib/domain/entities/payment_method.dart | 14 +-- lib/domain/entities/processing.dart | 16 +-- lib/domain/entities/rate.dart | 22 ++-- lib/domain/entities/receipt.dart | 10 +- lib/domain/entities/setting.dart | 35 +++--- lib/domain/entities/shipment.dart | 70 +++++------ lib/domain/entities/user.dart | 49 ++++---- lib/domain/exceiptions/server_exceptions.dart | 4 +- lib/domain/vo/contact.dart | 12 +- lib/domain/vo/delivery_address.dart | 17 +-- lib/domain/vo/message.dart | 35 +++--- lib/domain/vo/privilege.dart | 18 +-- lib/domain/vo/radio.dart | 5 - lib/domain/vo/shipment_status.dart | 14 ++- lib/domain/vo/status.dart | 9 +- lib/domain/vo/term.dart | 4 +- lib/helpers/api_helper.dart | 26 ++-- lib/helpers/dev_info.dart | 24 ++-- lib/helpers/firebase_helper.dart | 60 +++++----- lib/helpers/network_connectivity.dart | 4 +- lib/helpers/paginator.dart | 20 ++-- lib/helpers/shared_pref.dart | 14 +-- lib/helpers/theme.dart | 23 ++-- pubspec.yaml | 2 +- 57 files changed, 620 insertions(+), 626 deletions(-) delete mode 100644 lib/domain/vo/radio.dart diff --git a/lib/data/provider/auth_fb.dart b/lib/data/provider/auth_fb.dart index 15d9dc1..6062f1a 100644 --- a/lib/data/provider/auth_fb.dart +++ b/lib/data/provider/auth_fb.dart @@ -9,7 +9,7 @@ import 'package:fcs/domain/entities/user.dart'; import 'package:fcs/domain/exceiptions/signin_exception.dart'; import 'package:fcs/helpers/api_helper.dart'; import 'package:fcs/helpers/firebase_helper.dart'; -import 'package:firebase_auth/firebase_auth.dart'; +import 'package:firebase_auth/firebase_auth.dart' as fb; import 'package:logging/logging.dart'; class AuthFb { @@ -18,17 +18,17 @@ class AuthFb { static final AuthFb instance = AuthFb._(); AuthFb._(); - StreamController controller; - static final FirebaseAuth _fb = FirebaseAuth.instance; - static String _verificationId; + late StreamController controller; + static final fb.FirebaseAuth _fb = fb.FirebaseAuth.instance; + static String _verificationId = ''; Future sendSmsCodeToPhoneNumber(String phoneNumber) { Completer completer = Completer(); bool codeSentCompleted = false; - final PhoneVerificationCompleted verificationCompleted = - (AuthCredential credential) async { - AuthResult _authResult; + final fb.PhoneVerificationCompleted verificationCompleted = + (fb.AuthCredential credential) async { + fb.UserCredential _authResult; try { _authResult = await _fb.signInWithCredential(credential); print("PhoneVerificationCompleted :$_authResult"); @@ -48,23 +48,23 @@ class AuthFb { 'Inside _sendCodeToPhoneNumber: signInWithPhoneNumber auto succeeded: ${_authResult.user}'); }; - final PhoneVerificationFailed verificationFailed = - (AuthException authException) async { + final fb.PhoneVerificationFailed verificationFailed = + (fb.FirebaseAuthException authException) async { print( 'Phone number verification failed. Code: ${authException.code}. Message: ${authException.message}'); completer.completeError(SigninException( "Phone number verification failed:${authException.message}")); }; - final PhoneCodeSent codeSent = - (String verificationId, [int forceResendingToken]) async { + final fb.PhoneCodeSent codeSent = + (String verificationId, [int? forceResendingToken]) async { _verificationId = verificationId; print("codeSent " + phoneNumber); codeSentCompleted = true; completer.complete(fcs.AuthResult(authStatus: AuthStatus.SMS_SENT)); }; - final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout = + final fb.PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout = (String verificationId) { print("codeAutoRetrievalTimeout $verificationId "); @@ -89,11 +89,11 @@ class AuthFb { Future signInWithPhoneNumber(String smsCode) async { try { - final AuthCredential credential = PhoneAuthProvider.getCredential( - verificationId: _verificationId, - smsCode: smsCode, - ); - AuthResult _authResult = await _fb.signInWithCredential(credential); + final fb.AuthCredential credential = fb.PhoneAuthProvider.credential( + verificationId: _verificationId, smsCode: smsCode); + + fb.UserCredential _authResult = + await _fb.signInWithCredential(credential); if (_authResult == null) { throw SigninException("Sigin error!"); } @@ -105,19 +105,21 @@ class AuthFb { } Future signout() async { - if (userListener != null) await userListener.cancel(); + if (userListener != null) await userListener!.cancel(); return _fb.signOut(); } Future _addUserToStream({bool refreshIdToken = false}) async { - FirebaseUser firebaseUser = await _fb.currentUser(); + fb.User? firebaseUser = _fb.currentUser; if (firebaseUser == null) return null; - Map claims = await getClaims(refreshIdToken: refreshIdToken); + Map? claims = + await getClaims(refreshIdToken: refreshIdToken); log.info("Claims:$claims"); + if (claims == null) return; String cid = claims["cid"]; - User user; + User? user; if (cid != null && cid != "") { user = await _getUserFromFirestore(cid); } @@ -136,20 +138,20 @@ class AuthFb { controller.add(user); } - Future _getUserFromFirestore(String userID) async { - DocumentSnapshot snap = await Firestore.instance + Future _getUserFromFirestore(String userID) async { + DocumentSnapshot snap = await FirebaseFirestore.instance .collection(user_collection) - .document(userID) + .doc(userID) .get(); if (snap.exists) { - User user = User.fromMap(snap.data, snap.documentID); + User user = User.fromMap(snap.data() as Map, snap.id); return user; } return null; } Future isLogin() async { - final FirebaseUser firebaseUser = await _fb.currentUser(); + final fb.User? firebaseUser = _fb.currentUser; return Future.value(firebaseUser != null); } @@ -193,48 +195,50 @@ class AuthFb { } Stream settings() async* { - Stream snapshot = Firestore.instance + Stream snapshot = FirebaseFirestore.instance .collection(config_collection) - .document(setting_doc_id) + .doc(setting_doc_id) .snapshots(); await for (var snap in snapshot) { - Setting setting = Setting.fromMap(snap.data); + Setting setting = Setting.fromMap(snap.data() as Map); yield setting; } } - Future _getCurrentUserID() async { - FirebaseUser firebaseUser = await _fb.currentUser(); + Future _getCurrentUserID() async { + fb.User? firebaseUser = _fb.currentUser; if (firebaseUser == null) return null; - Map claims = await getClaims(); + Map? claims = await getClaims(); + if (claims == null) return null; String cid = claims["cid"]; return cid; } Future _startUserListener() async { - if (userListener != null) userListener.cancel(); - String _userID = await _getCurrentUserID(); + if (userListener != null) userListener!.cancel(); + String? _userID = await _getCurrentUserID(); if (_userID == null) { return; } - Stream snapshot = Firestore.instance + Stream snapshot = FirebaseFirestore.instance .collection(user_collection) - .document(_userID) + .doc(_userID) .snapshots(); userListener = snapshot.listen((snap) async { - User user = User.fromMap(snap.data, snap.documentID); + User user = User.fromMap(snap.data() as Map, snap.id); - FirebaseUser firebaseUser = await _fb.currentUser(); + fb.User? firebaseUser = _fb.currentUser; if (firebaseUser == null) { - userListener.cancel(); + userListener?.cancel(); return; } try { // get privilege from claim - IdTokenResult idToken = await firebaseUser.getIdToken(refresh: true); - String privileges = idToken.claims["pr"]; + fb.IdTokenResult idToken = await firebaseUser.getIdTokenResult(true); + + String privileges = idToken.claims?["pr"] ?? ''; if (privileges != null && privileges != "") { user.privileges = privileges.split(":").toList(); } @@ -245,13 +249,13 @@ class AuthFb { }); } - StreamSubscription userListener; - Stream user() { + StreamSubscription? userListener; + Stream user() { // ignore: close_sinks - StreamSubscription authListener; + StreamSubscription? authListener; Future _start() async { - authListener = _fb.onAuthStateChanged.listen((firebaseUser) async { + authListener = _fb.authStateChanges().listen((firebaseUser) { if (firebaseUser == null) { controller.add(null); } else { @@ -263,10 +267,10 @@ class AuthFb { void _stop() { if (userListener != null) { - userListener.cancel(); + userListener!.cancel(); } if (authListener != null) { - authListener.cancel(); + authListener!.cancel(); } } diff --git a/lib/data/provider/carton_data_provider.dart b/lib/data/provider/carton_data_provider.dart index 7f74557..622b8c8 100644 --- a/lib/data/provider/carton_data_provider.dart +++ b/lib/data/provider/carton_data_provider.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:convert'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:fcs/domain/constants.dart'; @@ -36,7 +35,7 @@ class CartonDataProvider { } Future> searchCarton(String term) async { - if (term == null || term == '') return List(); + if (term == null || term == '') return []; // var bytes = utf8.encode(term); // var base64Str = base64.encode(bytes); @@ -45,7 +44,7 @@ class CartonDataProvider { try { String path = "/$cartons_collection"; - var querySnap = await Firestore.instance + var querySnap = await FirebaseFirestore.instance .collection(path) .where("carton_number", isEqualTo: term) .where("carton_type", @@ -53,13 +52,11 @@ class CartonDataProvider { .where("status", isEqualTo: carton_packed_status) .where("is_deleted", isEqualTo: false) .orderBy("user_name") - .getDocuments(); - return querySnap.documents - .map((e) => Carton.fromMap(e.data, e.documentID)) - .toList(); + .get(); + return querySnap.docs.map((e) => Carton.fromMap(e.data(), e.id)).toList(); } catch (e) { log.warning("carton error:" + e.toString()); - return null; + return []; } } } diff --git a/lib/data/provider/package_data_provider.dart b/lib/data/provider/package_data_provider.dart index e0d99a2..8183eaa 100644 --- a/lib/data/provider/package_data_provider.dart +++ b/lib/data/provider/package_data_provider.dart @@ -56,8 +56,8 @@ class PackageDataProvider { token: await getToken()); } - Future> ftsSearchPackage(String term) async { - if (term == null || term == '') return List(); + Future?> ftsSearchPackage(String term) async { + if (term == null || term == '') return []; var bytes = utf8.encode(term); var base64Str = base64.encode(bytes); @@ -72,7 +72,7 @@ class PackageDataProvider { "/api/fts/$packages_collection/$escapePackage/$limit", "GET", url: Config.instance.reportURL, token: await getToken()); - if (data == null) return List(); + if (data == null) return []; data.forEach((p) { var package = Package.fromJson(p); @@ -86,7 +86,7 @@ class PackageDataProvider { } Future> searchPackage(String term) async { - if (term == null || term == '') return List(); + if (term == null || term == '') return []; List packages = []; diff --git a/lib/data/provider/rate_data_provider.dart b/lib/data/provider/rate_data_provider.dart index c8c416e..0ffc089 100644 --- a/lib/data/provider/rate_data_provider.dart +++ b/lib/data/provider/rate_data_provider.dart @@ -16,33 +16,33 @@ class RateDataProvider { static final RateDataProvider instance = RateDataProvider._(); RateDataProvider._(); - StreamController controller; + late StreamController controller; static Rate _rate = Rate(); Stream _rateStream() async* { - Stream snapshot = Firestore.instance + Stream snapshot = FirebaseFirestore.instance .collection(config_collection) - .document(rate_doc_id) + .doc(rate_doc_id) .snapshots(); await for (var snap in snapshot) { - Rate rate = Rate.fromMap(snap.data); + Rate rate = Rate.fromMap(snap.data() as Map); yield rate; } } Stream> _cargoTypeStream() async* { List cargoTypes = []; - Stream snapshots = Firestore.instance + Stream snapshots = FirebaseFirestore.instance .collection(config_collection) - .document(rate_doc_id) + .doc(rate_doc_id) .collection(cargo_types_collection) .where("custom_duty", isEqualTo: false) .snapshots(); await for (var snaps in snapshots) { cargoTypes = []; - cargoTypes = snaps.documents.map((snap) { - return CargoType.fromMap(snap.data, snap.documentID); + cargoTypes = snaps.docs.map((snap) { + return CargoType.fromMap(snap.data() as Map, snap.id); }).toList(); yield cargoTypes; @@ -51,17 +51,17 @@ class RateDataProvider { Stream> _customDutiesStream() async* { List customDuries = []; - Stream snapshots = Firestore.instance + Stream snapshots = FirebaseFirestore.instance .collection(config_collection) - .document(rate_doc_id) + .doc(rate_doc_id) .collection(cargo_types_collection) .where("custom_duty", isEqualTo: true) .snapshots(); await for (var snaps in snapshots) { customDuries = []; - customDuries = snaps.documents.map((snap) { - return CargoType.fromMap(snap.data, snap.documentID); + customDuries = snaps.docs.map((snap) { + return CargoType.fromMap(snap.data() as Map, snap.id); }).toList(); yield customDuries; } @@ -69,25 +69,26 @@ class RateDataProvider { Stream> _discountByWeightStream() async* { List discountByWeight = []; - Stream snapshots = Firestore.instance + Stream snapshots = FirebaseFirestore.instance .collection(config_collection) - .document(rate_doc_id) + .doc(rate_doc_id) .collection(discounts_by_weights_collection) .snapshots(); await for (var snaps in snapshots) { discountByWeight = []; - discountByWeight = snaps.documents.map((snap) { - return DiscountByWeight.fromMap(snap.data, snap.documentID); + discountByWeight = snaps.docs.map((snap) { + return DiscountByWeight.fromMap( + snap.data() as Map, snap.id); }).toList(); yield discountByWeight; } } - StreamSubscription rateListener; - StreamSubscription> cargoListener; - StreamSubscription> customListener; - StreamSubscription> discountListener; + late StreamSubscription rateListener; + late StreamSubscription> cargoListener; + late StreamSubscription> customListener; + late StreamSubscription> discountListener; Stream rate() { Future _start() async { rateListener = _rateStream().listen((rate) { diff --git a/lib/data/provider/user_data_provider.dart b/lib/data/provider/user_data_provider.dart index 99ec833..3fc8394 100644 --- a/lib/data/provider/user_data_provider.dart +++ b/lib/data/provider/user_data_provider.dart @@ -37,23 +37,23 @@ class UserDataProvider { payload: {"token": token}, token: await getToken()); } - Future findUser(String phoneNumber) async { - QuerySnapshot querySnap = await Firestore.instance + Future findUser(String phoneNumber) async { + QuerySnapshot querySnap = await FirebaseFirestore.instance .collection(user_collection) .where("phone_number", isEqualTo: phoneNumber) .limit(1) - .getDocuments(); + .get(); - if (querySnap.documents.length > 0) { - var snap = querySnap.documents.first; - User user = User.fromMap(snap.data, snap.documentID); + if (querySnap.docs.length > 0) { + var snap = querySnap.docs.first; + User user = User.fromMap(snap.data() as Map, snap.id); return user; } return null; } Future> searchUser(String term) async { - if (term == null || term == '') return List(); + if (term == null || term == '') return []; var bytes = utf8.encode(term); var base64Str = base64.encode(bytes); @@ -68,7 +68,7 @@ class UserDataProvider { "/api/fts/$user_collection/$escapeBuyer/$limit", "GET", url: Config.instance.reportURL, token: await getToken()); - if (data == null) return List(); + if (data == null) return []; data.forEach((buyer) { var user = User.fromJson(buyer); @@ -76,7 +76,7 @@ class UserDataProvider { }); } catch (e) { log.warning("buyer error:" + e.toString()); - return null; + // return null; } return users; } diff --git a/lib/data/services/auth_imp.dart b/lib/data/services/auth_imp.dart index 05b36ec..056907f 100644 --- a/lib/data/services/auth_imp.dart +++ b/lib/data/services/auth_imp.dart @@ -3,17 +3,16 @@ import 'package:fcs/domain/entities/auth_result.dart'; import 'package:fcs/domain/entities/connectivity.dart'; import 'package:fcs/domain/entities/setting.dart'; import 'package:fcs/domain/entities/user.dart'; -import 'package:flutter/material.dart'; import 'auth_service.dart'; class AuthServiceImp implements AuthService { AuthServiceImp({ - @required this.authFb, - @required this.connectivity, + required this.authFb, + required this.connectivity, }); - final Connectivity connectivity; + final Connectivity? connectivity; final AuthFb authFb; @override @@ -32,7 +31,7 @@ class AuthServiceImp implements AuthService { } @override - Stream getUserStream() { + Stream getUserStream() { return authFb.user(); } diff --git a/lib/data/services/auth_service.dart b/lib/data/services/auth_service.dart index dad8ce7..a276495 100644 --- a/lib/data/services/auth_service.dart +++ b/lib/data/services/auth_service.dart @@ -11,6 +11,6 @@ abstract class AuthService { Future updateProfileName(String newUserName); Future updatePreferredCurrency(String currency); Future hasInvite(); - Stream getUserStream(); + Stream getUserStream(); Stream getSetting(); } diff --git a/lib/data/services/carton_imp.dart b/lib/data/services/carton_imp.dart index ba97084..402f48e 100644 --- a/lib/data/services/carton_imp.dart +++ b/lib/data/services/carton_imp.dart @@ -1,17 +1,16 @@ import 'package:fcs/data/provider/carton_data_provider.dart'; import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/entities/connectivity.dart'; -import 'package:flutter/material.dart'; import 'carton_service.dart'; class CartonServiceImp implements CartonService { CartonServiceImp({ - @required this.cartonDataProvider, - @required this.connectivity, + required this.cartonDataProvider, + required this.connectivity, }); - final Connectivity connectivity; + final Connectivity? connectivity; final CartonDataProvider cartonDataProvider; @override diff --git a/lib/data/services/common_imp.dart b/lib/data/services/common_imp.dart index 74e0654..cfc24e0 100644 --- a/lib/data/services/common_imp.dart +++ b/lib/data/services/common_imp.dart @@ -2,13 +2,12 @@ import 'package:fcs/data/provider/common_data_provider.dart'; import 'package:fcs/domain/entities/discount.dart'; import 'package:fcs/domain/entities/payment_method.dart'; import 'package:fcs/domain/vo/message.dart'; -import 'package:flutter/material.dart'; import 'common_service.dart'; class CommonServiceImp implements CommonService { CommonServiceImp({ - @required this.commonDataProvider, + required this.commonDataProvider, }); final CommonDataProvider commonDataProvider; diff --git a/lib/data/services/delivery_address_imp.dart b/lib/data/services/delivery_address_imp.dart index 96d8a36..d60219a 100644 --- a/lib/data/services/delivery_address_imp.dart +++ b/lib/data/services/delivery_address_imp.dart @@ -1,17 +1,16 @@ import 'package:fcs/data/provider/delivery_address_data_provider.dart'; import 'package:fcs/domain/entities/connectivity.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; -import 'package:flutter/material.dart'; import 'delivery_address_service.dart'; class DeliveryAddressImp implements DeliveryAddressService { DeliveryAddressImp({ - @required this.connectivity, - @required this.deliveryAddressDataProvider, + required this.connectivity, + required this.deliveryAddressDataProvider, }); - final Connectivity connectivity; + final Connectivity? connectivity; final DeliveryAddressDataProvider deliveryAddressDataProvider; @override diff --git a/lib/data/services/fcs_shipment_imp.dart b/lib/data/services/fcs_shipment_imp.dart index 6ffaafa..35e5071 100644 --- a/lib/data/services/fcs_shipment_imp.dart +++ b/lib/data/services/fcs_shipment_imp.dart @@ -1,17 +1,16 @@ import 'package:fcs/data/provider/fcs_shipment_data_provider.dart'; import 'package:fcs/domain/entities/connectivity.dart'; import 'package:fcs/domain/entities/fcs_shipment.dart'; -import 'package:flutter/material.dart'; import 'fcs_shipment_service.dart'; class FcsShipmentServiceImp implements FcsShipmentService { FcsShipmentServiceImp({ - @required this.connectivity, - @required this.shipmentDataProvider, + required this.connectivity, + required this.shipmentDataProvider, }); - final Connectivity connectivity; + final Connectivity? connectivity; final FcsShipmentDataProvider shipmentDataProvider; @override diff --git a/lib/data/services/invoice_imp.dart b/lib/data/services/invoice_imp.dart index c26dab4..de8e1d0 100644 --- a/lib/data/services/invoice_imp.dart +++ b/lib/data/services/invoice_imp.dart @@ -1,21 +1,17 @@ import 'package:fcs/data/provider/invoice_data_provider.dart'; -import 'package:fcs/data/provider/shipment_data_provider.dart'; -import 'package:fcs/data/services/shipment_service.dart'; import 'package:fcs/domain/entities/connectivity.dart'; import 'package:fcs/domain/entities/invoice.dart'; import 'package:fcs/domain/entities/payment.dart'; -import 'package:fcs/domain/entities/shipment.dart'; -import 'package:flutter/material.dart'; import 'invoice_service.dart'; class InvoiceServiceImp implements InvoiceService { InvoiceServiceImp({ - @required this.invoiceDataProvider, - @required this.connectivity, + required this.invoiceDataProvider, + required this.connectivity, }); - final Connectivity connectivity; + final Connectivity? connectivity; final InvoiceDataProvider invoiceDataProvider; @override diff --git a/lib/data/services/package_imp.dart b/lib/data/services/package_imp.dart index 75f0b56..f200147 100644 --- a/lib/data/services/package_imp.dart +++ b/lib/data/services/package_imp.dart @@ -1,17 +1,16 @@ import 'package:fcs/data/provider/package_data_provider.dart'; import 'package:fcs/domain/entities/connectivity.dart'; import 'package:fcs/domain/entities/package.dart'; -import 'package:flutter/material.dart'; import 'package_service.dart'; class PackageServiceImp implements PackageService { PackageServiceImp({ - @required this.connectivity, - @required this.packageDataProvider, + required this.connectivity, + required this.packageDataProvider, }); - final Connectivity connectivity; + final Connectivity? connectivity; final PackageDataProvider packageDataProvider; @override @@ -30,7 +29,7 @@ class PackageServiceImp implements PackageService { } @override - Future> ftsSearchPackage(String term) { + Future?> ftsSearchPackage(String term) { return packageDataProvider.ftsSearchPackage(term); } diff --git a/lib/data/services/package_service.dart b/lib/data/services/package_service.dart index ca00c58..2d27585 100644 --- a/lib/data/services/package_service.dart +++ b/lib/data/services/package_service.dart @@ -7,7 +7,7 @@ abstract class PackageService { Future deleteReceiving(Package package); Future updateProcessing(Package package); Future deleteProcessing(Package package); - Future> ftsSearchPackage(String term); + Future?> ftsSearchPackage(String term); Future> searchPackage(String term); Future changeDeliveryAddress(String packageID, String deliveryID); Future packageReturn(String packageID); diff --git a/lib/data/services/rate_imp.dart b/lib/data/services/rate_imp.dart index 6bea2ee..ad1d0e9 100644 --- a/lib/data/services/rate_imp.dart +++ b/lib/data/services/rate_imp.dart @@ -4,17 +4,16 @@ import 'package:fcs/domain/entities/connectivity.dart'; import 'package:fcs/domain/entities/discount_by_weight.dart'; import 'package:fcs/domain/entities/custom_duty.dart'; import 'package:fcs/domain/entities/rate.dart'; -import 'package:flutter/material.dart'; import 'rate_service.dart'; class RateServiceImp implements RateService { RateServiceImp({ - @required this.rateDataProvider, - @required this.connectivity, + required this.rateDataProvider, + required this.connectivity, }); - final Connectivity connectivity; + final Connectivity? connectivity; final RateDataProvider rateDataProvider; @override diff --git a/lib/data/services/services.dart b/lib/data/services/services.dart index aee169b..b2e15d0 100644 --- a/lib/data/services/services.dart +++ b/lib/data/services/services.dart @@ -35,17 +35,18 @@ import 'user_service.dart'; class Services { static final Services instance = Services._(); - AuthService _authService; - UserService _userService; - PackageService _packageService; - MessagingService _messagingService; - CommonService _commonService; - FcsShipmentService _fcsShipmentService; - DeliveryAddressService _deliveryAddressService; - RateService _rateService; - ShipmentService _shipmentService; - CartonService _cartonService; - InvoiceService _invoiceService; + late AuthService _authService; + late UserService _userService; + late PackageService _packageService; + late MessagingService _messagingService; + late CommonService _commonService; + late FcsShipmentService _fcsShipmentService; + late DeliveryAddressService _deliveryAddressService; + late RateService _rateService; + late ShipmentService _shipmentService; + late CartonService _cartonService; + late InvoiceService _invoiceService; + Services._() { _authService = AuthServiceImp( authFb: AuthFb.instance, diff --git a/lib/data/services/shipment_imp.dart b/lib/data/services/shipment_imp.dart index 8aeb11d..0b3a784 100644 --- a/lib/data/services/shipment_imp.dart +++ b/lib/data/services/shipment_imp.dart @@ -2,15 +2,14 @@ import 'package:fcs/data/provider/shipment_data_provider.dart'; import 'package:fcs/data/services/shipment_service.dart'; import 'package:fcs/domain/entities/connectivity.dart'; import 'package:fcs/domain/entities/shipment.dart'; -import 'package:flutter/material.dart'; class ShipmentServiceImp implements ShipmentService { ShipmentServiceImp({ - @required this.shipmentDataProvider, - @required this.connectivity, + required this.shipmentDataProvider, + required this.connectivity, }); - final Connectivity connectivity; + final Connectivity? connectivity; final ShipmentDataProvider shipmentDataProvider; @override diff --git a/lib/data/services/user_imp.dart b/lib/data/services/user_imp.dart index d3b7685..9b5305a 100644 --- a/lib/data/services/user_imp.dart +++ b/lib/data/services/user_imp.dart @@ -1,17 +1,16 @@ import 'package:fcs/data/provider/user_data_provider.dart'; import 'package:fcs/domain/entities/connectivity.dart'; import 'package:fcs/domain/entities/user.dart'; -import 'package:flutter/material.dart'; import 'user_service.dart'; class UserServiceImp implements UserService { UserServiceImp({ - @required this.connectivity, - @required this.userDataProvider, + required this.connectivity, + required this.userDataProvider, }); - final Connectivity connectivity; + final Connectivity? connectivity; final UserDataProvider userDataProvider; @override @@ -30,7 +29,7 @@ class UserServiceImp implements UserService { } @override - Future findUser(String phoneNumber) { + Future findUser(String phoneNumber) { return userDataProvider.findUser(phoneNumber); } diff --git a/lib/data/services/user_service.dart b/lib/data/services/user_service.dart index 168193d..0dd4297 100644 --- a/lib/data/services/user_service.dart +++ b/lib/data/services/user_service.dart @@ -4,7 +4,7 @@ abstract class UserService { Future inviteUser(String userName, String phoneNumber); Future deleteInvite(String phoneNumber); Future acceptRequest(String userID); - Future findUser(String phoneNumber); + Future findUser(String phoneNumber); Future> searchUser(String term); Future uploadMsgToken(String token); Future removeMsgToken(String token); diff --git a/lib/domain/entities/auth_result.dart b/lib/domain/entities/auth_result.dart index dd989fd..5467733 100644 --- a/lib/domain/entities/auth_result.dart +++ b/lib/domain/entities/auth_result.dart @@ -1,9 +1,9 @@ import 'auth_status.dart'; class AuthResult { - AuthStatus authStatus; - String authErrorCode; - String authErrorMsg; + AuthStatus? authStatus; + String? authErrorCode; + String? authErrorMsg; AuthResult({this.authStatus, this.authErrorCode, this.authErrorMsg}); } diff --git a/lib/domain/entities/cargo_type.dart b/lib/domain/entities/cargo_type.dart index 68ec494..0e165ea 100644 --- a/lib/domain/entities/cargo_type.dart +++ b/lib/domain/entities/cargo_type.dart @@ -1,28 +1,28 @@ class CargoType { - String id; - String name; + String? id; + String? name; double rate; double weight; bool isChecked; int qty; - bool isCutomDuty; + bool? isCutomDuty; double customDutyFee; - - double get calAmount => (calRate ?? 0) * (calWeight ?? 0); - double calRate; double calWeight; + + double get calAmount => calRate * calWeight; + CargoType( {this.id, this.name, - this.rate, - this.weight, - this.calWeight, - this.calRate, + this.rate = 0, + this.weight = 0, + this.calWeight = 0, + this.calRate = 0, this.isChecked = false, this.qty = 0, this.isCutomDuty, - this.customDutyFee}); + this.customDutyFee = 0}); factory CargoType.fromMap(Map map, String id) { return CargoType( @@ -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/domain/entities/carton.dart b/lib/domain/entities/carton.dart index 831adf2..8006051 100644 --- a/lib/domain/entities/carton.dart +++ b/lib/domain/entities/carton.dart @@ -9,61 +9,60 @@ import 'cargo_type.dart'; import 'package.dart'; class Carton { - String id; - String shipmentID; - String shipmentNumber; - String senderID; - String senderFCSID; - String senderName; + String? id; + String? shipmentID; + String? shipmentNumber; + String? senderID; + String? senderFCSID; + String? senderName; - String boxNumber; - String status; - String cargoDesc; - String desc; + String? boxNumber; + String? status; + String? cargoDesc; + String? desc; double width; double height; double length; - int shipmentWeight; - bool isChecked; - bool isShipmentCarton; - String cartonType; - String fcsID; - String userName; - String userID; - String fcsShipmentID; - String fcsShipmentNumber; - String mixCartonID; - String mixCartonNumber; - String cartonSizeID; - String cartonSizeName; - double cartonWeight; + int? shipmentWeight; + bool? isChecked; + bool? isShipmentCarton; + String? cartonType; + String? fcsID; + String? userName; + String? userID; + String? fcsShipmentID; + String? fcsShipmentNumber; + String? mixCartonID; + String? mixCartonNumber; + String? cartonSizeID; + String? cartonSizeName; + double? cartonWeight; int rate; int weight; - String packageType; - String pickUpID; - List photos; - String remark; - DateTime arrivedDate; - String cartonNumber; + String? packageType; + String? pickUpID; + List photos = []; + String? remark; + DateTime? arrivedDate; + String? cartonNumber; List packageIDs; List packages; - List cargoTypes; + List cargoTypes = []; - DeliveryAddress deliveryAddress; - Shipment shipment; + DeliveryAddress? deliveryAddress; + Shipment? shipment; //for mix box - String mixBoxType; + String? mixBoxType; List mixCartons; List mixCartonIDs; - int get amount => rate != null && weight != null ? rate * weight : 0; + int get amount => rate != null && weight != null ? (rate * weight) : 0; // String get packageNumber => // shipmentNumber + "-" + receiverNumber + " #" + boxNumber; - double get price => rate.toDouble() * weight; double get actualWeight => cargoTypes == null ? 0 : cargoTypes.fold(0, (p, e) => e.weight + p); @@ -84,15 +83,15 @@ class Carton { /// getCargoTypeForCalWeight returns carton with shipment weight List getCargoTypeForCalWeight(double volumetricRatio) { // get shipment weight - double volume = (length ?? 0) * (width ?? 0) * (height ?? 0); - double sw = volume / volumetricRatio ?? 0; + double volume = length * width * height; + double sw = volume / volumetricRatio; // get actual weight double aw = cargoTypes.fold(0.0, (p, c) => p + c.weight); if (aw == 0 || sw == 0) return []; cargoTypes.forEach((e) { - double calWeight = aw > sw ? e.weight : e.weight / aw * sw; + double calWeight = aw > sw ? e.weight : (e.weight / aw) * sw; e.calWeight = calWeight; }); return cargoTypes; @@ -116,7 +115,7 @@ class Carton { double total = 0; cargoTypes.forEach((e) { double r = - e.rate - (discountByWeight != null ? discountByWeight.discount : 0); + e.rate - (discountByWeight != null ? (discountByWeight.discount) : 0); double amount = e.weight * r; total += amount; }); @@ -134,9 +133,9 @@ class Carton { this.senderName, this.boxNumber, this.desc, - this.width, - this.height, - this.length, + this.width = 0, + this.height = 0, + this.length = 0, this.shipmentWeight, this.isChecked = false, this.cartonType, @@ -151,13 +150,13 @@ class Carton { this.status, this.arrivedDate, this.cargoDesc, - this.shipmentHistory, - this.packages, - this.cargoTypes, + this.shipmentHistory = const [], + this.packages = const [], + this.cargoTypes = const [], this.cartonNumber, this.fcsShipmentID, this.fcsShipmentNumber, - this.packageIDs, + this.packageIDs = const [], this.mixCartonID, this.mixCartonNumber, this.isShipmentCarton = false, @@ -165,14 +164,14 @@ class Carton { this.cartonSizeID, this.cartonSizeName, this.mixBoxType, - this.mixCartons, - this.mixCartonIDs, + this.mixCartons = const [], + this.mixCartonIDs = const [], this.cartonWeight}); Map toMap() { - List _cargoTypes = cargoTypes?.map((c) => c.toMap())?.toList() ?? []; - List _packages = packages?.map((c) => c.toJson())?.toList(); - List _mixCartons = mixCartons?.map((c) => c.toJson())?.toList(); + List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList(); + List _packages = packages.map((c) => c.toJson()).toList(); + List _mixCartons = mixCartons.map((c) => c.toJson()).toList(); return { 'id': id, 'fcs_shipment_id': fcsShipmentID, @@ -213,9 +212,9 @@ class Carton { shipmentNumber: map['shipment_number'], // receiverNumber: map['receiver_number'], boxNumber: map['box_number'], - length: double.tryParse(map['length']?.toString()), - width: double.tryParse(map['width']?.toString()), - height: double.tryParse(map['height']?.toString()), + length: double.tryParse(map['length'].toString()) ?? 0, + width: double.tryParse(map['width'].toString()) ?? 0, + height: double.tryParse(map['height'].toString()) ?? 0, userName: map['user_name'], fcsID: map['fcs_id'], cartonType: map['carton_type'], @@ -242,8 +241,8 @@ class Carton { Map toJson() { List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList(); - List _packages = packages?.map((c) => c.toJson())?.toList(); - List _mixCartons = mixCartons?.map((c) => c.toJson())?.toList(); + List _packages = packages.map((c) => c.toJson()).toList(); + List _mixCartons = mixCartons.map((c) => c.toJson()).toList(); return { 'id': id, 'fcs_shipment_id': fcsShipmentID, diff --git a/lib/domain/entities/carton_size.dart b/lib/domain/entities/carton_size.dart index 7d9f494..e9cd28b 100644 --- a/lib/domain/entities/carton_size.dart +++ b/lib/domain/entities/carton_size.dart @@ -1,10 +1,11 @@ class CartonSize { - String id; - String name; + String? id; + String? name; double length; double width; double height; - CartonSize({this.id, this.name, this.length, this.width, this.height}); + CartonSize( + {this.id, this.name, this.length = 0, this.width = 0, this.height = 0}); Map toMap() { return { @@ -27,19 +28,10 @@ class CartonSize { } @override - bool operator ==(other) { - if (identical(this, other)) { - return true; - } - return other.id == this.id; - } + bool operator ==(Object other) => other is CartonSize && other.id == id; @override - int get hashCode { - int result = 17; - result = 37 * result + id.hashCode; - return result; - } + int get hashCode => id.hashCode; bool isChangedForEdit(CartonSize cartonSize) { return cartonSize.name != this.name || diff --git a/lib/domain/entities/custom_duty.dart b/lib/domain/entities/custom_duty.dart index fb2a3aa..6f033f0 100644 --- a/lib/domain/entities/custom_duty.dart +++ b/lib/domain/entities/custom_duty.dart @@ -1,11 +1,15 @@ class CustomDuty { - String id; - String productType; - String desc; + String? id; + String? productType; + String? desc; double fee; double shipmentRate; CustomDuty( - {this.id, this.productType, this.desc, this.fee, this.shipmentRate}); + {this.id, + this.productType, + this.desc, + this.fee = 0, + this.shipmentRate = 0}); factory CustomDuty.fromMap(Map map, String id) { return CustomDuty( diff --git a/lib/domain/entities/customer.dart b/lib/domain/entities/customer.dart index 0fb51e7..6606f28 100644 --- a/lib/domain/entities/customer.dart +++ b/lib/domain/entities/customer.dart @@ -1,10 +1,8 @@ - - class Customer { - String id; - String name; - String phoneNumber; - String status; + String? id; + String? name; + String? phoneNumber; + String? status; Customer({ this.id, diff --git a/lib/domain/entities/discount.dart b/lib/domain/entities/discount.dart index cb2bda0..144bb9d 100644 --- a/lib/domain/entities/discount.dart +++ b/lib/domain/entities/discount.dart @@ -1,9 +1,9 @@ class Discount { - String id; - String code; - String customerId; - String customerName; - String status; + String? id; + String? code; + String? customerId; + String? customerName; + String? status; double amount; Discount({ @@ -11,7 +11,7 @@ class Discount { this.code, this.customerId, this.customerName, - this.amount, + this.amount = 0, this.status, }); diff --git a/lib/domain/entities/discount_by_weight.dart b/lib/domain/entities/discount_by_weight.dart index 3ff9a1d..92d46f0 100644 --- a/lib/domain/entities/discount_by_weight.dart +++ b/lib/domain/entities/discount_by_weight.dart @@ -1,9 +1,9 @@ class DiscountByWeight { - String id; + String? id; double weight; double discount; - DiscountByWeight({this.id, this.weight, this.discount}); + DiscountByWeight({this.id, this.weight = 0, this.discount = 0}); factory DiscountByWeight.fromMap(Map map, String id) { return DiscountByWeight( diff --git a/lib/domain/entities/faq.dart b/lib/domain/entities/faq.dart index fe20f07..7deae33 100644 --- a/lib/domain/entities/faq.dart +++ b/lib/domain/entities/faq.dart @@ -1,16 +1,17 @@ class FAQ { - String id; - int sn; - String questionEng; - String questionMm; - String answerEng; - String answerMm; - String pageLinkLabelEng; - String pageLinkLabelMm; - String pageLink; + String? id; + int? sn; + String? questionEng; + String? questionMm; + String? answerEng; + String? answerMm; + String? pageLinkLabelEng; + String? pageLinkLabelMm; + String? pageLink; - String question(bool isEng) => isEng ? questionEng : questionMm; - String answer(bool isEng) => isEng ? answerEng : answerMm; + String question(bool isEng) => + isEng ? (questionEng ?? "") : (questionMm ?? ""); + String answer(bool isEng) => isEng ? (answerEng ?? "") : (answerMm ?? ""); FAQ( {this.id, diff --git a/lib/domain/entities/fcs_shipment.dart b/lib/domain/entities/fcs_shipment.dart index 37e2c71..794e65e 100644 --- a/lib/domain/entities/fcs_shipment.dart +++ b/lib/domain/entities/fcs_shipment.dart @@ -3,17 +3,18 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import '../constants.dart'; class FcsShipment { - String id; - String shipmentNumber; - DateTime cutoffDate; - String shipType; - DateTime arrivalDate; - DateTime departureDate; - String consignee; - String port; - String destination; - String status; - String reportName; + String? id; + String? shipmentNumber; + DateTime? cutoffDate; + String? shipType; + DateTime? arrivalDate; + DateTime? departureDate; + String? consignee; + String? port; + String? destination; + String? status; + String? reportName; + FcsShipment({ this.id, this.shipmentNumber, @@ -51,10 +52,10 @@ class FcsShipment { return { "id": id, 'shipment_number': shipmentNumber, - 'cutoff_date': cutoffDate?.toUtc()?.toIso8601String(), + 'cutoff_date': cutoffDate?.toUtc().toIso8601String(), 'shipment_type': shipType, - 'arrival_date': arrivalDate?.toUtc()?.toIso8601String(), - 'departure_date': departureDate?.toUtc()?.toIso8601String(), + 'arrival_date': arrivalDate?.toUtc().toIso8601String(), + 'departure_date': departureDate?.toUtc().toIso8601String(), 'consignee': consignee, 'port': port, 'destination': destination, diff --git a/lib/domain/entities/invoice.dart b/lib/domain/entities/invoice.dart index b614fcc..3ac1c9e 100644 --- a/lib/domain/entities/invoice.dart +++ b/lib/domain/entities/invoice.dart @@ -10,15 +10,15 @@ import 'package:fcs/domain/entities/rate.dart'; import 'package:fcs/domain/entities/shipment.dart'; class Invoice { - String id; - String invoiceNumber; - DateTime invoiceDate; - String fcsShipmentID; - String userID; - String fcsID; - String userName; - String phoneNumber; - String status; + String? id; + String? invoiceNumber; + DateTime? invoiceDate; + String? fcsShipmentID; + String? userID; + String? fcsID; + String? userName; + String? phoneNumber; + String? status; double handlingFee; double deliveryFee; @@ -30,9 +30,9 @@ class Invoice { List cargoTypes; List shipments; List payments; - Discount discount; - PaymentMethod paymentMethod; - String invoiceURL; + Discount? discount; + PaymentMethod? paymentMethod; + String? invoiceURL; List getCargoTypes(Rate rate) { if (cargoTypes != null) return cargoTypes; @@ -40,7 +40,7 @@ class Invoice { List _cargoTypes = []; double totalCalWeight = 0; cartons.forEach((carton) { - if (carton.isChecked) { + if (carton.isChecked ?? false) { var _cartonsTypes = carton.getCargoTypeForCalWeight(rate.volumetricRatio); _cartonsTypes.forEach((ct) { @@ -68,15 +68,15 @@ class Invoice { double getTotal(Rate rate) { List cargoTypes = getCargoTypes(rate); - var total = cargoTypes.fold(0.0, (p, c) => c.calAmount + p); + double total = cargoTypes.fold(0.0, (p, c) => c.calAmount + p); return total; } - double get balance => (amount ?? 0) - (paidAmount ?? 0); + double get balance => amount - paidAmount; double getNetAmount(Rate rate) { List cargoTypes = getCargoTypes(rate); - var total = cargoTypes.fold(0.0, (p, c) => c.calAmount + p); + double total = cargoTypes.fold(0.0, (p, c) => c.calAmount + p); total += getCustomFee(); total += getDeliveryFee(); total += getHandlingFee(); @@ -85,13 +85,13 @@ class Invoice { } double getHandlingFee() { - return shipments?.where((sh) => sh.isSelected ?? false)?.fold(0, (p, s) { - return p + (s?.handlingFee ?? 0) - (s?.paidHandlingFee ?? 0); - }); + return shipments + .where((sh) => sh.isSelected) + .fold(0, (p, s) => p + (s.handlingFee - s.paidHandlingFee)); } double getTotalBalance(Rate rate) { - return getNetAmount(rate) - (paidAmount ?? 0); + return getNetAmount(rate) - paidAmount; } double getCustomFee() { @@ -102,7 +102,7 @@ class Invoice { return deliveryFee == null ? 0 : deliveryFee; } - double getDiscount() => discount == null ? 0 : discount.amount; + double getDiscount() => discount == null ? 0 : discount!.amount; Invoice( {this.id, @@ -111,19 +111,19 @@ class Invoice { this.fcsID, this.userName, this.phoneNumber, - this.amount, - this.paidAmount, + this.amount = 0, + this.paidAmount = 0, this.discount, this.status, - this.customDuties, - this.cartons, - this.cargoTypes, - this.handlingFee, - this.deliveryFee, + this.customDuties = const [], + this.cartons = const [], + this.cargoTypes = const [], + this.handlingFee = 0, + this.deliveryFee = 0, this.fcsShipmentID, - this.shipments, + this.shipments = const [], this.invoiceURL, - this.payments, + this.payments = const [], this.paymentMethod}); factory Invoice.fromMap(Map map, String docID) { @@ -153,7 +153,7 @@ class Invoice { return Invoice( id: docID, invoiceNumber: map['invoice_number'], - invoiceDate: invd?.toDate(), + invoiceDate: invd.toDate(), userName: map['user_name'], fcsID: map['fcs_id'], phoneNumber: map['phone_number'], @@ -174,12 +174,12 @@ class Invoice { Map toMap() { List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList(); - List _customDuties = customDuties?.map((c) => c.toMap())?.toList(); - List _cartons = cartons?.map((c) => c.toMap())?.toList() ?? []; - List _shipments = shipments?.map((s) => s.toMap())?.toList() ?? []; + List _customDuties = customDuties.map((c) => c.toMap()).toList(); + List _cartons = cartons.map((c) => c.toMap()).toList(); + List _shipments = shipments.map((s) => s.toMap()).toList(); return { "id": id, - "invoice_date": invoiceDate?.toUtc()?.toIso8601String(), + "invoice_date": invoiceDate?.toUtc().toIso8601String(), "user_id": userID, "user_name": userName, "invoice_number": invoiceNumber, diff --git a/lib/domain/entities/market.dart b/lib/domain/entities/market.dart index 0b7ebec..f12c955 100644 --- a/lib/domain/entities/market.dart +++ b/lib/domain/entities/market.dart @@ -1,11 +1,8 @@ class Market { - String id; - String name; + String? id; + String? name; - Market({ - this.id, - this.name, - }); + Market({this.id, this.name}); Map toMap() { return { diff --git a/lib/domain/entities/package.dart b/lib/domain/entities/package.dart index 9eb3249..c583de1 100644 --- a/lib/domain/entities/package.dart +++ b/lib/domain/entities/package.dart @@ -5,35 +5,35 @@ import 'package:fcs/domain/vo/delivery_address.dart'; import 'package:fcs/domain/vo/shipment_status.dart'; class Package { - String id; - String trackingID; - String userID; - String fcsID; - String userName; - String phoneNumber; - DateTime currentStatusDate; + String? id; + String? trackingID; + String? userID; + String? fcsID; + String? userName; + String? phoneNumber; + DateTime? currentStatusDate; List photoUrls; List shipmentHistory; - String desc; + String? desc; - String status; - String shipmentNumber; - String senderFCSID; - String senderName; - String senderPhoneNumber; - String boxNumber; - String cargoDesc; - String market; + String? status; + String? shipmentNumber; + String? senderFCSID; + String? senderName; + String? senderPhoneNumber; + String? boxNumber; + String? cargoDesc; + String? market; bool isChecked; int rate; int weight; - String packageType; - String pickUpID; - List photos; - String remark; - DateTime arrivedDate; - DeliveryAddress deliveryAddress; + String? packageType; + String? pickUpID; + // List photos; + String? remark; + DateTime? arrivedDate; + DeliveryAddress? deliveryAddress; //for packages in processing List photoFiles; @@ -42,35 +42,34 @@ class Package { double get price => rate.toDouble() * weight; - Package({ - this.id, - this.trackingID, - this.userID, - this.userName, - this.fcsID, - this.phoneNumber, - this.shipmentNumber, - this.senderFCSID, - this.senderName, - this.boxNumber, - this.rate, - this.weight, - this.packageType, - this.pickUpID, - this.remark, - this.status, - this.arrivedDate, - this.cargoDesc, - this.market, - this.shipmentHistory, - this.currentStatusDate, - this.photoUrls, - this.desc, - this.deliveryAddress, - this.isChecked = false, - this.photoFiles, - this.senderPhoneNumber - }); + Package( + {this.id, + this.trackingID, + this.userID, + this.userName, + this.fcsID, + this.phoneNumber, + this.shipmentNumber, + this.senderFCSID, + this.senderName, + this.boxNumber, + this.rate = 0, + this.weight = 0, + this.packageType, + this.pickUpID, + this.remark, + this.status, + this.arrivedDate, + this.cargoDesc, + this.market, + this.shipmentHistory = const [], + this.currentStatusDate, + this.photoUrls = const [], + this.desc, + this.deliveryAddress, + this.isChecked = false, + this.photoFiles = const [], + this.senderPhoneNumber}); factory Package.fromMap(Map map, String docID) { var _currentStatusDate = (map['status_date'] as Timestamp); @@ -98,9 +97,7 @@ class Package { senderName: map['sender_name'], senderPhoneNumber: map['sender_phone_number'], deliveryAddress: _da, - currentStatusDate: _currentStatusDate != null - ? _currentStatusDate.toDate().toLocal() - : null, + currentStatusDate: _currentStatusDate.toDate().toLocal(), photoUrls: _photoUrls, shipmentHistory: _shipmentStatus); } diff --git a/lib/domain/entities/payment.dart b/lib/domain/entities/payment.dart index d30eebc..feaeaca 100644 --- a/lib/domain/entities/payment.dart +++ b/lib/domain/entities/payment.dart @@ -1,11 +1,11 @@ import 'package:cloud_firestore/cloud_firestore.dart'; class Payment { - String id; - String invoiceID; - DateTime paymentDate; - String paymentReceiptURL; - String status; + String? id; + String? invoiceID; + DateTime? paymentDate; + String? paymentReceiptURL; + String? status; double amount; Payment( @@ -14,13 +14,13 @@ class Payment { this.paymentDate, this.paymentReceiptURL, this.status, - this.amount}); + this.amount = 0}); factory Payment.fromMap(Map map, String id) { var _paymentDate = (map['payment_date'] as Timestamp); return Payment( id: id, - paymentDate: _paymentDate?.toDate(), + paymentDate: _paymentDate.toDate(), paymentReceiptURL: map['payment_receipt_url'], status: map['status'], amount: map['amount']?.toDouble() ?? 0, @@ -31,7 +31,7 @@ class Payment { return { "id": id, "invoice_id": invoiceID, - 'payment_date': paymentDate?.toUtc()?.toIso8601String(), + 'payment_date': paymentDate?.toUtc().toIso8601String(), 'payment_receipt_url': paymentReceiptURL, 'status': status, 'amount': amount, @@ -39,7 +39,7 @@ class Payment { } Payment clone() { - return Payment.fromMap(toMap(), this.id); + return Payment.fromMap(toMap(), this.id!); } @override diff --git a/lib/domain/entities/payment_method.dart b/lib/domain/entities/payment_method.dart index 50cf277..109ad16 100644 --- a/lib/domain/entities/payment_method.dart +++ b/lib/domain/entities/payment_method.dart @@ -1,11 +1,11 @@ class PaymentMethod { - String id; - String name; - String accountName; - String account; - String phone; - String email; - String link; + String? id; + String? name; + String? accountName; + String? account; + String? phone; + String? email; + String? link; PaymentMethod( {this.id, diff --git a/lib/domain/entities/processing.dart b/lib/domain/entities/processing.dart index 0006183..0c1a165 100644 --- a/lib/domain/entities/processing.dart +++ b/lib/domain/entities/processing.dart @@ -1,15 +1,15 @@ import 'package:fcs/domain/entities/package.dart'; class Processing { - String id; + String? id; //for consignee - String userID; - String userName; - String userPhoneNumber; + String? userID; + String? userName; + String? userPhoneNumber; //for shipper - String fcsID; - String shipperName; - String shipperPhoneNumber; + String? fcsID; + String? shipperName; + String? shipperPhoneNumber; List packages; @@ -21,7 +21,7 @@ class Processing { this.fcsID, this.shipperName, this.shipperPhoneNumber, - this.packages}); + this.packages = const []}); @override bool operator ==(Object other) => other is Processing && other.id == id; diff --git a/lib/domain/entities/rate.dart b/lib/domain/entities/rate.dart index f5682e1..566d827 100644 --- a/lib/domain/entities/rate.dart +++ b/lib/domain/entities/rate.dart @@ -1,4 +1,3 @@ - import 'package:fcs/domain/entities/discount_by_weight.dart'; import 'cargo_type.dart'; @@ -11,26 +10,25 @@ class Rate { double diffDiscountWeight; double diffWeightRate; - List cargoTypes; - List customDuties; - List discountByWeights; + List cargoTypes = []; + List customDuties = []; + List discountByWeights = []; DiscountByWeight getDiscountByWeight(double weight) { discountByWeights.sort((d1, d2) => d2.weight.compareTo(d1.weight)); - return discountByWeights.firstWhere((e) => e.weight < weight, - orElse: () => null); + return discountByWeights.firstWhere((e) => e.weight < weight); } - CargoType get defaultCargoType => cargoTypes == null + CargoType? get defaultCargoType => cargoTypes == null ? null : cargoTypes.firstWhere((e) => e.name == "General"); Rate( - {this.deliveryFee, - this.freeDeliveryWeight, - this.volumetricRatio, - this.diffDiscountWeight, - this.diffWeightRate}); + {this.deliveryFee = 0, + this.freeDeliveryWeight = 0, + this.volumetricRatio = 0, + this.diffDiscountWeight = 0, + this.diffWeightRate = 0}); factory Rate.fromMap(Map map) { return Rate( diff --git a/lib/domain/entities/receipt.dart b/lib/domain/entities/receipt.dart index 6fffbbe..70f59f5 100644 --- a/lib/domain/entities/receipt.dart +++ b/lib/domain/entities/receipt.dart @@ -1,9 +1,9 @@ class Receipt { - String id; - int amount; - String date; - String status; - String fileUrl; + String? id; + int? amount = 0; + String? date; + String? status; + String? fileUrl; Receipt({this.id, this.amount, this.date, this.status, this.fileUrl}); } diff --git a/lib/domain/entities/setting.dart b/lib/domain/entities/setting.dart index 8f594bb..c0aefe1 100644 --- a/lib/domain/entities/setting.dart +++ b/lib/domain/entities/setting.dart @@ -9,21 +9,20 @@ List dayLists = [ ]; class Setting { - final int supportBuildNum; - + final int? supportBuildNum; // contact page - String usaAddress; - String mmAddress; - String usaContactNumber; - String mmContactNumber; - String emailAddress; - String facebookLink; - bool inviteRequired; - String appUrl; - final String termsEng; - final String termsMm; - String about; - String courierWebsite; + String? usaAddress; + String? mmAddress; + String? usaContactNumber; + String? mmContactNumber; + String? emailAddress; + String? facebookLink; + bool? inviteRequired; + String? appUrl; + final String? termsEng; + final String? termsMm; + String? about; + String? courierWebsite; List shipmentTypes; @@ -40,7 +39,7 @@ class Setting { this.termsEng, this.termsMm, this.about, - this.shipmentTypes, + this.shipmentTypes = const [], this.courierWebsite}); factory Setting.fromMap(Map map) { @@ -76,9 +75,9 @@ class Setting { } class Day { - int id; - String name; - bool isChecked = false; + int? id; + String? name; + bool? isChecked = false; Day({this.id, this.name, this.isChecked}); @override diff --git a/lib/domain/entities/shipment.dart b/lib/domain/entities/shipment.dart index 7b837df..2d4cabc 100644 --- a/lib/domain/entities/shipment.dart +++ b/lib/domain/entities/shipment.dart @@ -4,35 +4,35 @@ import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; class Shipment { - String id; - String shipmentNumber; - String shipmentType; - DeliveryAddress pickupAddress; - DateTime pickupDate; - String pickupTimeStart; - String pickupTimeEnd; + String? id; + String? shipmentNumber; + String? shipmentType; + DeliveryAddress? pickupAddress; + DateTime? pickupDate; + String? pickupTimeStart; + String? pickupTimeEnd; - String userName; - String userID; - String phoneNumber; - int numberOfPackage; - int weight; - double handlingFee; - double paidHandlingFee; - String address; - String status; + String? userName; + String? userID; + String? phoneNumber; + int numberOfPackage = 0; + int weight = 0; + double handlingFee = 0; + double paidHandlingFee = 0; + String? address; + String? status; bool isCourier; int radioIndex; List boxes; - String pickupUserID; - String pickupUserName; - String pickupUserPhoneNumber; + String? pickupUserID; + String? pickupUserName; + String? pickupUserPhoneNumber; - String fcsShipmentID; - String fcsShipmentNumber; - String shipmentLabelUrl; - bool isSelected; + String? fcsShipmentID; + String? fcsShipmentNumber; + String? shipmentLabelUrl; + bool isSelected = false; Shipment( {this.id, @@ -43,28 +43,28 @@ class Shipment { this.phoneNumber, this.pickupTimeStart, this.pickupTimeEnd, - this.numberOfPackage, - this.weight, - this.handlingFee, - this.paidHandlingFee, + this.numberOfPackage = 0, + this.weight = 0, + this.handlingFee = 0, + this.paidHandlingFee = 0, this.address, this.status, this.pickupDate, this.isCourier = false, this.radioIndex = 1, - this.pickupAddress, + required this.pickupAddress, this.pickupUserID, this.pickupUserName, this.pickupUserPhoneNumber, this.fcsShipmentID, this.fcsShipmentNumber, this.shipmentLabelUrl, - this.boxes}); + this.boxes = const []}); - int get last => DateTime.now().difference(pickupDate).inDays; + // int get last => DateTime.now().difference(pickupDate).inDays; - double get totalWeight => boxes?.fold(0, (p, e) => p + e.actualWeight); - int get totalCount => boxes?.length; + double get totalWeight => boxes.fold(0, (p, e) => p + e.actualWeight); + int get totalCount => boxes.length; bool get isPending => status == shipment_pending_status; bool get isAssigned => status == shipment_assigned_status; @@ -100,15 +100,15 @@ class Shipment { } Map toMap() { - List _boxes = boxes?.map((l) => l.toMap())?.toList() ?? []; + List _boxes = boxes.map((l) => l.toMap()).toList(); return { "id": id, 'user_id': userID, 'cartons': _boxes, 'shipment_type': shipmentType, - 'pickup_address': pickupAddress.toMap(), - "pickup_date": pickupDate?.toUtc()?.toIso8601String(), + 'pickup_address': pickupAddress?.toMap(), + "pickup_date": pickupDate?.toUtc().toIso8601String(), 'pickup_time_start': pickupTimeStart, 'pickup_time_end': pickupTimeEnd, 'pickup_user_id': pickupUserID, diff --git a/lib/domain/entities/user.dart b/lib/domain/entities/user.dart index 6ada508..ae917fe 100644 --- a/lib/domain/entities/user.dart +++ b/lib/domain/entities/user.dart @@ -9,18 +9,19 @@ DateFormat timeFormat = DateFormat("HH:mm"); final DateFormat dateFormat = DateFormat("d MMM yyyy"); class User { - String id; - String name; - String phoneNumber; - String status; - String fcsID; - DateTime lastMessageTime; - String lastMessage; - int userUnseenCount; - int fcsUnseenCount; - String preferCurrency; + String? id; + String? name; + String? phoneNumber; + String? status; + String? fcsID; + DateTime? lastMessageTime; + String? lastMessage; + int? userUnseenCount; + int? fcsUnseenCount; + String? preferCurrency; - String get initial => name != null && name != "" ? name.substring(0, 1) : "?"; + String get initial => + name != null && name != "" ? name!.substring(0, 1) : "?"; String get getLastMessage { var msg = lastMessage ?? "Say hi to $name"; @@ -31,27 +32,31 @@ class User { String get getLastMessageTime { if (lastMessageTime == null) return ""; DateTime today = DateTime.now(); - if (lastMessageTime.year == today.year && - lastMessageTime.month == today.month && - lastMessageTime.day == today.day) { - return timeFormat.format(lastMessageTime); + if (lastMessageTime!.year == today.year && + lastMessageTime!.month == today.month && + lastMessageTime!.day == today.day) { + return timeFormat.format(lastMessageTime!); } else { - return dateFormat.format(lastMessageTime); + return dateFormat.format(lastMessageTime!); } } String get getUserUnseenCount => userUnseenCount != null - ? userUnseenCount > 100 ? "99+" : userUnseenCount.toString() + ? userUnseenCount! > 100 + ? "99+" + : userUnseenCount.toString() : "0"; String get getFcsUnseenCount => fcsUnseenCount != null - ? fcsUnseenCount > 100 ? "99+" : fcsUnseenCount.toString() + ? fcsUnseenCount! > 100 + ? "99+" + : fcsUnseenCount.toString() : "0"; List privileges = []; - String get phone => phoneNumber != null && phoneNumber.startsWith("959") - ? "0${phoneNumber.substring(2)}" - : phoneNumber; + String get phone => phoneNumber != null && phoneNumber!.startsWith("959") + ? "0${phoneNumber!.substring(2)}" + : phoneNumber!; bool get joined => status != null && status == user_joined_status; bool get invited => status != null && status == user_invited_status; bool get requested => status != null && status == user_requested_status; @@ -64,7 +69,7 @@ class User { this.phoneNumber, this.fcsID, this.status, - this.privileges, + this.privileges = const [], this.lastMessage, this.lastMessageTime, this.userUnseenCount, diff --git a/lib/domain/exceiptions/server_exceptions.dart b/lib/domain/exceiptions/server_exceptions.dart index a76ba67..7436d0b 100644 --- a/lib/domain/exceiptions/server_exceptions.dart +++ b/lib/domain/exceiptions/server_exceptions.dart @@ -1,12 +1,12 @@ class ServerException { @override - List get props => null; + List? get props => null; call() { return null; } @override - bool get stringify => null; + bool? get stringify => null; } diff --git a/lib/domain/vo/contact.dart b/lib/domain/vo/contact.dart index 5df67a2..2037ddf 100644 --- a/lib/domain/vo/contact.dart +++ b/lib/domain/vo/contact.dart @@ -1,12 +1,12 @@ import 'package:fcs/domain/entities/setting.dart'; class Contact { - String usaAddress; - String mmAddress; - String usaContactNumber; - String mmContactNumber; - String emailAddress; - String facebookLink; + String? usaAddress; + String? mmAddress; + String? usaContactNumber; + String? mmContactNumber; + String? emailAddress; + String? facebookLink; Contact({ this.usaAddress, diff --git a/lib/domain/vo/delivery_address.dart b/lib/domain/vo/delivery_address.dart index 93e7960..b212ebc 100644 --- a/lib/domain/vo/delivery_address.dart +++ b/lib/domain/vo/delivery_address.dart @@ -1,13 +1,14 @@ class DeliveryAddress { - String id; - String fullName; - String addressLine1; - String addressLine2; - String city; - String state; - String phoneNumber; + String? id; + String? fullName; + String? addressLine1; + String? addressLine2; + String? city; + String? state; + String? phoneNumber; bool isDefault; - String userID; + String? userID; + DeliveryAddress( {this.id, this.fullName, diff --git a/lib/domain/vo/message.dart b/lib/domain/vo/message.dart index fc86b58..3417058 100644 --- a/lib/domain/vo/message.dart +++ b/lib/domain/vo/message.dart @@ -1,15 +1,15 @@ import 'package:cloud_firestore/cloud_firestore.dart'; class Message { - String id; - String message; - DateTime date; - String receiverID; - String receiverName; - String senderID; - String senderName; - String messageType; - String messageID; + String? id; + String? message; + DateTime? date; + String? receiverID; + String? receiverName; + String? senderID; + String? senderName; + String? messageType; + String? messageID; Message( {this.id, @@ -21,11 +21,13 @@ class Message { this.senderName, this.messageType, this.messageID}); + bool fromToday() { + if (date == null) return false; var now = DateTime.now(); - return date.day == now.day && - date.month == now.month && - date.year == now.year; + return date!.day == now.day && + date!.month == now.month && + date!.year == now.year; } Map toMap() { @@ -36,9 +38,10 @@ class Message { } bool sameDay(Message another) { - return date.year == another.date.year && - date.month == another.date.month && - date.day == another.date.day; + if (date == null) return false; + return date!.year == another.date!.year && + date!.month == another.date!.month && + date!.day == another.date!.day; } factory Message.fromMap(Map map, String id) { @@ -52,7 +55,7 @@ class Message { receiverName: map['receiver_name'], messageType: map['msg_type'], messageID: map['msg_id'], - date: date != null ? date.toDate() : null, + date: date.toDate(), ); } } diff --git a/lib/domain/vo/privilege.dart b/lib/domain/vo/privilege.dart index 5b913b2..85907a2 100644 --- a/lib/domain/vo/privilege.dart +++ b/lib/domain/vo/privilege.dart @@ -1,20 +1,24 @@ import 'package:fcs/domain/constants.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_icons/flutter_icons.dart'; +import 'package:flutter_icons_null_safety/flutter_icons_null_safety.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; class Privilege { String id; - String name; - String desc; - bool sysAdminOnly = true; - bool isChecked = false; + String? name; + String? desc; + bool? sysAdminOnly = true; + bool? isChecked = false; - IconData iconData; + IconData? iconData; Privilege( - {this.id, this.name, this.desc, this.isChecked, this.sysAdminOnly}) { + {required this.id, + this.name, + this.desc, + this.isChecked, + this.sysAdminOnly}) { if (this.id == privilege_admin) { iconData = MaterialCommunityIcons.account_tie; } else if (this.id == privilege_support) { diff --git a/lib/domain/vo/radio.dart b/lib/domain/vo/radio.dart deleted file mode 100644 index ab1a7a1..0000000 --- a/lib/domain/vo/radio.dart +++ /dev/null @@ -1,5 +0,0 @@ -class RadioGroup { - String text; - int index; - RadioGroup({this.text, this.index}); -} \ No newline at end of file diff --git a/lib/domain/vo/shipment_status.dart b/lib/domain/vo/shipment_status.dart index ed4549c..7783190 100644 --- a/lib/domain/vo/shipment_status.dart +++ b/lib/domain/vo/shipment_status.dart @@ -3,17 +3,21 @@ import 'package:cloud_firestore/cloud_firestore.dart'; class ShipmentStatus { String status; DateTime date; - bool done; - String staffId; - String staffName; + bool? done; + String? staffId; + String? staffName; ShipmentStatus( - {this.status, this.date, this.done, this.staffId, this.staffName}); + {required this.status, + required this.date, + this.done, + this.staffId, + this.staffName}); factory ShipmentStatus.fromMap(Map map) { var _date = (map['date'] as Timestamp); return ShipmentStatus( status: map['status'], - date: _date == null ? null : _date.toDate(), + date: _date.toDate(), done: map['done'], staffId: map['staff_id'], staffName: map['staff_name']); diff --git a/lib/domain/vo/status.dart b/lib/domain/vo/status.dart index e229726..a8b5b7b 100644 --- a/lib/domain/vo/status.dart +++ b/lib/domain/vo/status.dart @@ -1,8 +1,7 @@ - class Status { - String status; - String message; - String errorCode; + String? status; + String? message; + String? errorCode; Status(this.status, this.message); Status.fromJson(Map json) { @@ -10,4 +9,4 @@ class Status { message = json['message']; errorCode = json['error_code']; } -} \ No newline at end of file +} diff --git a/lib/domain/vo/term.dart b/lib/domain/vo/term.dart index b9c1086..9aa2c26 100644 --- a/lib/domain/vo/term.dart +++ b/lib/domain/vo/term.dart @@ -1,8 +1,8 @@ import 'package:fcs/domain/entities/setting.dart'; class Term { - String termEng; - String termMm; + String? termEng; + String? termMm; Term({this.termEng, this.termMm}); diff --git a/lib/helpers/api_helper.dart b/lib/helpers/api_helper.dart index 06fca69..8eacdd2 100644 --- a/lib/helpers/api_helper.dart +++ b/lib/helpers/api_helper.dart @@ -20,8 +20,8 @@ Future requestAPI( String path, method, { dynamic payload, - String token, - String url, + String? token, + String? url, }) async { DevInfo devInfo = await DevInfo.getDevInfo(); @@ -33,7 +33,7 @@ Future requestAPI( headers["Token"] = token; } if (devInfo != null && devInfo.deviceID != null && deviceName != null) { - headers["Device"] = devInfo.deviceID + ":" + deviceName; + headers["Device"] = devInfo.deviceID??"" + ":" + deviceName; } headers["Project-ID"] = Config.instance.reportProjectID; @@ -66,7 +66,7 @@ Future requestAPI( // request makes http request // if token is null Future requestDownloadAPI(String path, method, - {dynamic payload, String token, String url, String filePath}) async { + {dynamic payload, String? token, String? url, String? filePath}) async { DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; String deviceName = "${androidInfo.model}(${androidInfo.id})"; @@ -81,7 +81,7 @@ Future requestDownloadAPI(String path, method, log.info("Path:$baseUrl$path"); HttpClient client = new HttpClient(); var _downloadData = StringBuffer(); - var fileSave = new File(filePath); + var fileSave = new File(filePath!); var request = await client.getUrl(Uri.parse("$baseUrl$path")); request.headers.set("Project-ID", Config.instance.reportProjectID); request.headers @@ -108,7 +108,7 @@ Future requestDownloadAPI(String path, method, // request makes http request // if token is null Future requestDownloadPDFAPI(String path, method, - {dynamic payload, String token, String url, String filePath}) async { + {dynamic payload, String? token, String? url, String? filePath}) async { DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; String deviceName = "${androidInfo.model}(${androidInfo.id})"; @@ -123,7 +123,7 @@ Future requestDownloadPDFAPI(String path, method, log.info("Path:$baseUrl$path"); HttpClient client = new HttpClient(); // var _downloadData = StringBuffer(); - var fileSave = new File(filePath); + var fileSave = new File(filePath!); var request = await client.getUrl(Uri.parse("$baseUrl$path")); request.headers.set("Project-ID", Config.instance.reportProjectID); if (token != null) { @@ -135,7 +135,7 @@ Future requestDownloadPDFAPI(String path, method, request.headers.set("payload", escapePayload); var response = await request.close(); print("headers:${response.headers}"); - var _downloadData = List(); + List _downloadData = []; response.listen((d) => _downloadData.addAll(d), onDone: () { fileSave.writeAsBytes(_downloadData); @@ -155,10 +155,10 @@ typedef OnDownloadDone(File file); // if token is null Future requestDownload(String path, method, {dynamic payload, - String token, - String url, - String filePath, - OnDownloadDone onDownloadDone}) async { + required String token, + required String url, + required String filePath, + OnDownloadDone? onDownloadDone}) async { DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; String deviceName = "${androidInfo.model}(${androidInfo.id})"; @@ -188,7 +188,7 @@ Future requestDownload(String path, method, // request.write(escapePayload); var response = await request.close(); print("headers:${response.headers}"); - var _downloadData = List(); + List _downloadData = []; var cd = response.headers.value("content-disposition"); String fileName = "download.csv"; if (cd != null && cd.contains("filename=")) { diff --git a/lib/helpers/dev_info.dart b/lib/helpers/dev_info.dart index 255bf92..2d2c72d 100644 --- a/lib/helpers/dev_info.dart +++ b/lib/helpers/dev_info.dart @@ -2,13 +2,13 @@ import 'package:device_info/device_info.dart'; import 'dart:io' show Platform; class DevInfo { - bool isAndroid; - bool isIOS; - String deviceID; - String id; - String model; + bool? isAndroid; + bool? isIOS; + String? deviceID; + String? id; + String? model; - static DevInfo _instance; + static DevInfo? _instance; static Future getDevInfo() async { if (_instance != null) return Future.value(_instance); @@ -18,14 +18,14 @@ class DevInfo { if (Platform.isAndroid) { AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; - _instance.deviceID = androidInfo.androidId; - _instance.id = androidInfo.id; - _instance.model = androidInfo.model; + _instance!.deviceID = androidInfo.androidId; + _instance!.id = androidInfo.id; + _instance!.model = androidInfo.model; } else if (Platform.isIOS) { IosDeviceInfo iosDeviceInfo = await deviceInfo.iosInfo; - _instance.deviceID = iosDeviceInfo.identifierForVendor; - _instance.id = iosDeviceInfo.utsname.release; - _instance.model = iosDeviceInfo.model; + _instance!.deviceID = iosDeviceInfo.identifierForVendor; + _instance!.id = iosDeviceInfo.utsname.release; + _instance!.model = iosDeviceInfo.model; } return Future.value(_instance); } diff --git a/lib/helpers/firebase_helper.dart b/lib/helpers/firebase_helper.dart index f9539e8..0fd5b84 100644 --- a/lib/helpers/firebase_helper.dart +++ b/lib/helpers/firebase_helper.dart @@ -1,32 +1,31 @@ import 'dart:io'; -import 'package:fcs/config.dart'; -import 'package:firebase_auth/firebase_auth.dart'; +import 'package:firebase_auth/firebase_auth.dart' as fb; import 'package:firebase_storage/firebase_storage.dart'; import 'package:logging/logging.dart'; import 'package:uuid/uuid.dart'; final log = Logger('firebaseHelper'); -final FirebaseAuth auth = FirebaseAuth.instance; +final fb.FirebaseAuth auth = fb.FirebaseAuth.instance; Future getToken() async { - FirebaseUser firebaseUser = await auth.currentUser(); - IdTokenResult token = await firebaseUser.getIdToken(); - return token.token; + fb.User? firebaseUser = fb.FirebaseAuth.instance.currentUser; + String token = await firebaseUser?.getIdToken() ?? ""; + return token; } -Future getClaims({bool refreshIdToken = false}) async { - FirebaseUser firebaseUser = await auth.currentUser(); +Future getClaims({bool refreshIdToken = false}) async { + fb.User? firebaseUser = auth.currentUser; if (firebaseUser == null) return null; - IdTokenResult idToken = - await firebaseUser.getIdToken(refresh: refreshIdToken); + fb.IdTokenResult idToken = + await firebaseUser.getIdTokenResult(refreshIdToken); return idToken.claims; } // returns list of url Future> uploadFiles(String path, List files, - {String fileName}) async { + {String? fileName}) async { List> fu = []; for (File f in files) { Future u = uploadStorage(path, f); @@ -35,22 +34,27 @@ Future> uploadFiles(String path, List files, return Future.wait(fu); } -Future uploadStorage(String path, File file, {String fileName}) async { +Future uploadStorage(String path, File file, {String? fileName}) async { if (fileName == null) { fileName = Uuid().v4(); } - StorageReference storageReference = - FirebaseStorage(storageBucket: Config.instance.bucketName) - .ref() - .child('$path/$fileName'); - StorageUploadTask uploadTask = storageReference.putFile(file); - await uploadTask.onComplete; - String downloadUrl = await storageReference.getDownloadURL(); - print("name:${await storageReference.getName()}"); - print("bucket:${await storageReference.getBucket()}"); - print("path:${await storageReference.getPath()}"); - print("meta:${await storageReference.getMetadata()}"); + Reference ref = FirebaseStorage.instance.ref().child('$path/$fileName'); + UploadTask uploadTask = ref.putFile(file); + await uploadTask.resume(); + String downloadUrl = await ref.getDownloadURL(); return downloadUrl; + // StorageReference storageReference = + // FirebaseStorage(storageBucket: Config.instance.bucketName) + // .ref() + // .child('$path/$fileName'); + // StorageUploadTask uploadTask = storageReference.putFile(file); + // await uploadTask.onComplete; + // String downloadUrl = await storageReference.getDownloadURL(); + // print("name:${await storageReference.getName()}"); + // print("bucket:${await storageReference.getBucket()}"); + // print("path:${await storageReference.getPath()}"); + // print("meta:${await storageReference.getMetadata()}"); + // return downloadUrl; } Future deleteStorageFromUrls(List urls) async { @@ -62,10 +66,12 @@ Future deleteStorageFromUrls(List urls) async { Future deleteStorageFromUrl(String url) async { try { - StorageReference storageReference = - await FirebaseStorage(storageBucket: Config.instance.bucketName) - .getReferenceFromUrl(url); - await storageReference.delete(); + Reference ref = FirebaseStorage.instance.refFromURL(url); + await ref.delete(); + // StorageReference storageReference = + // await FirebaseStorage(storageBucket: Config.instance.bucketName) + // .getReferenceFromUrl(url); + // await storageReference.delete(); } catch (e) { log.warning("deleteStorage:$e"); } diff --git a/lib/helpers/network_connectivity.dart b/lib/helpers/network_connectivity.dart index fe7c21d..4a7932d 100644 --- a/lib/helpers/network_connectivity.dart +++ b/lib/helpers/network_connectivity.dart @@ -11,7 +11,7 @@ class NetworkConnectivity { final log = Logger('NetworkConnectivity'); static final NetworkConnectivity instance = NetworkConnectivity._internal(); - static String hostName; + static String? hostName; NetworkConnectivity._internal() { _initialise(); var uri = Uri.parse(Config.instance.apiURL); @@ -38,7 +38,7 @@ class NetworkConnectivity { // lookup if connectivity is not none if (result != ConnectivityResult.none) { try { - final hostNameLookup = await InternetAddress.lookup(hostName); + final hostNameLookup = await InternetAddress.lookup(hostName ?? ""); if (hostNameLookup.isNotEmpty && hostNameLookup[0].rawAddress.isNotEmpty) { if (await checkHeartbeat()) { diff --git a/lib/helpers/paginator.dart b/lib/helpers/paginator.dart index cb89f15..240a8e3 100644 --- a/lib/helpers/paginator.dart +++ b/lib/helpers/paginator.dart @@ -13,7 +13,7 @@ class Paginator { final log = Logger('Paginator'); final int rowPerLoad; - DocumentSnapshot prev; + DocumentSnapshot? prev; bool ended = false; bool isLoading = false; List values = []; @@ -21,7 +21,7 @@ class Paginator { Query pageQuery; - Paginator(this.pageQuery, {this.rowPerLoad = 20, this.toObj}) { + Paginator(this.pageQuery, {this.rowPerLoad = 20, required this.toObj}) { _clearState(); } @@ -36,27 +36,27 @@ class Paginator { _clearState(); } - Future refresh({CallBack onFinished}) async { + Future refresh({CallBack? onFinished}) async { _clearState(); await load(); if (onFinished != null) onFinished(); } - Future load({CallBack onFinished}) async { + Future load({CallBack? onFinished}) async { if (ended) return null; isLoading = true; Query _query = - prev != null ? pageQuery.startAfterDocument(prev) : pageQuery; + prev != null ? pageQuery.startAfterDocument(prev!) : pageQuery; try { await _query .limit(rowPerLoad) - .getDocuments(source: Source.server) + .get(GetOptions(source: Source.server)) .then((QuerySnapshot snapshot) { - int count = snapshot.documents.length; + int count = snapshot.docs.length; ended = count < rowPerLoad; - prev = count > 0 ? snapshot.documents[count - 1] : prev; - snapshot.documents.forEach((e) { - values.add(toObj(e.data, e.documentID)); + prev = count > 0 ? snapshot.docs[count - 1] : prev; + snapshot.docs.forEach((e) { + values.add(toObj(e.data() as Map, e.id)); }); }); } catch (e) { diff --git a/lib/helpers/shared_pref.dart b/lib/helpers/shared_pref.dart index d2f26f8..e020232 100644 --- a/lib/helpers/shared_pref.dart +++ b/lib/helpers/shared_pref.dart @@ -7,17 +7,17 @@ class SharedPref { static final SharedPref instance = SharedPref._(); SharedPref._(); - static Future isFirstLaunch() async { + static Future isFirstLaunch() async { SharedPreferences prefs = await SharedPreferences.getInstance(); return prefs.getBool('first_launch'); } static Future finishFirstLaunch() async { SharedPreferences prefs = await SharedPreferences.getInstance(); - return prefs.setBool('first_launch', false); + prefs.setBool('first_launch', false); } - static Future getLang() async { + static Future getLang() async { SharedPreferences prefs = await SharedPreferences.getInstance(); return prefs.getString('language'); } @@ -27,7 +27,7 @@ class SharedPref { prefs.setString('language', lang); } - static Future getStaffMode() async { + static Future getStaffMode() async { SharedPreferences prefs = await SharedPreferences.getInstance(); return prefs.getBool('staff_mode_on'); } @@ -41,7 +41,7 @@ class SharedPref { await _save("user", user.toJson()); } - static Future getUser() async { + static Future getUser() async { try { return User.fromJson(await _read("user")); } catch (e) { @@ -57,7 +57,7 @@ class SharedPref { await _save("skipped_recovery_email", skipped); } - static Future getSkippedRecoverEmail() async { + static Future getSkippedRecoverEmail() async { try { bool _skipped = await _read("skipped_recovery_email"); return _skipped; @@ -69,7 +69,7 @@ class SharedPref { static _read(String key) async { try { final prefs = await SharedPreferences.getInstance(); - return json.decode(prefs.getString(key)); + return json.decode(prefs.getString(key) ?? ""); } catch (e) { print("Error:$e"); } diff --git a/lib/helpers/theme.dart b/lib/helpers/theme.dart index e029208..e3ec100 100644 --- a/lib/helpers/theme.dart +++ b/lib/helpers/theme.dart @@ -20,8 +20,10 @@ const TextStyle labelStyleMM = TextStyle( fontFamily: "Myanmar3"); const TextStyle subMenuStyle = TextStyle(fontSize: 14, color: Colors.white, fontWeight: FontWeight.w500); -const TextStyle subMenuStyleMM = - TextStyle(fontSize: 14, color: Colors.white, fontWeight: FontWeight.w500, +const TextStyle subMenuStyleMM = TextStyle( + fontSize: 14, + color: Colors.white, + fontWeight: FontWeight.w500, fontFamily: "Myanmar3"); const TextStyle welcomeLabelStyle = @@ -31,11 +33,10 @@ const TextStyle welcomeSubLabelStyle = const TextStyle siginButtonStyle = TextStyle(fontSize: 16, color: Colors.white, fontWeight: FontWeight.w500); - TextStyle newLabelStyle( - {Color color, - double fontSize, - FontWeight fontWeight, + {Color? color, + double? fontSize, + FontWeight? fontWeight, bool underline = false}) { return TextStyle( fontSize: fontSize == null ? 14 : fontSize, @@ -45,9 +46,9 @@ TextStyle newLabelStyle( } TextStyle newLabelStyleMM( - {Color color, - double fontSize, - FontWeight fontWeight, + {Color? color, + double? fontSize, + FontWeight? fontWeight, bool underline = false}) { return TextStyle( fontSize: fontSize == null ? 13 : fontSize, @@ -59,8 +60,8 @@ TextStyle newLabelStyleMM( const TextStyle photoLabelStyle = TextStyle(color: Colors.black, fontSize: 13.0); -const TextStyle photoLabelStyleMM = TextStyle( - color: Colors.black, fontSize: 13.0, fontFamily: "Myanmar3"); +const TextStyle photoLabelStyleMM = + TextStyle(color: Colors.black, fontSize: 13.0, fontFamily: "Myanmar3"); const TextStyle textStyle = TextStyle(fontSize: 14, color: Colors.black87, fontWeight: FontWeight.w500); const TextStyle textStyleOdd = TextStyle( diff --git a/pubspec.yaml b/pubspec.yaml index 6d589fb..89b0fa2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -43,7 +43,7 @@ dependencies: permission_handler: ^8.1.4+2 country_code_picker: ^2.0.2 pin_input_text_field: ^4.1.0 - # flutter_icons: ^1.1.0 + flutter_icons_null_safety: ^1.1.0 country_icons: ^2.0.2 timeline_list: ^0.0.5 # barcode_scan: ^2.0.2