|
|
|
|
|
|
|
|
import 'dart:convert'; |
|
|
import 'dart:convert'; |
|
|
|
|
|
|
|
|
import 'package:farm_tpf/custom_model/Media.dart'; |
|
|
|
|
|
import 'package:farm_tpf/custom_model/Nursery.dart'; |
|
|
import 'package:farm_tpf/custom_model/Nursery.dart'; |
|
|
import 'package:farm_tpf/custom_model/NurseryDetail.dart'; |
|
|
import 'package:farm_tpf/custom_model/NurseryDetail.dart'; |
|
|
import 'package:farm_tpf/custom_model/Supply.dart'; |
|
|
import 'package:farm_tpf/custom_model/Supply.dart'; |
|
|
|
|
|
|
|
|
import 'package:farm_tpf/utils/validators.dart'; |
|
|
import 'package:farm_tpf/utils/validators.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter_bloc/flutter_bloc.dart'; |
|
|
import 'package:flutter_bloc/flutter_bloc.dart'; |
|
|
import 'package:flutter_cache_manager/flutter_cache_manager.dart'; |
|
|
|
|
|
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; |
|
|
|
|
|
import 'package:get/get.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
import 'package:get/state_manager.dart'; |
|
|
import 'package:get/state_manager.dart'; |
|
|
import 'package:intl/intl.dart'; |
|
|
|
|
|
import 'package:keyboard_dismisser/keyboard_dismisser.dart'; |
|
|
import 'package:keyboard_dismisser/keyboard_dismisser.dart'; |
|
|
import 'package:mime/mime.dart'; |
|
|
|
|
|
import 'package:pattern_formatter/pattern_formatter.dart'; |
|
|
|
|
|
import 'package:farm_tpf/utils/formatter.dart'; |
|
|
import 'package:farm_tpf/utils/formatter.dart'; |
|
|
|
|
|
|
|
|
import '../util_action.dart'; |
|
|
import '../util_action.dart'; |
|
|
|
|
|
|
|
|
int selectedSupplyId = -1; |
|
|
int selectedSupplyId = -1; |
|
|
List<String> filePaths = List<String>(); |
|
|
List<String> filePaths = List<String>(); |
|
|
var changeFileController = Get.put(ChangeFileController()); |
|
|
var changeFileController = Get.put(ChangeFileController()); |
|
|
|
|
|
GlobalKey<FormState> _formWorkerKey = GlobalKey(); |
|
|
|
|
|
|
|
|
Future<Null> getSharedPrefs() async { |
|
|
Future<Null> getSharedPrefs() async { |
|
|
var currentFullName = await pref.getString(DATA_CONST.CURRENT_FULL_NAME); |
|
|
var currentFullName = await pref.getString(DATA_CONST.CURRENT_FULL_NAME); |
|
|
|
|
|
|
|
|
borderRadius: BorderRadius.circular(10), |
|
|
borderRadius: BorderRadius.circular(10), |
|
|
color: Colors.white, |
|
|
color: Colors.white, |
|
|
border: Border.all(color: COLOR_CONST.DEFAULT)), |
|
|
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) {}, |
|
|
|
|
|
), |
|
|
|
|
|
TextFormField( |
|
|
|
|
|
keyboardType: TextInputType.text, |
|
|
|
|
|
controller: _trayNumberController, |
|
|
|
|
|
decoration: InputDecoration(labelText: "Ươm khây số"), |
|
|
|
|
|
onSaved: (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: () { |
|
|
|
|
|
if (_workerNameController.text.isEmpty || |
|
|
|
|
|
_trayNumberController.text.isEmpty) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
NurseryDetail _nurseryDetail = NurseryDetail() |
|
|
|
|
|
..workerName = _workerNameController.text |
|
|
|
|
|
..trayNumber = _trayNumberController.text; |
|
|
|
|
|
|
|
|
child: Form( |
|
|
|
|
|
key: _formWorkerKey, |
|
|
|
|
|
child: Column( |
|
|
|
|
|
children: [ |
|
|
|
|
|
TextFormField( |
|
|
|
|
|
keyboardType: TextInputType.text, |
|
|
|
|
|
controller: _workerNameController, |
|
|
|
|
|
decoration: InputDecoration(labelText: "Tên công nhân *"), |
|
|
|
|
|
validator: (value) { |
|
|
|
|
|
return Validators.validateNotNullOrEmpty( |
|
|
|
|
|
value, "Tên công nhân"); |
|
|
|
|
|
}, |
|
|
|
|
|
onSaved: (newValue) {}, |
|
|
|
|
|
), |
|
|
|
|
|
TextFormField( |
|
|
|
|
|
keyboardType: TextInputType.text, |
|
|
|
|
|
controller: _trayNumberController, |
|
|
|
|
|
decoration: InputDecoration(labelText: "Ươm khây số"), |
|
|
|
|
|
onSaved: (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: () { |
|
|
|
|
|
if (_formWorkerKey.currentState.validate()) { |
|
|
|
|
|
_formWorkerKey.currentState.save(); |
|
|
|
|
|
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), |
|
|
|
|
|
)) |
|
|
|
|
|
], |
|
|
|
|
|
|
|
|
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()); |
|
|
|
|
|
} else { |
|
|
|
|
|
// |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
child: Text( |
|
|
|
|
|
(state is Edit) ? "Sửa" : "Thêm", |
|
|
|
|
|
style: TextStyle(color: Colors.white), |
|
|
|
|
|
)) |
|
|
|
|
|
], |
|
|
|
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
|
|
|
], |
|
|
|
|
|
|
|
|
], |
|
|
|
|
|
), |
|
|
)); |
|
|
)); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
padding: EdgeInsets.all(4), |
|
|
padding: EdgeInsets.all(4), |
|
|
width: 120, |
|
|
width: 120, |
|
|
child: Column( |
|
|
child: Column( |
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
children: [ |
|
|
children: [ |
|
|
SizedBox( |
|
|
SizedBox( |
|
|
height: 12.0, |
|
|
height: 12.0, |
|
|
|
|
|
|
|
|
overflow: TextOverflow.ellipsis, |
|
|
overflow: TextOverflow.ellipsis, |
|
|
maxLines: 1), |
|
|
maxLines: 1), |
|
|
), |
|
|
), |
|
|
Flexible( |
|
|
|
|
|
child: Text(currentNurseryDetail[index] |
|
|
|
|
|
.trayNumber ?? |
|
|
|
|
|
"")) |
|
|
|
|
|
|
|
|
Validators.stringNotNullOrEmpty( |
|
|
|
|
|
currentNurseryDetail[index] |
|
|
|
|
|
.trayNumber) |
|
|
|
|
|
? Flexible( |
|
|
|
|
|
child: Text( |
|
|
|
|
|
currentNurseryDetail[index] |
|
|
|
|
|
.trayNumber ?? |
|
|
|
|
|
"")) |
|
|
|
|
|
: SizedBox() |
|
|
], |
|
|
], |
|
|
), |
|
|
), |
|
|
), |
|
|
), |