update
This commit is contained in:
@@ -11,7 +11,7 @@ import 'package:provider/provider.dart';
|
||||
import 'model/shipment_rate_model.dart';
|
||||
|
||||
class CargoEditor extends StatefulWidget {
|
||||
final CargoType cargo;
|
||||
final CargoType? cargo;
|
||||
CargoEditor({this.cargo});
|
||||
|
||||
@override
|
||||
@@ -23,14 +23,14 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
TextEditingController _rateController = new TextEditingController();
|
||||
|
||||
bool _isLoading = false;
|
||||
CargoType _cargo;
|
||||
late CargoType _cargo;
|
||||
bool _isNew = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.cargo != null) {
|
||||
_cargo = widget.cargo;
|
||||
_cargo = widget.cargo!;
|
||||
_descController.text = _cargo.name;
|
||||
_rateController.text = _cargo.rate.toStringAsFixed(2);
|
||||
} else {
|
||||
@@ -71,7 +71,7 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
},
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
title: Text(AppTranslations.of(context).text("cargo.form.title")),
|
||||
title: Text(AppTranslations.of(context)!.text("cargo.form.title")),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
@@ -114,7 +114,7 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
if (_isNew) {
|
||||
await shipmentRateModel.addCargoType(_cargo);
|
||||
} else {
|
||||
_cargo.id = widget.cargo.id;
|
||||
_cargo.id = this._cargo.id;
|
||||
await shipmentRateModel.updateCargoType(_cargo);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
@@ -138,7 +138,7 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
try {
|
||||
var shipmentRateModel =
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
await shipmentRateModel.deleteCargoType(widget.cargo.id);
|
||||
await shipmentRateModel.deleteCargoType(this._cargo.id);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
@@ -155,7 +155,7 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
} else {
|
||||
CargoType _cargo = CargoType(
|
||||
name: _descController.text, rate: double.parse(_rateController.text));
|
||||
return widget.cargo.isChangedForEdit(_cargo);
|
||||
return this._cargo.isChangedForEdit(_cargo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user