|
|
|
@@ -1,4 +1,13 @@ |
|
|
|
import 'package:farm_tpf/data/repository/repository.dart'; |
|
|
|
import 'package:farm_tpf/models/index.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'; |
|
|
|
|
|
|
|
class EditActionOtherScreen extends StatefulWidget { |
|
|
|
@override |
|
|
|
@@ -6,8 +15,110 @@ class EditActionOtherScreen extends StatefulWidget { |
|
|
|
} |
|
|
|
|
|
|
|
class _EditActionOtherScreenState extends State<EditActionOtherScreen> { |
|
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); |
|
|
|
final _repository = Repository(); |
|
|
|
GlobalKey<FormState> _formKey = GlobalKey(); |
|
|
|
bool _autoValidate = false; |
|
|
|
OtherAction _otherAction = OtherAction(); |
|
|
|
var pref = LocalPref(); |
|
|
|
FlutterToast flutterToast; |
|
|
|
TextEditingController _descriptionController = TextEditingController(); |
|
|
|
TextEditingController _workerNameController = TextEditingController(); |
|
|
|
String executeTimeView; |
|
|
|
DateTime executeTime = DateTime.now(); |
|
|
|
|
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
super.initState(); |
|
|
|
flutterToast = FlutterToast(context); |
|
|
|
//UPDATE |
|
|
|
if (_otherAction != null) { |
|
|
|
try { |
|
|
|
executeTime = DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") |
|
|
|
.parse(_otherAction.executeDate); |
|
|
|
} catch (_) {} |
|
|
|
} else { |
|
|
|
//ADD NEW |
|
|
|
var parsedExecuteDate = |
|
|
|
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(executeTime); |
|
|
|
_otherAction.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); |
|
|
|
_otherAction.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: 15.0, color: Colors.black54), |
|
|
|
)), |
|
|
|
Icon( |
|
|
|
Icons.date_range, |
|
|
|
color: Colors.blue, |
|
|
|
), |
|
|
|
], |
|
|
|
))); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _desciptionField() { |
|
|
|
return TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
decoration: InputDecoration(labelText: "Ghi chú"), |
|
|
|
controller: _descriptionController, |
|
|
|
onSaved: (newValue) { |
|
|
|
_otherAction.description = newValue; |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _workerNameField() { |
|
|
|
return TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
decoration: InputDecoration(labelText: "Người thực hiện"), |
|
|
|
controller: _workerNameController, |
|
|
|
validator: (String value) { |
|
|
|
return Validators.validateNotNullOrEmpty(value, "Người thực hiện"); |
|
|
|
}, |
|
|
|
onSaved: (newValue) { |
|
|
|
_otherAction.workerName = newValue; |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return Container(); |
|
|
|
return Scaffold( |
|
|
|
appBar: AppBar( |
|
|
|
title: Text(plot_action_other), |
|
|
|
actions: <Widget>[ |
|
|
|
IconButton( |
|
|
|
icon: Icon(Icons.done), |
|
|
|
disabledColor: Colors.grey, |
|
|
|
onPressed: 1 == 1 ? null : () {}) |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
} |