|
|
|
@@ -0,0 +1,283 @@ |
|
|
|
import 'package:farm_tpf/custom_model/Nursery.dart'; |
|
|
|
import 'package:farm_tpf/data/repository/repository.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_string.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_style.dart'; |
|
|
|
import 'package:farm_tpf/utils/pref.dart'; |
|
|
|
import 'package:farm_tpf/utils/validators.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; |
|
|
|
import 'package:fluttertoast/fluttertoast.dart'; |
|
|
|
import 'package:intl/intl.dart'; |
|
|
|
import 'package:keyboard_dismisser/keyboard_dismisser.dart'; |
|
|
|
import 'package:pattern_formatter/pattern_formatter.dart'; |
|
|
|
import 'package:farm_tpf/utils/formatter.dart'; |
|
|
|
|
|
|
|
class EditActionNursery extends StatefulWidget { |
|
|
|
@override |
|
|
|
_EditActionNurseryState createState() => _EditActionNurseryState(); |
|
|
|
} |
|
|
|
|
|
|
|
class _EditActionNurseryState extends State<EditActionNursery> { |
|
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); |
|
|
|
final _repository = Repository(); |
|
|
|
GlobalKey<FormState> _formKey = GlobalKey(); |
|
|
|
bool _autoValidate = false; |
|
|
|
Nursery _nursery = Nursery(); |
|
|
|
var pref = LocalPref(); |
|
|
|
FlutterToast flutterToast; |
|
|
|
TextEditingController _substrateController = TextEditingController(); |
|
|
|
TextEditingController _seedLengthController = TextEditingController(); |
|
|
|
TextEditingController _quantityController = TextEditingController(); |
|
|
|
TextEditingController _seedIncubationTimeController = TextEditingController(); |
|
|
|
TextEditingController _descriptionController = TextEditingController(); |
|
|
|
String executeTimeView; |
|
|
|
DateTime executeTime = DateTime.now(); |
|
|
|
|
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
super.initState(); |
|
|
|
flutterToast = FlutterToast(context); |
|
|
|
//UPDATE |
|
|
|
if (_nursery != null) { |
|
|
|
try { |
|
|
|
executeTime = |
|
|
|
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse(_nursery.executeDate); |
|
|
|
} catch (_) {} |
|
|
|
} else { |
|
|
|
//ADD NEW |
|
|
|
var parsedExecuteDate = |
|
|
|
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(executeTime); |
|
|
|
_nursery.executeDate = "$parsedExecuteDate"; |
|
|
|
} |
|
|
|
executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(executeTime); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _btnExecuteTimePicker() { |
|
|
|
return FlatButton( |
|
|
|
padding: EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), |
|
|
|
onPressed: () { |
|
|
|
DatePicker.showDateTimePicker(context, |
|
|
|
showTitleActions: true, onChanged: (date) {}, onConfirm: (date) { |
|
|
|
setState(() { |
|
|
|
var parsedDate = |
|
|
|
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(date); |
|
|
|
_nursery.executeDate = "$parsedDate"; |
|
|
|
executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(date); |
|
|
|
}); |
|
|
|
}, currentTime: executeTime, locale: LocaleType.vi); |
|
|
|
}, |
|
|
|
child: Container( |
|
|
|
padding: |
|
|
|
EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), |
|
|
|
decoration: BoxDecoration( |
|
|
|
border: kBorderTextField, |
|
|
|
), |
|
|
|
child: Row( |
|
|
|
children: [ |
|
|
|
Expanded( |
|
|
|
child: Text( |
|
|
|
//TODO: check condition |
|
|
|
executeTimeView == null ? "$executeTime" : executeTimeView, |
|
|
|
style: TextStyle(fontSize: 14.0, color: Colors.black87), |
|
|
|
)), |
|
|
|
Icon( |
|
|
|
Icons.date_range, |
|
|
|
color: Colors.blue, |
|
|
|
), |
|
|
|
], |
|
|
|
))); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _btnSelectSeed() { |
|
|
|
return FlatButton( |
|
|
|
padding: EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), |
|
|
|
onPressed: () {}, |
|
|
|
child: Container( |
|
|
|
padding: |
|
|
|
EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), |
|
|
|
decoration: BoxDecoration( |
|
|
|
border: kBorderTextField, |
|
|
|
), |
|
|
|
child: Row( |
|
|
|
children: [ |
|
|
|
Expanded( |
|
|
|
child: Text( |
|
|
|
"Tên giống", |
|
|
|
style: TextStyle(fontSize: 14.0, color: Colors.black87), |
|
|
|
)), |
|
|
|
Icon( |
|
|
|
Icons.arrow_drop_down, |
|
|
|
color: Colors.grey, |
|
|
|
), |
|
|
|
], |
|
|
|
))); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _subStratesField() { |
|
|
|
return TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
decoration: InputDecoration(labelText: "Loại giá thể"), |
|
|
|
controller: _substrateController, |
|
|
|
validator: (String value) { |
|
|
|
return Validators.validateNotNullOrEmpty(value, "Loại giá thể"); |
|
|
|
}, |
|
|
|
onSaved: (newValue) { |
|
|
|
_nursery.substrates = newValue; |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _seedLengthField() { |
|
|
|
return TextFormField( |
|
|
|
keyboardType: TextInputType.numberWithOptions(decimal: true), |
|
|
|
inputFormatters: [ |
|
|
|
ThousandsFormatter( |
|
|
|
formatter: NumberFormat("#,###.##", "es"), allowFraction: true) |
|
|
|
], |
|
|
|
decoration: InputDecoration(labelText: "Chiều dài mần"), |
|
|
|
controller: _seedLengthController, |
|
|
|
validator: (String value) { |
|
|
|
return Validators.validNumber(value, "Chiều dài mần"); |
|
|
|
}, |
|
|
|
onSaved: (newValue) { |
|
|
|
_nursery.seedLength = newValue.parseDoubleThousand(); |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _quantityField() { |
|
|
|
return TextFormField( |
|
|
|
keyboardType: TextInputType.numberWithOptions(decimal: true), |
|
|
|
inputFormatters: [ |
|
|
|
ThousandsFormatter( |
|
|
|
formatter: NumberFormat("#,###.##", "es"), allowFraction: true) |
|
|
|
], |
|
|
|
decoration: InputDecoration(labelText: "Số lượng hạt gieo"), |
|
|
|
controller: _quantityController, |
|
|
|
validator: (String value) { |
|
|
|
return Validators.validNumber(value, "Số lượng hạt gieo"); |
|
|
|
}, |
|
|
|
onSaved: (newValue) { |
|
|
|
_nursery.quantity = newValue.parseDoubleThousand(); |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _seedIncubationTimeField() { |
|
|
|
return TextFormField( |
|
|
|
keyboardType: TextInputType.numberWithOptions(decimal: true), |
|
|
|
inputFormatters: [ |
|
|
|
ThousandsFormatter( |
|
|
|
formatter: NumberFormat("#,###.##", "es"), allowFraction: true) |
|
|
|
], |
|
|
|
decoration: InputDecoration(labelText: "Thời gian ngâm hạt"), |
|
|
|
controller: _seedIncubationTimeController, |
|
|
|
validator: (String value) { |
|
|
|
return Validators.validNumber(value, "Thời gian ngâm hạt"); |
|
|
|
}, |
|
|
|
onSaved: (newValue) { |
|
|
|
_nursery.seedIncubationTime = newValue.parseDoubleThousand(); |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _desciptionField() { |
|
|
|
return TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
decoration: InputDecoration(labelText: "Ghi chú"), |
|
|
|
controller: _descriptionController, |
|
|
|
onSaved: (newValue) { |
|
|
|
_nursery.description = newValue; |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
_actionAppBar() { |
|
|
|
IconButton iconButton; |
|
|
|
if (1 == 1) { |
|
|
|
iconButton = IconButton( |
|
|
|
icon: Icon( |
|
|
|
Icons.done, |
|
|
|
color: Colors.black, |
|
|
|
), |
|
|
|
onPressed: () {}, |
|
|
|
); |
|
|
|
return <Widget>[iconButton]; |
|
|
|
} |
|
|
|
return <Widget>[Container()]; |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) => KeyboardDismisser( |
|
|
|
gestures: [ |
|
|
|
GestureType.onTap, |
|
|
|
GestureType.onPanUpdateDownDirection, |
|
|
|
], |
|
|
|
child: Scaffold( |
|
|
|
key: _scaffoldKey, |
|
|
|
appBar: AppBar( |
|
|
|
centerTitle: true, |
|
|
|
title: Text(plot_action_nursery), |
|
|
|
actions: _actionAppBar()), |
|
|
|
body: KeyboardDismisser( |
|
|
|
child: Form( |
|
|
|
key: _formKey, |
|
|
|
autovalidate: _autoValidate, |
|
|
|
child: SingleChildScrollView( |
|
|
|
padding: EdgeInsets.all(8.0), |
|
|
|
child: Column( |
|
|
|
children: <Widget>[ |
|
|
|
Container( |
|
|
|
width: double.infinity, |
|
|
|
child: Text( |
|
|
|
"Ngày thực hiện", |
|
|
|
style: TextStyle( |
|
|
|
color: Colors.black54, fontSize: 13.0), |
|
|
|
), |
|
|
|
), |
|
|
|
_btnExecuteTimePicker(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
Container( |
|
|
|
width: double.infinity, |
|
|
|
child: Text( |
|
|
|
"Tên giống", |
|
|
|
style: TextStyle( |
|
|
|
color: Colors.black54, fontSize: 13.0), |
|
|
|
), |
|
|
|
), |
|
|
|
_btnSelectSeed(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_subStratesField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_seedLengthField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_quantityField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_seedIncubationTimeField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_desciptionField() |
|
|
|
], |
|
|
|
), |
|
|
|
))))); |
|
|
|
@override |
|
|
|
void dispose() { |
|
|
|
_substrateController.dispose(); |
|
|
|
_seedLengthController.dispose(); |
|
|
|
_quantityController.dispose(); |
|
|
|
_seedIncubationTimeController.dispose(); |
|
|
|
_descriptionController.dispose(); |
|
|
|
super.dispose(); |
|
|
|
} |
|
|
|
} |