|
|
|
@@ -1,12 +1,21 @@ |
|
|
|
import 'package:farm_tpf/custom_model/Nursery.dart'; |
|
|
|
import 'package:farm_tpf/data/repository/repository.dart'; |
|
|
|
import 'package:farm_tpf/models/index.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/actions/nursery/bloc/expansion_list_bloc.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/resources/sc_resource_helper.dart'; |
|
|
|
import 'package:farm_tpf/utils/bloc/bloc/status_add_form_bloc.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_color.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_common.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_bloc/flutter_bloc.dart'; |
|
|
|
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; |
|
|
|
import 'package:fluttertoast/fluttertoast.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:get/state_manager.dart'; |
|
|
|
import 'package:intl/intl.dart'; |
|
|
|
import 'package:keyboard_dismisser/keyboard_dismisser.dart'; |
|
|
|
import 'package:pattern_formatter/pattern_formatter.dart'; |
|
|
|
@@ -30,12 +39,22 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
TextEditingController _quantityController = TextEditingController(); |
|
|
|
TextEditingController _seedIncubationTimeController = TextEditingController(); |
|
|
|
TextEditingController _descriptionController = TextEditingController(); |
|
|
|
TextEditingController _workerNameController = TextEditingController(); |
|
|
|
TextEditingController _trayNumberController = TextEditingController(); |
|
|
|
String executeTimeView; |
|
|
|
DateTime executeTime = DateTime.now(); |
|
|
|
List<NurseryDetail> currentNurseryDetail = List<NurseryDetail>(); |
|
|
|
ExpansionListBloc _bloc; |
|
|
|
int currentIndexUpdate = -1; |
|
|
|
bool isResetForm = true; |
|
|
|
final changeSupply = Get.put(ChangeSupply()); |
|
|
|
int selectedSupplyId = -1; |
|
|
|
|
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
super.initState(); |
|
|
|
changeSupply.initValue(); |
|
|
|
_nursery.nurseryDetail = new List<NurseryDetail>(); |
|
|
|
flutterToast = FlutterToast(context); |
|
|
|
//UPDATE |
|
|
|
if (_nursery != null) { |
|
|
|
@@ -91,7 +110,23 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
Widget _btnSelectSeed() { |
|
|
|
return FlatButton( |
|
|
|
padding: EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), |
|
|
|
onPressed: () {}, |
|
|
|
onPressed: () { |
|
|
|
Navigator.of(context) |
|
|
|
.push(MaterialPageRoute( |
|
|
|
builder: (_) => ResourceHelperScreen( |
|
|
|
titleName: "Gía thể", |
|
|
|
type: ConstCommon.supplyTypeSubStrate, |
|
|
|
selectedId: Get.find<ChangeSupply>().selectedSupplyId), |
|
|
|
fullscreenDialog: false)) |
|
|
|
.then((value) { |
|
|
|
if (value != null) { |
|
|
|
var result = value as Supply; |
|
|
|
_nursery.substrates = result.name; |
|
|
|
changeSupply.change(result); |
|
|
|
print("Home: $value"); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
child: Container( |
|
|
|
padding: |
|
|
|
EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), |
|
|
|
@@ -100,11 +135,14 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
), |
|
|
|
child: Row( |
|
|
|
children: [ |
|
|
|
Expanded( |
|
|
|
child: Text( |
|
|
|
"Tên giống", |
|
|
|
style: TextStyle(fontSize: 14.0, color: Colors.black87), |
|
|
|
)), |
|
|
|
GetBuilder<ChangeSupply>( |
|
|
|
builder: (_) => Expanded( |
|
|
|
child: Text( |
|
|
|
changeSupply.currentSupply.name == null |
|
|
|
? "Loại giá thể" |
|
|
|
: _nursery.substrates.toString(), |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 14.0, color: Colors.black87)))), |
|
|
|
Icon( |
|
|
|
Icons.arrow_drop_down, |
|
|
|
color: Colors.grey, |
|
|
|
@@ -113,20 +151,6 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
))); |
|
|
|
} |
|
|
|
|
|
|
|
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), |
|
|
|
@@ -192,6 +216,193 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _btnAddWorker() { |
|
|
|
return Builder(builder: (context) { |
|
|
|
return BlocConsumer<StatusAddFormBloc, StatusAddFormState>( |
|
|
|
listener: (context, state) { |
|
|
|
if (state is Edit) { |
|
|
|
isResetForm = false; |
|
|
|
_workerNameController.text = state.nurseryDetail.workerName; |
|
|
|
_trayNumberController.text = state.nurseryDetail.trayNumber; |
|
|
|
} else if (state is Delete) { |
|
|
|
if (currentIndexUpdate == state.index) { |
|
|
|
isResetForm = true; |
|
|
|
_workerNameController.text = ""; |
|
|
|
_trayNumberController.text = ""; |
|
|
|
} |
|
|
|
} else { |
|
|
|
isResetForm = true; |
|
|
|
_workerNameController.text = ""; |
|
|
|
_trayNumberController.text = ""; |
|
|
|
} |
|
|
|
}, builder: (context, state) { |
|
|
|
return Container( |
|
|
|
padding: EdgeInsets.all(8.0), |
|
|
|
decoration: BoxDecoration( |
|
|
|
shape: BoxShape.rectangle, |
|
|
|
borderRadius: BorderRadius.circular(10), |
|
|
|
color: Colors.white, |
|
|
|
border: Border.all(color: COLOR_CONST.DEFAULT)), |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
controller: _workerNameController, |
|
|
|
decoration: InputDecoration(labelText: "Tên công nhân"), |
|
|
|
onSaved: (newValue) { |
|
|
|
_nursery.description = newValue; |
|
|
|
}, |
|
|
|
), |
|
|
|
TextFormField( |
|
|
|
keyboardType: TextInputType.text, |
|
|
|
controller: _trayNumberController, |
|
|
|
decoration: InputDecoration(labelText: "Ươm khây số"), |
|
|
|
onSaved: (newValue) { |
|
|
|
_nursery.description = newValue; |
|
|
|
}, |
|
|
|
), |
|
|
|
Align( |
|
|
|
alignment: Alignment.centerRight, |
|
|
|
child: Row( |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
children: [ |
|
|
|
isResetForm |
|
|
|
? Container() |
|
|
|
: OutlineButton( |
|
|
|
shape: RoundedRectangleBorder( |
|
|
|
borderRadius: new BorderRadius.circular(8.0)), |
|
|
|
child: Text("Huỷ"), |
|
|
|
onPressed: () { |
|
|
|
context.bloc<StatusAddFormBloc>().add(Reset()); |
|
|
|
}), |
|
|
|
FlatButton( |
|
|
|
color: COLOR_CONST.DEFAULT, |
|
|
|
shape: RoundedRectangleBorder( |
|
|
|
borderRadius: new BorderRadius.circular(8.0)), |
|
|
|
onPressed: () { |
|
|
|
NurseryDetail _nurseryDetail = NurseryDetail() |
|
|
|
..workerName = _workerNameController.text |
|
|
|
..trayNumber = _trayNumberController.text; |
|
|
|
|
|
|
|
if (state is Edit) { |
|
|
|
context.bloc<ExpansionListBloc>().add(Update( |
|
|
|
index: state.index, |
|
|
|
item: _nurseryDetail, |
|
|
|
items: state.items)); |
|
|
|
} else { |
|
|
|
currentNurseryDetail.insert(0, _nurseryDetail); |
|
|
|
BlocProvider.of<ExpansionListBloc>(context) |
|
|
|
.add(AddNew(items: currentNurseryDetail)); |
|
|
|
} |
|
|
|
context.bloc<StatusAddFormBloc>().add(Reset()); |
|
|
|
}, |
|
|
|
child: Text( |
|
|
|
(state is Edit) ? "Sửa" : "Thêm", |
|
|
|
style: TextStyle(color: Colors.white), |
|
|
|
)) |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _buildListAddWorker() { |
|
|
|
return Builder(builder: (context) { |
|
|
|
return BlocBuilder<ExpansionListBloc, ExpansionListState>( |
|
|
|
builder: (context, state) { |
|
|
|
if (state is ExpansionListSuccess) { |
|
|
|
currentNurseryDetail = state.items; |
|
|
|
if (currentNurseryDetail.isEmpty) { |
|
|
|
return Container(); |
|
|
|
} |
|
|
|
return Container( |
|
|
|
height: 70, |
|
|
|
child: ListView.builder( |
|
|
|
physics: ClampingScrollPhysics(), |
|
|
|
scrollDirection: Axis.horizontal, |
|
|
|
shrinkWrap: true, |
|
|
|
itemCount: currentNurseryDetail.length, |
|
|
|
itemBuilder: (context, index) { |
|
|
|
return GestureDetector( |
|
|
|
onTap: () { |
|
|
|
print("Show preview image or video"); |
|
|
|
currentIndexUpdate = index; |
|
|
|
context.bloc<StatusAddFormBloc>().add(Changed( |
|
|
|
status: CRUDStatus.edit, |
|
|
|
index: index, |
|
|
|
nurseryDetail: currentNurseryDetail[index], |
|
|
|
items: currentNurseryDetail)); |
|
|
|
}, |
|
|
|
child: Card( |
|
|
|
child: Stack( |
|
|
|
alignment: Alignment.bottomCenter, |
|
|
|
overflow: Overflow.visible, |
|
|
|
children: <Widget>[ |
|
|
|
Positioned( |
|
|
|
child: ClipRRect( |
|
|
|
borderRadius: BorderRadius.circular(8), |
|
|
|
child: Container( |
|
|
|
padding: EdgeInsets.all(4), |
|
|
|
width: 120, |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
SizedBox( |
|
|
|
height: 12.0, |
|
|
|
), |
|
|
|
Flexible( |
|
|
|
child: Text( |
|
|
|
currentNurseryDetail[index] |
|
|
|
.workerName ?? |
|
|
|
"", |
|
|
|
overflow: TextOverflow.ellipsis, |
|
|
|
maxLines: 1), |
|
|
|
), |
|
|
|
Flexible( |
|
|
|
child: Text(currentNurseryDetail[index] |
|
|
|
.trayNumber ?? |
|
|
|
"")) |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
)), |
|
|
|
Positioned( |
|
|
|
top: -10, |
|
|
|
right: -10, |
|
|
|
child: IconButton( |
|
|
|
icon: Icon( |
|
|
|
Icons.cancel, |
|
|
|
color: Colors.redAccent, |
|
|
|
), |
|
|
|
onPressed: () { |
|
|
|
print("On tap delete media"); |
|
|
|
context.bloc<ExpansionListBloc>().add( |
|
|
|
DeleteItem( |
|
|
|
index: index, |
|
|
|
items: currentNurseryDetail)); |
|
|
|
context.bloc<StatusAddFormBloc>().add( |
|
|
|
Changed( |
|
|
|
status: CRUDStatus.delete, |
|
|
|
index: index, |
|
|
|
nurseryDetail: |
|
|
|
currentNurseryDetail[index], |
|
|
|
items: currentNurseryDetail)); |
|
|
|
}), |
|
|
|
) |
|
|
|
], |
|
|
|
))); |
|
|
|
})); |
|
|
|
} else if (state is ExpansionListFailure) { |
|
|
|
return Container(); |
|
|
|
} else { |
|
|
|
return Container(); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
_actionAppBar() { |
|
|
|
IconButton iconButton; |
|
|
|
if (1 == 1) { |
|
|
|
@@ -220,57 +431,71 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
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, |
|
|
|
child: MultiBlocProvider( |
|
|
|
providers: [ |
|
|
|
BlocProvider<ExpansionListBloc>( |
|
|
|
create: (context) => ExpansionListBloc(), |
|
|
|
), |
|
|
|
BlocProvider<StatusAddFormBloc>( |
|
|
|
create: (context) => StatusAddFormBloc(), |
|
|
|
) |
|
|
|
], |
|
|
|
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, |
|
|
|
), |
|
|
|
_seedLengthField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_quantityField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_seedIncubationTimeField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_desciptionField(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_btnAddWorker(), |
|
|
|
SizedBox( |
|
|
|
height: 8.0, |
|
|
|
), |
|
|
|
_buildListAddWorker(), |
|
|
|
Container(child: Text("Them hinh anh")), |
|
|
|
], |
|
|
|
), |
|
|
|
_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(); |
|
|
|
@@ -281,3 +506,20 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { |
|
|
|
super.dispose(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class ChangeSupply extends GetxController { |
|
|
|
Supply currentSupply; |
|
|
|
int selectedSupplyId; |
|
|
|
|
|
|
|
void initValue() { |
|
|
|
currentSupply = Supply(); |
|
|
|
selectedSupplyId = -1; |
|
|
|
update(); |
|
|
|
} |
|
|
|
|
|
|
|
void change(Supply supply) { |
|
|
|
currentSupply = supply; |
|
|
|
selectedSupplyId = supply.id; |
|
|
|
update(); |
|
|
|
} |
|
|
|
} |