Browse Source

ui action nursery

master
daivph 5 years ago
parent
commit
b555d609c6
8 changed files with 377 additions and 294 deletions
  1. BIN
      assets/png/icAddMedia.png
  2. +1
    -1
      lib/presentation/custom_widgets/hoz_list_view.dart
  3. +1
    -1
      lib/presentation/custom_widgets/widget_field_time_picker.dart
  4. +49
    -60
      lib/presentation/custom_widgets/widget_media_picker.dart
  5. +27
    -0
      lib/presentation/custom_widgets/widget_text_field_description.dart
  6. +297
    -231
      lib/presentation/screens/actions/nursery/sc_edit_action_nursery.dart
  7. +1
    -1
      lib/presentation/screens/plot_detail/sc_plot_information.dart
  8. +1
    -0
      lib/utils/const_assets.dart

BIN
assets/png/icAddMedia.png View File

Before After
Width: 552  |  Height: 552  |  Size: 11KB

+ 1
- 1
lib/presentation/custom_widgets/hoz_list_view.dart View File

@@ -32,7 +32,7 @@ class _WrapContentHozListViewState extends State<WrapContentHozListView> {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
reverse: true,
reverse: false,
scrollDirection: Axis.horizontal,
physics: BouncingScrollPhysics(),
child: Row(

+ 1
- 1
lib/presentation/custom_widgets/widget_field_time_picker.dart View File

@@ -53,7 +53,7 @@ class _WidgetFieldDateTimePickerState extends State<WidgetFieldDateTimePicker> {
)),
Icon(
Icons.date_range,
color: Colors.blue,
color: Colors.grey,
),
],
)));

+ 49
- 60
lib/presentation/custom_widgets/widget_media_picker.dart View File

@@ -6,14 +6,13 @@ import 'package:farm_tpf/presentation/custom_widgets/camera_helper.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_show_video.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart';
import 'package:farm_tpf/presentation/screens/actions/util_action.dart';
import 'package:farm_tpf/utils/const_color.dart';
import 'package:farm_tpf/utils/const_assets.dart';
import 'package:farm_tpf/utils/const_common.dart';
import 'package:farm_tpf/utils/const_string.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get/get.dart';

import 'bloc/media_helper_bloc.dart';
import 'hoz_list_view.dart';
@@ -49,14 +48,25 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> {
} else if (state is MediaHelperSuccess) {
currentItems = widget.currentItems ?? [];
return Container(
padding: EdgeInsets.only(top: 8, bottom: 8),
padding: EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Hình ảnh/ Video',
style: TextStyle(color: Colors.black54, fontSize: 16)),
SizedBox(
width: double.infinity,
height: 44,
child: FlatButton(
onPressed: () {
height: 8,
),
Row(
children: [
InkWell(
child: Image.asset(
AppAssets.icAddMedia,
fit: BoxFit.contain,
width: 114,
height: 114,
),
onTap: () {
showDialog(
context: context,
barrierDismissible: true,
@@ -65,33 +75,14 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> {
opacity: 1,
));
},
color: AppColors.DEFAULT,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(7.0),
),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.image, color: Colors.white),
SizedBox(
width: 8.0,
),
Text(
button_add_media,
style: TextStyle(
fontWeight: FontWeight.bold,
color: AppColors.WHITE),
)
],
),
)),
),
SizedBox(
height: 8.0,
),
Container(
child: _buildListPoster(),
),
SizedBox(
width: 8.0,
),
Expanded(
child: _buildListPoster(),
),
],
),
],
));
@@ -215,13 +206,14 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> {
return BlocBuilder<MediaHelperBloc, MediaHelperState>(
builder: (context, state) {
if (state is MediaHelperSuccess) {
return GridView.count(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
crossAxisCount: 4,
children: currentItems.map(
(item) {
return _WidgetItemMedia(
return WrapContentHozListView(
list: currentItems,
itemBuilder: (context, index) {
var item = currentItems[index];
return Container(
width: 120,
height: 120,
child: _WidgetItemMedia(
item: item,
deleteImage: (item) {
if (item.isServerFile) {
@@ -234,9 +226,9 @@ class _WidgetMediaPickerState extends State<WidgetMediaPicker> {
widget.onChangeFiles(addNewFilePaths, deleteFilePaths);
BlocProvider.of<MediaHelperBloc>(context)
.add(ChangeListMedia(items: currentItems));
});
},
).toList());
}),
);
});
}
return Container();
});
@@ -250,9 +242,7 @@ class _WidgetItemMedia extends StatelessWidget {
_WidgetItemMedia({@required this.item, @required this.deleteImage});

BuildContext _context;
// screenSize/rowGridview - iconSize - (rowGridview-1)*marginContainer
// Get.width/4 - 24 - 3*4
double positionIconDelete = -(Get.width / 4 - 36);
double positionIconDelete = -(120.0 - 36);

@override
Widget build(BuildContext context) {
@@ -287,19 +277,18 @@ class _WidgetItemMedia extends StatelessWidget {
: Image.file(File(item.pathFile)),
)),
Positioned.fill(
top: positionIconDelete,
right: positionIconDelete,
child: IconButton(
icon: Icon(
Icons.cancel,
color: Colors.redAccent,
size: 24,
),
onPressed: () {
print("On tap delete media");
deleteImage(item);
}),
)
top: positionIconDelete,
right: positionIconDelete,
child: IconButton(
icon: Icon(
Icons.delete,
color: Colors.redAccent,
size: 24,
),
onPressed: () {
print("On tap delete media");
deleteImage(item);
}))
],
));
}

+ 27
- 0
lib/presentation/custom_widgets/widget_text_field_description.dart View File

@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:farm_tpf/utils/const_color.dart';

class TextFieldDescriptionWidget extends StatelessWidget {
final TextEditingController controller;
final Function onSaved;
TextFieldDescriptionWidget(
{@required this.onSaved, @required this.controller});
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: AppColors.YELLOW.withOpacity(0.1),
borderRadius: BorderRadius.circular(8)),
child: TextFormField(
keyboardType: TextInputType.text,
controller: controller,
decoration: InputDecoration(
labelText: "Ghi chú",
hintText: 'Ghi chú',
border: InputBorder.none),
onSaved: onSaved,
),
);
}
}

+ 297
- 231
lib/presentation/screens/actions/nursery/sc_edit_action_nursery.dart View File

@@ -5,10 +5,13 @@ import 'package:farm_tpf/custom_model/NurseryDetail.dart';
import 'package:farm_tpf/custom_model/Supply.dart';
import 'package:farm_tpf/data/api/app_exception.dart';
import 'package:farm_tpf/data/repository/repository.dart';
import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart';
import 'package:farm_tpf/presentation/custom_widgets/bloc/media_helper_bloc.dart';
import 'package:farm_tpf/presentation/custom_widgets/button_widget.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_field_time_picker.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_text_field_description.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_text_form_field.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart';
import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart';
@@ -46,6 +49,7 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
final _repository = Repository();
GlobalKey<FormState> _formKey = GlobalKey();
GlobalKey<FormState> _formWorkerKey = GlobalKey();
bool _autoValidate = false;
Nursery _nursery = Nursery();
var pref = LocalPref();
@@ -209,14 +213,11 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> {
}

Widget _desciptionField() {
return TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(labelText: "Ghi chú"),
controller: _descriptionController,
onSaved: (newValue) {
_nursery.description = newValue;
},
);
return TextFieldDescriptionWidget(
controller: _descriptionController,
onSaved: (newValue) {
_nursery.description = newValue;
});
}

Widget _executeByField() {
@@ -251,53 +252,59 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> {
}
}, 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: AppColors.DEFAULT)),
child: Form(
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: AppColors.DEFAULT,
key: _formWorkerKey,
child: Column(
children: [
Container(
padding: EdgeInsets.all(8.0),
margin: EdgeInsets.all(8),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(10),
color: Colors.white,
border: Border.all(color: Colors.grey[300])),
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) {},
),
],
),
),
Container(
margin: EdgeInsets.all(8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: [
isResetForm
? Container()
: OutlineButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
child: Text("Huỷ"),
onPressed: () {
context.bloc<StatusAddFormBloc>().add(Reset());
}),
Expanded(
child: FlatButton(
onPressed: () {
if (_formWorkerKey.currentState.validate()) {
_formWorkerKey.currentState.save();
if (Validators.stringNotNullOrEmpty(
_workerNameController.text)) {
NurseryDetail _nurseryDetail = NurseryDetail()
@@ -320,17 +327,23 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> {
Utils.showSnackBarWarning(
message: "Vui lòng nhập tên công nhân");
}
},
child: Text(
(state is Edit) ? "Sửa" : "Thêm",
style: TextStyle(color: Colors.white),
))
],
),
),
],
} else {
//
}
},
child: Text(
(state is Edit)
? "Sửa người thực hiện"
: "+ Thêm người thực hiện",
style: TextStyle(color: Colors.blue),
)),
)
],
),
),
));
],
),
));
});
});
}
@@ -435,40 +448,6 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> {
});
}

_actionAppBar() {
IconButton iconButton;
if (1 == 1) {
iconButton = IconButton(
icon: Icon(
Icons.done,
color: Colors.black,
),
onPressed: () {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
if (!Validators.stringNotNullOrEmpty(_workerNameController.text) &&
!Validators.stringNotNullOrEmpty(_trayNumberController.text)) {
_validateInputs();
} else {
Utils.showDialog(
title: "Tên công nhân hoặc khây trồng đang cập nhật",
message: "Bạn có muốn cập nhật?",
textConfirm: "Tiếp tục",
textCancel: "Xem lại",
onConfirm: () {
Get.back();
_validateInputs();
});
}
},
);
return <Widget>[iconButton];
}
return <Widget>[Container()];
}

@override
Widget build(BuildContext context) => KeyboardDismisser(
gestures: [
@@ -476,11 +455,22 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> {
GestureType.onPanUpdateDownDirection,
],
child: Scaffold(
backgroundColor: Colors.white,
key: _scaffoldKey,
appBar: AppBar(
centerTitle: true,
title: Text(plot_action_nursery),
actions: _actionAppBar()),
appBar: AppBarWidget(
isBack: true,
action: InkWell(
child: Text(
'Huỷ',
style: TextStyle(
color: Colors.red, fontWeight: FontWeight.normal),
),
onTap: () {
if (Get.isSnackbarOpen) Get.back();
Get.back();
},
),
),
body: KeyboardDismisser(
child: MultiBlocProvider(
providers: [
@@ -505,141 +495,217 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> {
child: Form(
key: _formKey,
autovalidate: _autoValidate,
child: SingleChildScrollView(
padding: EdgeInsets.all(8.0),
child: BlocConsumer<ActionDetailBloc,
ActionDetailState>(
listener: (context, state) async {
if (state is ActionDetailFailure) {
print("fail");
LoadingDialog.hideLoadingDialog(context);
} else if (state is ActionDetailSuccess) {
LoadingDialog.hideLoadingDialog(context);
print("success");
print(state.item);
_nursery = Nursery.fromJson(state.item);
_seedLengthController.text = _nursery
.seedLength
.formatNumtoStringDecimal();
_quantityController.text = _nursery.quantity
.formatNumtoStringDecimal();
_seedIncubationTimeController.text = _nursery
.seedIncubationTime
.formatNumtoStringDecimal();
_descriptionController.text =
_nursery.description;
_executeByController.text =
_nursery.executeBy;
Get.find<ChangeDateTimePicker>().change(_nursery
.executeDate
.convertStringServerDateTimeToLocalDateTime());
//Show media
if (Validators.stringNotNullOrEmpty(
_nursery.media)) {
BlocProvider.of<MediaHelperBloc>(context)
.add(ChangeListMedia(
items: UtilAction
.convertFilePathToMedia(
_nursery.media)));
}
//Show worker
if (_nursery.nurseryDetail.length > 0) {
BlocProvider.of<ExpansionListBloc>(context)
.add(AddNew(
items: _nursery.nurseryDetail));
child: SafeArea(
child: SingleChildScrollView(
child: BlocConsumer<ActionDetailBloc,
ActionDetailState>(
listener: (context, state) async {
if (state is ActionDetailFailure) {
print("fail");
LoadingDialog.hideLoadingDialog(context);
} else if (state is ActionDetailSuccess) {
LoadingDialog.hideLoadingDialog(context);
print("success");
print(state.item);
_nursery = Nursery.fromJson(state.item);
_seedLengthController.text = _nursery
.seedLength
.formatNumtoStringDecimal();
_quantityController.text = _nursery.quantity
.formatNumtoStringDecimal();
_seedIncubationTimeController.text =
_nursery.seedIncubationTime
.formatNumtoStringDecimal();
_descriptionController.text =
_nursery.description;
_executeByController.text =
_nursery.executeBy;
Get.find<ChangeDateTimePicker>().change(_nursery
.executeDate
.convertStringServerDateTimeToLocalDateTime());
//Show media
if (Validators.stringNotNullOrEmpty(
_nursery.media)) {
BlocProvider.of<MediaHelperBloc>(context)
.add(ChangeListMedia(
items: UtilAction
.convertFilePathToMedia(
_nursery.media)));
}
//Show worker
if (_nursery.nurseryDetail.length > 0) {
BlocProvider.of<ExpansionListBloc>(
context)
.add(AddNew(
items: _nursery.nurseryDetail));
}
//change subStrates
if (_nursery.substratesId != null) {
Get.find<ChangeSupply>()
.changeByIdAndName(
_nursery.substratesId,
_nursery.substrateName);
}
} else if (state is ActionDetailInitial) {
print("init");
} else if (state is ActionDetailLoading) {
print("loading");
LoadingDialog.showLoadingDialog(context);
}
//change subStrates
if (_nursery.substratesId != null) {
Get.find<ChangeSupply>().changeByIdAndName(
_nursery.substratesId,
_nursery.substrateName);
}
} else if (state is ActionDetailInitial) {
print("init");
} else if (state is ActionDetailLoading) {
print("loading");
LoadingDialog.showLoadingDialog(context);
}
},
builder: (context, state) {
return Column(
children: <Widget>[
Container(
width: double.infinity,
child: Text(
"Ngày thực hiện *",
style: TextStyle(
color: Colors.black54,
fontSize: 13.0),
},
builder: (context, state) {
return Column(
children: [
Padding(
padding: EdgeInsets.all(8),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
'Ươm',
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 22),
),
SizedBox(
height: 8.0,
),
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(
"Loại giá thể",
style: TextStyle(
color: Colors.black54,
fontSize: 13.0),
),
),
_btnSelectSubstrates(),
SizedBox(
height: 8.0,
),
_seedLengthField(),
SizedBox(
height: 8.0,
),
_quantityField(),
SizedBox(
height: 8.0,
),
_seedIncubationTimeField(),
SizedBox(
height: 8.0,
),
_desciptionField(),
SizedBox(
height: 8.0,
),
_executeByField(),
SizedBox(
height: 8.0,
),
],
),
),
),
_btnExecuteTimePicker(),
SizedBox(
height: 8.0,
),
Container(
width: double.infinity,
child: Text(
"Loại giá thể",
style: TextStyle(
color: Colors.black54,
fontSize: 13.0),
Container(
width: double.infinity,
height: 16,
color: Colors.grey[200],
),
),
_btnSelectSubstrates(),
SizedBox(
height: 8.0,
),
_seedLengthField(),
SizedBox(
height: 8.0,
),
_quantityField(),
SizedBox(
height: 8.0,
),
_seedIncubationTimeField(),
SizedBox(
height: 8.0,
),
_desciptionField(),
SizedBox(
height: 8.0,
),
_executeByField(),
SizedBox(
height: 8.0,
),
_buildListAddWorker(),
SizedBox(
height: 8.0,
),
_btnAddWorker(),
SizedBox(
height: 8.0,
),
BlocBuilder<MediaHelperBloc,
MediaHelperState>(
builder: (context, state) {
if (state is MediaHelperSuccess) {
print("length: " +
state.items.length.toString());
return WidgetMediaPicker(
currentItems: state.items,
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>()
.change(newPathFiles,
deletePathFiles);
});
} else {
return Center(
child: CircularProgressIndicator());
}
}),
],
);
},
SizedBox(
height: 8.0,
),
_buildListAddWorker(),
SizedBox(
height: 8.0,
),
_btnAddWorker(),
SizedBox(
height: 8.0,
),
Container(
width: double.infinity,
height: 16,
color: Colors.grey[200],
),
SizedBox(
height: 8.0,
),
BlocBuilder<MediaHelperBloc,
MediaHelperState>(
builder: (context, state) {
if (state is MediaHelperSuccess) {
print("length: " +
state.items.length.toString());
return WidgetMediaPicker(
currentItems: state.items,
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>()
.change(newPathFiles,
deletePathFiles);
});
} else {
return Center(
child:
CircularProgressIndicator());
}
}),
SizedBox(
height: 16,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ButtonWidget(
title: 'CẬP NHẬT',
onPressed: () {
FocusScopeNode currentFocus =
FocusScope.of(context);
if (!currentFocus
.hasPrimaryFocus) {
currentFocus.unfocus();
}
if (!Validators
.stringNotNullOrEmpty(
_workerNameController
.text) &&
!Validators
.stringNotNullOrEmpty(
_trayNumberController
.text)) {
_validateInputs();
} else {
Utils.showDialog(
title:
"Tên công nhân hoặc khây trồng đang cập nhật",
message:
"Bạn có muốn cập nhật?",
textConfirm: "Tiếp tục",
textCancel: "Xem lại",
onConfirm: () {
Get.back();
_validateInputs();
});
}
}),
),
],
);
},
),
),
))))));
@override

+ 1
- 1
lib/presentation/screens/plot_detail/sc_plot_information.dart View File

@@ -77,7 +77,7 @@ class _PlotInformationScreenState extends State<PlotInformationScreen>
Widget _descriptionField() {
return Container(
padding: EdgeInsets.all(8),
color: Colors.yellow[100],
color: AppColors.YELLOW.withOpacity(0.1),
child: TextFormField(
keyboardType: TextInputType.text,
controller: _descriptionController,

+ 1
- 0
lib/utils/const_assets.dart View File

@@ -14,4 +14,5 @@ class AppAssets {
static const icActionPlant = baseAssets + 'icActionPlant.png';
static const icActionSpraying = baseAssets + 'icActionSpraying.png';
static const icActionUseWater = baseAssets + 'icActionUseWater.png';
static const icAddMedia = baseAssets + 'icAddMedia.png';
}

Loading…
Cancel
Save