Browse Source

ui action environment update

master
daivph 5 years ago
parent
commit
d0398bbf5d
2 changed files with 196 additions and 158 deletions
  1. +1
    -0
      lib/presentation/screens/actions/crop_status/sc_edit_action_crop_status.dart
  2. +195
    -158
      lib/presentation/screens/actions/environment_update/sc_edit_action_environment_update.dart

+ 1
- 0
lib/presentation/screens/actions/crop_status/sc_edit_action_crop_status.dart View File

@@ -271,6 +271,7 @@ class _EditActionCropStatusScreenState
GestureType.onPanUpdateDownDirection,
],
child: Scaffold(
backgroundColor: Colors.white,
key: _scaffoldKey,
appBar: AppBarWidget(
isBack: true,

+ 195
- 158
lib/presentation/screens/actions/environment_update/sc_edit_action_environment_update.dart View File

@@ -4,7 +4,9 @@ import 'package:farm_tpf/custom_model/Environment.dart';
import 'package:farm_tpf/custom_model/RequestEnvironment.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';
@@ -223,27 +225,6 @@ class _EditActionEnvironmentUpdateState
);
}

_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();
}
_validateInputs();
},
);
return <Widget>[iconButton];
}
return <Widget>[Container()];
}

@override
Widget build(BuildContext context) => KeyboardDismisser(
gestures: [
@@ -251,11 +232,22 @@ class _EditActionEnvironmentUpdateState
GestureType.onPanUpdateDownDirection,
],
child: Scaffold(
backgroundColor: Colors.white,
key: _scaffoldKey,
appBar: AppBar(
centerTitle: true,
title: Text(plot_action_environment_update),
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: [
@@ -274,142 +266,187 @@ class _EditActionEnvironmentUpdateState
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);
_environment = Environment.fromJson(state.item);
//Parse theo API :')
_environment.environmentUpdates
.forEach((envDetail) {
switch (envDetail.tbEnvironmentalName) {
case "EC":
_environment.ec = envDetail.index.toString();
break;
case "pH":
_environment.pH = envDetail.index.toString();
break;
case "OCDD":
_environment.ocdd =
envDetail.index.toString();
break;
case "TEMPERATURE":
_environment.temperature =
envDetail.index.toString();
break;
case "DO":
_environment.dodo =
envDetail.index.toString();
break;
case "LLN":
_environment.lln = envDetail.index.toString();
break;
default:
break;
}
});
_environment.activityId = widget.activityId;
_ecController.text =
_environment.ec.formatStringToStringDecimal();
_phController.text =
_environment.pH.formatStringToStringDecimal();
_ocddController.text =
_environment.ocdd.formatStringToStringDecimal();
_temperatureController.text = _environment
.temperature
.formatStringToStringDecimal();
_doController.text =
_environment.dodo.formatStringToStringDecimal();
_llnController.text =
_environment.lln.formatStringToStringDecimal();
_executeByController.text = _environment.executeBy;
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);
_environment = Environment.fromJson(state.item);
//Parse theo API :')
_environment.environmentUpdates
.forEach((envDetail) {
switch (envDetail.tbEnvironmentalName) {
case "EC":
_environment.ec =
envDetail.index.toString();
break;
case "pH":
_environment.pH =
envDetail.index.toString();
break;
case "OCDD":
_environment.ocdd =
envDetail.index.toString();
break;
case "TEMPERATURE":
_environment.temperature =
envDetail.index.toString();
break;
case "DO":
_environment.dodo =
envDetail.index.toString();
break;
case "LLN":
_environment.lln =
envDetail.index.toString();
break;
default:
break;
}
});
_environment.activityId = widget.activityId;
_ecController.text =
_environment.ec.formatStringToStringDecimal();
_phController.text =
_environment.pH.formatStringToStringDecimal();
_ocddController.text = _environment.ocdd
.formatStringToStringDecimal();
_temperatureController.text = _environment
.temperature
.formatStringToStringDecimal();
_doController.text = _environment.dodo
.formatStringToStringDecimal();
_llnController.text = _environment.lln
.formatStringToStringDecimal();
_executeByController.text =
_environment.executeBy;

Get.find<ChangeDateTimePicker>().change(_environment
.executeDate
.convertStringServerDateTimeToLocalDateTime());
//Show media
if (Validators.stringNotNullOrEmpty(
_environment.media)) {
BlocProvider.of<MediaHelperBloc>(context).add(
ChangeListMedia(
items: UtilAction.convertFilePathToMedia(
_environment.media)));
Get.find<ChangeDateTimePicker>().change(_environment
.executeDate
.convertStringServerDateTimeToLocalDateTime());
//Show media
if (Validators.stringNotNullOrEmpty(
_environment.media)) {
BlocProvider.of<MediaHelperBloc>(context).add(
ChangeListMedia(
items:
UtilAction.convertFilePathToMedia(
_environment.media)));
}
} else if (state is ActionDetailInitial) {
print("init");
} else if (state is ActionDetailLoading) {
print("loading");
LoadingDialog.showLoadingDialog(context);
}
} 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: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
plot_action_environment_update,
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,
),
_ecField(),
SizedBox(
height: 8.0,
),
_phField(),
SizedBox(
height: 8.0,
),
_ocddField(),
SizedBox(
height: 8.0,
),
_temperatureField(),
SizedBox(
height: 8.0,
),
_doField(),
SizedBox(
height: 8.0,
),
_llnField(),
SizedBox(
height: 8.0,
),
_executeByField(),
SizedBox(
height: 8.0,
),
],
),
),
),
_btnExecuteTimePicker(),
SizedBox(
height: 8.0,
),
_ecField(),
SizedBox(
height: 8.0,
),
_phField(),
SizedBox(
height: 8.0,
),
_ocddField(),
SizedBox(
height: 8.0,
),
_temperatureField(),
SizedBox(
height: 8.0,
),
_doField(),
SizedBox(
height: 8.0,
),
_llnField(),
SizedBox(
height: 8.0,
),
_executeByField(),
SizedBox(
height: 8.0,
),
BlocBuilder<MediaHelperBloc, MediaHelperState>(
builder: (context, state) {
if (state is MediaHelperSuccess) {
return WidgetMediaPicker(
currentItems: state.items,
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>().change(
newPathFiles, deletePathFiles);
});
} else {
return Center(
child: CircularProgressIndicator());
}
}),
],
);
},
Container(
width: double.infinity,
height: 16,
color: Colors.grey[200],
),
BlocBuilder<MediaHelperBloc, MediaHelperState>(
builder: (context, state) {
if (state is MediaHelperSuccess) {
return WidgetMediaPicker(
currentItems: state.items,
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>()
.change(newPathFiles,
deletePathFiles);
});
} else {
return Center(
child: CircularProgressIndicator());
}
}),
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();
}
_validateInputs();
}),
),
],
);
},
),
),
)),
))));

Loading…
Cancel
Save