|
|
|
@@ -1,5 +1,6 @@ |
|
|
|
import 'package:farm_tpf/data/repository/repository.dart'; |
|
|
|
import 'package:farm_tpf/models/index.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/actions/other/bloc_get_action_type.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_string.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_style.dart'; |
|
|
|
import 'package:farm_tpf/utils/pref.dart'; |
|
|
|
@@ -8,6 +9,7 @@ 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'; |
|
|
|
|
|
|
|
class EditActionOtherScreen extends StatefulWidget { |
|
|
|
@override |
|
|
|
@@ -20,6 +22,8 @@ class _EditActionOtherScreenState extends State<EditActionOtherScreen> { |
|
|
|
GlobalKey<FormState> _formKey = GlobalKey(); |
|
|
|
bool _autoValidate = false; |
|
|
|
OtherAction _otherAction = OtherAction(); |
|
|
|
List<ActionType> _actionTypes = List<ActionType>(); |
|
|
|
ActionType _actionType; |
|
|
|
var pref = LocalPref(); |
|
|
|
FlutterToast flutterToast; |
|
|
|
TextEditingController _descriptionController = TextEditingController(); |
|
|
|
@@ -44,6 +48,17 @@ class _EditActionOtherScreenState extends State<EditActionOtherScreen> { |
|
|
|
_otherAction.executeDate = "$parsedExecuteDate"; |
|
|
|
} |
|
|
|
executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(executeTime); |
|
|
|
|
|
|
|
//Get action types |
|
|
|
getActionTypeBloc.getActionTypes((data) { |
|
|
|
_actionTypes = data; |
|
|
|
for (var item in _actionTypes) { |
|
|
|
if (item.id == _otherAction.activityId) { |
|
|
|
_actionType = item; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}, (err) {}); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _btnExecuteTimePicker() { |
|
|
|
@@ -72,7 +87,7 @@ class _EditActionOtherScreenState extends State<EditActionOtherScreen> { |
|
|
|
child: Text( |
|
|
|
//TODO: check condition |
|
|
|
executeTimeView == null ? "$executeTime" : executeTimeView, |
|
|
|
style: TextStyle(fontSize: 15.0, color: Colors.black54), |
|
|
|
style: TextStyle(fontSize: 14.0, color: Colors.black87), |
|
|
|
)), |
|
|
|
Icon( |
|
|
|
Icons.date_range, |
|
|
|
@@ -82,6 +97,44 @@ class _EditActionOtherScreenState extends State<EditActionOtherScreen> { |
|
|
|
))); |
|
|
|
} |
|
|
|
|
|
|
|
List<DropdownMenuItem<ActionType>> _buildDropMenu(List<ActionType> actions) { |
|
|
|
return actions |
|
|
|
.map((action) => DropdownMenuItem<ActionType>( |
|
|
|
child: Text(action.name.toString()), |
|
|
|
value: action, |
|
|
|
)) |
|
|
|
.toList(); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _dropdownAcionTypes() { |
|
|
|
return StreamBuilder( |
|
|
|
stream: getActionTypeBloc.actions, |
|
|
|
builder: (context, AsyncSnapshot<dynamic> snapshot) { |
|
|
|
if (snapshot.hasData) { |
|
|
|
return DropdownButtonFormField<ActionType>( |
|
|
|
value: _actionType, |
|
|
|
hint: Text("Hoạt động"), |
|
|
|
onChanged: (ActionType newValue) { |
|
|
|
setState(() { |
|
|
|
_actionType = newValue; |
|
|
|
_otherAction.activityId = newValue.id; |
|
|
|
_otherAction.activityTypeName = newValue.name; |
|
|
|
}); |
|
|
|
}, |
|
|
|
validator: (value) => value == null ? "Hoạt động" : null, |
|
|
|
isExpanded: true, |
|
|
|
items: _buildDropMenu(_actionTypes)); |
|
|
|
} else if (snapshot.hasError) { |
|
|
|
return Container(); |
|
|
|
} else { |
|
|
|
return Center( |
|
|
|
child: CircularProgressIndicator(), |
|
|
|
); |
|
|
|
} |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _desciptionField() { |
|
|
|
return TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
@@ -107,18 +160,63 @@ class _EditActionOtherScreenState extends State<EditActionOtherScreen> { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return Scaffold( |
|
|
|
appBar: AppBar( |
|
|
|
title: Text(plot_action_other), |
|
|
|
actions: <Widget>[ |
|
|
|
IconButton( |
|
|
|
icon: Icon(Icons.done), |
|
|
|
disabledColor: Colors.grey, |
|
|
|
onPressed: 1 == 1 ? null : () {}) |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
_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_other), |
|
|
|
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, |
|
|
|
), |
|
|
|
_dropdownAcionTypes(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_desciptionField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_workerNameField() |
|
|
|
], |
|
|
|
), |
|
|
|
))))); |
|
|
|
} |