null safety

This commit is contained in:
Phaung Phaung
2021-09-10 14:29:55 +06:30
parent 5a313d641e
commit d862049b45
22 changed files with 93 additions and 51 deletions

View File

@@ -22,6 +22,7 @@ import 'package:fcs/pages/widgets/local_title.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
@@ -214,7 +215,7 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
);
final shipmentWeightBox = DisplayText(
text: shipmentWeight.toStringAsFixed(0) : "",
text: shipmentWeight.toStringAsFixed(0),
labelTextKey: "box.shipment_weight",
iconData: MaterialCommunityIcons.weight,
);

View File

@@ -3,6 +3,7 @@ import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:intl/intl.dart';
import 'delivery_info.dart';

View File

@@ -8,6 +8,7 @@ import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:provider/provider.dart';
class DeliveryAddressEditor extends StatefulWidget {

View File

@@ -3,6 +3,7 @@ import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
typedef SelectionCallback(DeliveryAddress deliveryAddress);

View File

@@ -9,6 +9,7 @@ import 'package:fcs/pages/widgets/input_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';

View File

@@ -5,6 +5,7 @@ import 'package:fcs/pages/discount/discount_editor.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:intl/intl.dart';
typedef OnSelect(Discount discount);

View File

@@ -10,6 +10,7 @@ import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:provider/provider.dart';
const info = "Select additional page";

View File

@@ -7,14 +7,14 @@ Widget itemTitle(BuildContext context, String textKey) {
return Padding(
padding: const EdgeInsets.only(left: 18.0, top: 15, bottom: 0),
child: Text(
AppTranslations.of(context).text(textKey),
AppTranslations.of(context)!.text(textKey),
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 18, color: Colors.black),
),
);
}
Widget subItemTitle(BuildContext context, String textKey, {IconData iconData}) {
Widget subItemTitle(BuildContext context, String textKey, {IconData? iconData}) {
return Padding(
padding: const EdgeInsets.only(left: 0, top: 0, bottom: 0),
child: Row(
@@ -25,7 +25,7 @@ Widget subItemTitle(BuildContext context, String textKey, {IconData iconData}) {
),
SizedBox(width: 10),
Text(
AppTranslations.of(context).text(textKey),
AppTranslations.of(context)!.text(textKey),
style: TextStyle(
fontWeight: FontWeight.w700, fontSize: 15, color: primaryColor),
),
@@ -35,7 +35,7 @@ Widget subItemTitle(BuildContext context, String textKey, {IconData iconData}) {
}
Widget contactItem(BuildContext context, String text, IconData iconData,
{Function() onTap, String labelKey}) {
{Function()? onTap, String? labelKey}) {
return Material(
child: Padding(
padding: const EdgeInsets.only(left: 18.0, bottom: 10, right: 18),

View File

@@ -143,7 +143,7 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
labelStyle: languageModel.isEng
? newLabelStyle(color: Colors.black54, fontSize: 20)
: newLabelStyleMM(color: Colors.black54, fontSize: 20),
labelText: AppTranslations.of(context)
labelText: AppTranslations.of(context)!
.text('FCSshipment.shipment_type'),
icon: Icon(Ionicons.ios_airplane, color: primaryColor)),
items: mainModel.setting.shipmentTypes

View File

@@ -77,7 +77,7 @@ class _ProfileCurrencyEditState extends State<ProfileCurrencyEdit> {
onChanged: (Currency? value) {
if(value != null)
setState(() {
_currency = value!;
_currency = value;
});
},
),
@@ -96,7 +96,7 @@ class _ProfileCurrencyEditState extends State<ProfileCurrencyEdit> {
onChanged: (Currency? value) {
if(value != null)
setState(() {
_currency = value!;
_currency = value;
});
},
),

View File

@@ -31,8 +31,8 @@ class _CargoEditorState extends State<CargoEditor> {
super.initState();
if (widget.cargo != null) {
_cargo = widget.cargo!;
_descController.text = _cargo.name;
_rateController.text = _cargo.rate.toStringAsFixed(2);
_descController.text = _cargo.name ?? '';
_rateController.text = _cargo.rate?.toStringAsFixed(2) ?? '';
} else {
_isNew = true;
}
@@ -138,7 +138,8 @@ class _CargoEditorState extends State<CargoEditor> {
try {
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
await shipmentRateModel.deleteCargoType(this._cargo.id);
if(this._cargo.id != null)
await shipmentRateModel.deleteCargoType(this._cargo.id!);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -75,8 +75,8 @@ class _CargoTypeListState extends State<CargoTypeList> {
)));
},
child: Container(
child: _row(cargo.name,
"\$ " + cargo.rate.toStringAsFixed(2), 'per pound'),
child: _row(cargo.name?? '',
"\$ " + cargo.rate!.toStringAsFixed(2), 'per pound'),
),
);
}),

View File

@@ -33,10 +33,10 @@ class _CustomEditorState extends State<CustomEditor> {
super.initState();
if (widget.custom != null) {
_custom = widget.custom!;
_productController.text = _custom.name;
_feeController.text = _custom.customDutyFee.toStringAsFixed(2);
_productController.text = _custom.name ?? '';
_feeController.text = _custom.customDutyFee?.toStringAsFixed(2) ?? '';
_shipmentRateController.text =
_custom.rate == null ? "" : _custom.rate.toStringAsFixed(2);
_custom.rate == null ? "" : _custom.rate?.toStringAsFixed(2) ?? '';
} else {
_isNew = true;
}
@@ -154,7 +154,8 @@ class _CustomEditorState extends State<CustomEditor> {
try {
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
await shipmentRateModel.deleteCustomDuty(this._custom.id);
if(this._custom.id != null)
await shipmentRateModel.deleteCustomDuty(this._custom.id!);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -81,11 +81,15 @@ class _CustomListState extends State<CustomList> {
},
child: Container(
child: _row(
custom.name,
"Custom Fee \$ " + custom.customDutyFee.toStringAsFixed(2),
custom.name ?? '',
custom.customDutyFee == null
? ""
: "Custom Fee \$ " +
custom.customDutyFee!.toStringAsFixed(2),
custom.rate == null
? ""
: "Shipment rate \$ " + custom.rate.toStringAsFixed(2)),
: "Shipment rate \$ " +
custom.rate!.toStringAsFixed(2)),
),
);
}),

View File

@@ -4,6 +4,7 @@ import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
typedef SelectionCallback(CustomDuty custom);

View File

@@ -1,5 +1,4 @@
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/custom_duty.dart';
import 'package:fcs/domain/entities/discount_by_weight.dart';
import 'package:fcs/domain/entities/rate.dart';
import 'package:fcs/helpers/theme.dart';
@@ -186,7 +185,7 @@ class _ShipmentRatesState extends State<ShipmentRates> {
return cargos.map((cargo) {
return Container(
child: _row(
cargo.name, "\$ " + cargo.rate.toStringAsFixed(2), 'per pound'),
cargo.name ?? '', "\$ " + cargo.rate!.toStringAsFixed(2), 'per pound'),
);
}).toList();
}
@@ -194,7 +193,7 @@ class _ShipmentRatesState extends State<ShipmentRates> {
List<Widget> getCustonWidget(List<CargoType> customs) {
return customs.map((c) {
return Container(
child: _row(c.name, "\$ " + c.customDutyFee.toStringAsFixed(2), ''),
child: _row(c.name ?? '', "\$ " + c.customDutyFee!.toStringAsFixed(2), ''),
);
}).toList();
}

View File

@@ -11,6 +11,7 @@ import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:provider/provider.dart';
class ShipmentRatesCal extends StatefulWidget {
@@ -61,11 +62,11 @@ class _ShipmentRatesCalState extends State<ShipmentRatesCal> {
var amount = box.calAmount(rate);
var shipmentWeight = box.getShipmentWeight(rate.volumetricRatio);
var effectiveWeight =
_cargoType.weight > shipmentWeight ? _cargoType.weight : shipmentWeight;
_cargoType.weight! > shipmentWeight ? _cargoType.weight : shipmentWeight;
setState(() {
_deliveryFee =
effectiveWeight > rate.freeDeliveryWeight ? 0 : rate.deliveryFee;
effectiveWeight! > rate.freeDeliveryWeight ? 0 : rate.deliveryFee;
_amount = amount == null ? 0 : amount + _deliveryFee;
_shipmentWeight = shipmentWeight.toDouble();
});

View File

@@ -15,7 +15,7 @@ import 'package:provider/provider.dart';
typedef void FindCallBack();
class StaffEditor extends StatefulWidget {
final User staff;
final User? staff;
const StaffEditor({this.staff});
@override
_StaffEditorState createState() => _StaffEditorState();
@@ -25,8 +25,8 @@ class _StaffEditorState extends State<StaffEditor> {
TextEditingController _phoneInput = new TextEditingController();
bool _isLoading = false;
User user;
User selectedUser;
late User user;
User? selectedUser;
List<Privilege> privileges = [];
bool isNew = true;
@@ -38,8 +38,8 @@ class _StaffEditorState extends State<StaffEditor> {
user = User();
if (!isNew) {
user =
User(name: widget.staff.name, phoneNumber: widget.staff.phoneNumber);
user.privileges = widget.staff.privileges;
User(name: widget.staff!.name, phoneNumber: widget.staff!.phoneNumber);
user.privileges = widget.staff!.privileges;
privileges.forEach((p) => user.privileges.contains(p.id)
? p.isChecked = true
: p.isChecked = false);
@@ -64,7 +64,8 @@ class _StaffEditorState extends State<StaffEditor> {
new Checkbox(
value: p.isChecked == null ? false : p.isChecked,
activeColor: primaryColor,
onChanged: (bool value) {
onChanged: (bool? value) {
if(value != null)
setState(() {
p.isChecked = value;
});
@@ -110,7 +111,7 @@ class _StaffEditorState extends State<StaffEditor> {
style: textStyle,
decoration: new InputDecoration(
labelText:
AppTranslations.of(context).text('staff.phone.search'),
AppTranslations.of(context)!.text('staff.phone.search'),
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
// icon: Icon(
// Icons.search,
@@ -226,7 +227,7 @@ class _StaffEditorState extends State<StaffEditor> {
});
StaffModel staffModel = Provider.of<StaffModel>(context, listen: false);
try {
await staffModel.updatePrivileges(this.selectedUser.id, privilegesIDs());
await staffModel.updatePrivileges(this.selectedUser!.id, privilegesIDs());
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
@@ -248,7 +249,7 @@ class _StaffEditorState extends State<StaffEditor> {
if (widget.staff == null) return;
StaffModel staffModel = Provider.of<StaffModel>(context, listen: false);
try {
await staffModel.updatePrivileges(widget.staff.id, privilegesIDs());
await staffModel.updatePrivileges(widget.staff!.id, privilegesIDs());
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -5,7 +5,6 @@ import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
@@ -84,7 +83,7 @@ class _StaffListState extends State<StaffList> {
padding: new EdgeInsets.symmetric(
horizontal: 32.0 - dotSize / 2),
child: Icon(
MaterialCommunityIcons.worker,
Icons.person,
color: primaryColor,
size: 40,
),

View File

@@ -4,9 +4,9 @@ import 'package:fcs/pages/user_search/user_serach.dart';
import 'package:flutter/material.dart';
class UserListRow extends StatefulWidget {
final OnUserRowSelect onUserRowSelect;
final OnUserRowSelect? onUserRowSelect;
final User user;
const UserListRow({this.user, this.onUserRowSelect});
const UserListRow({required this.user, this.onUserRowSelect});
@override
_UserListRowState createState() => _UserListRowState();
@@ -14,7 +14,7 @@ class UserListRow extends StatefulWidget {
class _UserListRowState extends State<UserListRow> {
final double dotSize = 15.0;
User user;
late User user;
@override
void initState() {
super.initState();
@@ -31,7 +31,7 @@ class _UserListRowState extends State<UserListRow> {
child: InkWell(
onTap: () {
if (widget.onUserRowSelect != null)
widget.onUserRowSelect(widget.user);
widget.onUserRowSelect!(widget.user);
},
child: Row(
children: <Widget>[

View File

@@ -8,8 +8,8 @@ import 'package:provider/provider.dart';
typedef OnUserSelect(User suer);
typedef OnUserRowSelect(User suer);
Future<User> searchUser(BuildContext context,
{OnUserSelect onUserSelect, bool popPage = false}) async =>
Future<User?> searchUser(BuildContext context,
{required OnUserSelect onUserSelect, bool popPage = false}) async =>
await showSearch<User>(
context: context,
delegate:
@@ -17,10 +17,10 @@ Future<User> searchUser(BuildContext context,
);
class UserSearchDelegate extends SearchDelegate<User> {
final OnUserSelect onUserSelect;
final OnUserSelect? onUserSelect;
final bool popPage;
UserSearchDelegate({this.onUserSelect, this.popPage});
UserSearchDelegate({this.onUserSelect, required this.popPage});
@override
String get searchFieldLabel => 'Search by FCS ID or Name';
@@ -31,10 +31,10 @@ class UserSearchDelegate extends SearchDelegate<User> {
return theme.copyWith(
inputDecorationTheme: InputDecorationTheme(
hintStyle: TextStyle(
color: theme.primaryTextTheme.caption.color, fontSize: 14)),
color: theme.primaryTextTheme.caption?.color, fontSize: 14)),
textTheme: theme.textTheme.copyWith(
title: theme.textTheme.title.copyWith(
color: theme.primaryTextTheme.title.color, fontSize: 16)),
title: theme.textTheme.title?.copyWith(
color: theme.primaryTextTheme.title?.color, fontSize: 16)),
primaryColor: primaryColor,
);
}
@@ -53,7 +53,7 @@ class UserSearchDelegate extends SearchDelegate<User> {
Widget buildLeading(BuildContext context) {
return IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => close(context, null),
onPressed: () => close(context,User()),
);
}
@@ -64,7 +64,7 @@ class UserSearchDelegate extends SearchDelegate<User> {
future: packageModel.searchUser(query),
builder: (context, AsyncSnapshot<List<User>> snapshot) {
if (snapshot.hasData) {
if (snapshot.data.length == 0) {
if (snapshot.data?.length == 0) {
return Container(
child: Center(
child: Text(
@@ -77,7 +77,7 @@ class UserSearchDelegate extends SearchDelegate<User> {
return Container(
padding: EdgeInsets.only(top: 15),
child: ListView(
children: snapshot.data
children: snapshot.data!
.map((u) => UserListRow(
user: u,
onUserRowSelect: (u) => _onUserRowSelect(context, u),
@@ -119,7 +119,7 @@ class UserSearchDelegate extends SearchDelegate<User> {
_onUserRowSelect(BuildContext context, User user) {
if (onUserSelect != null) {
onUserSelect(user);
onUserSelect!(user);
}
if (popPage) {
Navigator.pop(context);