add structure
This commit is contained in:
416
lib/pages/setting_editor.dart
Normal file
416
lib/pages/setting_editor.dart
Normal file
@@ -0,0 +1,416 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/language_model.dart';
|
||||
import 'package:fcs/model/main_model.dart';
|
||||
import 'package:fcs/pages/util.dart';
|
||||
import 'package:fcs/theme/theme.dart';
|
||||
import 'package:fcs/vo/setting.dart';
|
||||
import 'package:fcs/widget/local_text.dart';
|
||||
import 'package:fcs/widget/progress.dart';
|
||||
|
||||
class SettingEidtor extends StatefulWidget {
|
||||
final Setting setting;
|
||||
const SettingEidtor({this.setting});
|
||||
@override
|
||||
_SettingEidtorState createState() => _SettingEidtorState();
|
||||
}
|
||||
|
||||
class _SettingEidtorState extends State<SettingEidtor> {
|
||||
TextEditingController _doExpire = new TextEditingController();
|
||||
TextEditingController _poExpire = new TextEditingController();
|
||||
TextEditingController _poOpend = new TextEditingController();
|
||||
TextEditingController _poClosed = new TextEditingController();
|
||||
TextEditingController _latestDeliveryDay = new TextEditingController();
|
||||
TextEditingController _firstStorageDay = new TextEditingController();
|
||||
TextEditingController _firstStorageCharge = new TextEditingController();
|
||||
TextEditingController _secondStorageDay = new TextEditingController();
|
||||
TextEditingController _secondStorgeCharge = new TextEditingController();
|
||||
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
bool _isLoading = false;
|
||||
List<Day> days = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
days = dayLists;
|
||||
if (widget.setting != null) {
|
||||
_doExpire.text = widget.setting.doExpireInHours.toString();
|
||||
_poExpire.text = widget.setting.poExpireInHours.toString();
|
||||
_poOpend.text = widget.setting.poOpenAt.toString();
|
||||
_poClosed.text = widget.setting.poCloseAt.toString();
|
||||
_latestDeliveryDay.text =widget.setting.latestDeliveryDay.toString();
|
||||
_firstStorageDay.text = widget.setting.firstStorageChargeIn.toString();
|
||||
_firstStorageCharge.text = widget.setting.firstStorageCharge.toString();
|
||||
_secondStorageDay.text = widget.setting.secondStorageChargeIn.toString();
|
||||
_secondStorgeCharge.text = widget.setting.secondStorageCharge.toString();
|
||||
|
||||
days.forEach((d) => widget.setting.poCloseOn.contains(d.id)
|
||||
? d.isChecked = true
|
||||
: d.isChecked = false);
|
||||
}
|
||||
}
|
||||
|
||||
Widget showDayList(BuildContext context, MainModel mainModel) {
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(vertical: 5.0),
|
||||
height: 75.0,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 10, top: 10),
|
||||
child: Text(
|
||||
"PO submission closed Day",
|
||||
style: TextStyle(color: Colors.black54),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: days.length,
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return new Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
new Checkbox(
|
||||
value: days[index].isChecked == null
|
||||
? false
|
||||
: days[index].isChecked,
|
||||
activeColor: primaryColor,
|
||||
onChanged: (bool value) {
|
||||
setState(() {
|
||||
days[index].isChecked = value;
|
||||
});
|
||||
}),
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 13),
|
||||
child: new Text(
|
||||
dayLists[index].name,
|
||||
style: TextStyle(
|
||||
fontSize: 15.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var languageModel = Provider.of<LanguageModel>(context);
|
||||
var mainModel = Provider.of<MainModel>(context);
|
||||
|
||||
final doExpireBox = TextFormField(
|
||||
controller: _doExpire,
|
||||
autofocus: false,
|
||||
cursorColor: primaryColor,
|
||||
keyboardType: TextInputType.phone,
|
||||
style: textStyle,
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'DO expired Time',
|
||||
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.clock,
|
||||
color: primaryColor,
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter DO expired Time';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final poExpireBox = TextFormField(
|
||||
controller: _poExpire,
|
||||
autofocus: false,
|
||||
cursorColor: primaryColor,
|
||||
keyboardType: TextInputType.phone,
|
||||
style: textStyle,
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'PO expired Time',
|
||||
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.clock,
|
||||
color: primaryColor,
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter PO expired Time';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final poOpenedBox = TextFormField(
|
||||
controller: _poOpend,
|
||||
autofocus: false,
|
||||
cursorColor: primaryColor,
|
||||
keyboardType: TextInputType.phone,
|
||||
style: textStyle,
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'PO submission opened Time',
|
||||
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.clock,
|
||||
color: primaryColor,
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter PO submission opened Time';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final poClosedBox = TextFormField(
|
||||
controller: _poClosed,
|
||||
autofocus: false,
|
||||
cursorColor: primaryColor,
|
||||
keyboardType: TextInputType.phone,
|
||||
style: textStyle,
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'PO submission closed Time',
|
||||
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.clock,
|
||||
color: primaryColor,
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter PO submission closed Time';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final latestDeliveryDayBox = TextFormField(
|
||||
controller: _latestDeliveryDay,
|
||||
autofocus: false,
|
||||
cursorColor: primaryColor,
|
||||
keyboardType: TextInputType.phone,
|
||||
style: textStyle,
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'Latest Delivery Day',
|
||||
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.clock,
|
||||
color: primaryColor,
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter Latest Delivery Day';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final firstStorageDayBox = TextFormField(
|
||||
controller: _firstStorageDay,
|
||||
autofocus: false,
|
||||
cursorColor: primaryColor,
|
||||
keyboardType: TextInputType.phone,
|
||||
style: textStyle,
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'First storage charge starts Day',
|
||||
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.calendarDay,
|
||||
color: primaryColor,
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter First storage charge starts Day';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final firstStorgeChargeBox = TextFormField(
|
||||
controller: _firstStorageCharge,
|
||||
autofocus: false,
|
||||
cursorColor: primaryColor,
|
||||
keyboardType: TextInputType.phone,
|
||||
style: textStyle,
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'First storage charge Fees',
|
||||
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.sortNumericUp,
|
||||
color: primaryColor,
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter First storage charge Fees';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final secondStorgeDayBox = TextFormField(
|
||||
controller: _secondStorageDay,
|
||||
autofocus: false,
|
||||
cursorColor: primaryColor,
|
||||
keyboardType: TextInputType.phone,
|
||||
style: textStyle,
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'Second storage charge starts Day',
|
||||
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.calendarDay,
|
||||
color: primaryColor,
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter Second storage charge starts Day';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final secondStorgeChargeBox = TextFormField(
|
||||
controller: _secondStorgeCharge,
|
||||
autofocus: false,
|
||||
cursorColor: primaryColor,
|
||||
keyboardType: TextInputType.phone,
|
||||
style: textStyle,
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'Second storage charge Fees',
|
||||
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.sortNumericUp,
|
||||
color: primaryColor,
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter Second storage charge Fees';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(
|
||||
context,
|
||||
"setting.title",
|
||||
fontSize: 20,
|
||||
color: Colors.white,
|
||||
),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.send),
|
||||
onPressed: () {
|
||||
if (!_formKey.currentState.validate()) return;
|
||||
showConfirmDialog(context, "setting.confirm", () {
|
||||
_submit();
|
||||
});
|
||||
})
|
||||
],
|
||||
),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
||||
children: <Widget>[
|
||||
// doExpireBox,
|
||||
poExpireBox,
|
||||
poOpenedBox,
|
||||
poClosedBox,
|
||||
showDayList(context, mainModel),
|
||||
latestDeliveryDayBox,
|
||||
firstStorageDayBox,
|
||||
firstStorgeChargeBox,
|
||||
secondStorgeDayBox,
|
||||
secondStorgeChargeBox
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
_submit() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
widget.setting.poExpireInHours = int.parse(_poExpire.text);
|
||||
widget.setting.poOpenAt = int.parse(_poOpend.text);
|
||||
widget.setting.poCloseAt = int.parse(_poClosed.text);
|
||||
widget.setting.latestDeliveryDay=int.parse(_latestDeliveryDay.text);
|
||||
widget.setting.firstStorageChargeIn = int.parse(_firstStorageDay.text);
|
||||
widget.setting.firstStorageCharge = int.parse(_firstStorageCharge.text);
|
||||
widget.setting.secondStorageChargeIn = int.parse(_secondStorageDay.text);
|
||||
widget.setting.secondStorageCharge = int.parse(_secondStorgeCharge.text);
|
||||
widget.setting.poCloseOn =
|
||||
this.days.where((d) => d.isChecked == true).map((p) => p.id).toList();
|
||||
var mainModel = Provider.of<MainModel>(context);
|
||||
await mainModel.updateSetting(widget.setting);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user