update cargo type form from rate, update carton info and form
This commit is contained in:
@@ -4,9 +4,11 @@ import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/input_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../widgets/local_text.dart';
|
||||
import 'model/shipment_rate_model.dart';
|
||||
|
||||
class CargoEditor extends StatefulWidget {
|
||||
@@ -20,11 +22,13 @@ class CargoEditor extends StatefulWidget {
|
||||
class _CargoEditorState extends State<CargoEditor> {
|
||||
TextEditingController _descController = new TextEditingController();
|
||||
TextEditingController _rateController = new TextEditingController();
|
||||
TextEditingController _displayIndexController = new TextEditingController();
|
||||
|
||||
bool _isLoading = false;
|
||||
late CargoType _cargo;
|
||||
bool _isNew = false;
|
||||
final _cargoFormKey = GlobalKey<FormState>();
|
||||
bool _isDefault = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -33,6 +37,8 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
_cargo = widget.cargo!;
|
||||
_descController.text = _cargo.name ?? "";
|
||||
_rateController.text = _cargo.rate.toStringAsFixed(2);
|
||||
_displayIndexController.text = _cargo.displayIndex.toString();
|
||||
_isDefault = _cargo.isDefault;
|
||||
} else {
|
||||
_isNew = true;
|
||||
}
|
||||
@@ -46,20 +52,23 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final typeBox = InputText(
|
||||
labelTextKey: 'cargo.type',
|
||||
iconData: Icons.text_format,
|
||||
controller: _descController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value){
|
||||
if(value==null || value.isEmpty){
|
||||
return "Please insert cargo type";
|
||||
}
|
||||
return null;
|
||||
},);
|
||||
labelTextKey: 'cargo.type',
|
||||
iconData: Icons.text_format,
|
||||
controller: _descController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Please insert cargo type";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final rateBox = InputText(
|
||||
labelTextKey: 'cargo.rate',
|
||||
iconData: Icons.attach_money,
|
||||
controller: _rateController,
|
||||
textInputType: TextInputType.number,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
@@ -68,6 +77,51 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final displayIndexBox = InputText(
|
||||
labelTextKey: 'cargo.display_index',
|
||||
iconData: Icons.numbers,
|
||||
controller: _displayIndexController,
|
||||
textInputType: TextInputType.number,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Please insert display index";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final defaultBox = Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 20),
|
||||
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
||||
Flexible(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
LocalText(
|
||||
context,
|
||||
'cargo.is_default',
|
||||
color: Colors.black54,
|
||||
fontSize: 15,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Transform.scale(
|
||||
scale: 0.7,
|
||||
alignment: Alignment.centerRight,
|
||||
child: CupertinoSwitch(
|
||||
activeColor: primaryColor,
|
||||
value: _isDefault,
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
_isDefault = v;
|
||||
});
|
||||
}))
|
||||
]),
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
@@ -105,6 +159,8 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
children: <Widget>[
|
||||
typeBox,
|
||||
rateBox,
|
||||
displayIndexBox,
|
||||
defaultBox,
|
||||
SizedBox(height: 30),
|
||||
],
|
||||
),
|
||||
@@ -131,7 +187,10 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
var shipmentRateModel =
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
CargoType _cargo = CargoType(
|
||||
name: _descController.text, rate: double.parse(_rateController.text));
|
||||
name: _descController.text,
|
||||
rate: double.parse(_rateController.text),
|
||||
displayIndex: int.parse(_displayIndexController.text),
|
||||
isDefault: _isDefault);
|
||||
if (_isNew) {
|
||||
await shipmentRateModel.addCargoType(_cargo);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user