Browse Source

ui plant action

master
daivph 5 years ago
parent
commit
56a921177b
2 changed files with 258 additions and 217 deletions
  1. +175
    -133
      lib/presentation/screens/actions/plant/sc_edit_action_plant.dart
  2. +83
    -84
      lib/presentation/screens/actions/plant/widget_plant_supply.dart

+ 175
- 133
lib/presentation/screens/actions/plant/sc_edit_action_plant.dart View File

import 'package:farm_tpf/custom_model/SuppliesUsing.dart'; import 'package:farm_tpf/custom_model/SuppliesUsing.dart';
import 'package:farm_tpf/data/api/app_exception.dart'; import 'package:farm_tpf/data/api/app_exception.dart';
import 'package:farm_tpf/data/repository/repository.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/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_field_time_picker.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_loading.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_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_text_form_field.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart'; import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart';
import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart'; import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart';
} }


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


_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 (Get.find<ChangeFieldFormSupply>().isChanged) {
Utils.showDialogConfirmSupply(onConfirm: () {
Get.back();
_validateInputs();
});
} else {
_validateInputs();
}
},
);
return <Widget>[iconButton];
}
return <Widget>[Container()];
}

@override @override
Widget build(BuildContext context) => KeyboardDismisser( Widget build(BuildContext context) => KeyboardDismisser(
gestures: [ gestures: [
GestureType.onPanUpdateDownDirection, GestureType.onPanUpdateDownDirection,
], ],
child: Scaffold( child: Scaffold(
backgroundColor: Colors.white,
key: _scaffoldKey, key: _scaffoldKey,
appBar: AppBar(
centerTitle: true,
title: Text(plot_action_plant),
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( body: KeyboardDismisser(
child: MultiBlocProvider( child: MultiBlocProvider(
providers: [ providers: [
child: Form( child: Form(
key: _formKey, key: _formKey,
autovalidate: _autoValidate, autovalidate: _autoValidate,
child: SingleChildScrollView(
padding: EdgeInsets.all(8.0),
child: BlocConsumer<ActionDetailBloc,
ActionDetailState>(
listener: (context, state) async {
if (state is ActionDetailFailure) {
LoadingDialog.hideLoadingDialog(context);
} else if (state is ActionDetailSuccess) {
LoadingDialog.hideLoadingDialog(context);
_plant = Plant.fromJson(state.item);
_plant.activityId = widget.activityId;
_quantityController.text = _plant.quantity
.formatNumtoStringDecimal();
_densityController.text = _plant.density;
_descriptionController.text =
_plant.description;
_executeByController.text = _plant.executeBy;
child: SafeArea(
child: SingleChildScrollView(
child: BlocConsumer<ActionDetailBloc,
ActionDetailState>(
listener: (context, state) async {
if (state is ActionDetailFailure) {
LoadingDialog.hideLoadingDialog(context);
} else if (state is ActionDetailSuccess) {
LoadingDialog.hideLoadingDialog(context);
_plant = Plant.fromJson(state.item);
_plant.activityId = widget.activityId;
_quantityController.text = _plant.quantity
.formatNumtoStringDecimal();
_densityController.text = _plant.density;
_descriptionController.text =
_plant.description;
_executeByController.text =
_plant.executeBy;


Get.find<ChangeDateTimePicker>().change(_plant
.executeDate
.convertStringServerDateTimeToLocalDateTime());
Get.find<ChangeDateTimePicker>().change(_plant
.executeDate
.convertStringServerDateTimeToLocalDateTime());


//Show media
if (Validators.stringNotNullOrEmpty(
_plant.media)) {
BlocProvider.of<MediaHelperBloc>(context)
.add(ChangeListMedia(
items: UtilAction
.convertFilePathToMedia(
_plant.media)));
//Show media
if (Validators.stringNotNullOrEmpty(
_plant.media)) {
BlocProvider.of<MediaHelperBloc>(context)
.add(ChangeListMedia(
items: UtilAction
.convertFilePathToMedia(
_plant.media)));
}
//list supply
suppliesUsing = _plant.suppliesUsing;
Get.find<ChangeSupplyUsing>()
.changeInitList(suppliesUsing);
} else if (state is ActionDetailInitial) {
print("init");
} else if (state is ActionDetailLoading) {
print("loading");
LoadingDialog.showLoadingDialog(context);
} }
//list supply
suppliesUsing = _plant.suppliesUsing;
Get.find<ChangeSupplyUsing>()
.changeInitList(suppliesUsing);
} 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(
'Trồng',
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,
),
_quantityField(),
SizedBox(
height: 8.0,
),
_densityField(),
SizedBox(
height: 8.0,
),
_desciptionField(),
SizedBox(
height: 8.0,
),
_executeByField(),
SizedBox(
height: 8.0,
),
],
),
),
Container(
width: double.infinity,
height: 16,
color: Colors.grey[200],
),
WidgetPlantSupply(
currentItems: [],
onChangeSupplies: (value) {
suppliesUsing = value;
}),
SizedBox(
height: 8.0,
),
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());
}
}),
SizedBox(
height: 8,
), ),
),
_btnExecuteTimePicker(),
SizedBox(
height: 8.0,
),
_quantityField(),
SizedBox(
height: 8.0,
),
_densityField(),
SizedBox(
height: 8.0,
),
_desciptionField(),
SizedBox(
height: 8.0,
),
_executeByField(),
SizedBox(
height: 8.0,
),
WidgetPlantSupply(
currentItems: [],
onChangeSupplies: (value) {
suppliesUsing = value;
}),
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());
}
}),
],
);
},
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 (Get.find<
ChangeFieldFormSupply>()
.isChanged) {
Utils.showDialogConfirmSupply(
onConfirm: () {
Get.back();
_validateInputs();
});
} else {
_validateInputs();
}
}),
)
],
);
},
),
), ),
)))))); ))))));
@override @override

+ 83
- 84
lib/presentation/screens/actions/plant/widget_plant_supply.dart View File



_buttonInForm() { _buttonInForm() {
return GetBuilder<ChangeButtonInForm>(builder: (_) { return GetBuilder<ChangeButtonInForm>(builder: (_) {
return Align(
alignment: Alignment.centerRight,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_.isEdit
? OutlineButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
child: Text("Huỷ"),
onPressed: () {
changeButton.resetValue();
_resetForm();
_hidenKeyboard(context);
})
: SizedBox(),
_.isEdit
? FlatButton(
color: AppColors.DEFAULT,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
onPressed: () {
var currentSupply = changeSelectedSupply.currentSupply;
if (currentSupply.id != null) {
var quantityWithCurrentSupplyUnit =
UtilAction.convertUnit(
inputValue: _quantityController.text
.parseDoubleThousand(),
oldUnit: changeUnit.selectedUnit,
newUnit:
changeSelectedSupply.currentSupply.unit);
SuppliesUsing newSup = SuppliesUsing()
..dosage = _dosageController.text
..quantity = quantityWithCurrentSupplyUnit
..tbSuppliesInWarehouseId = currentSupply.id
..suppliesInWarehouseId = currentSupply.id
..supplyName = currentSupply.tbSuppliesName
..supplyUnit = currentSupply.unit
..unit = currentSupply.unit;
changeSupplyUsing.editSupply(
changeSupplyUsing.currentIndex, newSup);
_resetForm();
_hidenKeyboard(context);
}
},
child: Text(
"Sửa",
style: TextStyle(color: Colors.white),
))
: FlatButton(
color: AppColors.DEFAULT,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
onPressed: () {
var currentSupply = changeSelectedSupply.currentSupply;
if (currentSupply.id != null) {
var quantityWithCurrentSupplyUnit =
UtilAction.convertUnit(
inputValue: _quantityController.text
.parseDoubleThousand(),
oldUnit: changeUnit.selectedUnit,
newUnit:
changeSelectedSupply.currentSupply.unit);
SuppliesUsing newSup = SuppliesUsing()
..dosage = _dosageController.text
..quantity = quantityWithCurrentSupplyUnit
..tbSuppliesInWarehouseId = currentSupply.id
..suppliesInWarehouseId = currentSupply.id
..supplyName = currentSupply.tbSuppliesName
..supplyUnit = currentSupply.unit
..unit = currentSupply.unit;
changeSupplyUsing.addSupply(newSup);
_resetForm();
_hidenKeyboard(context);
}
},
child: Text(
"Thêm",
style: TextStyle(color: Colors.white),
))
],
),
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
_.isEdit
? OutlineButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
child: Text("Huỷ"),
onPressed: () {
changeButton.resetValue();
_resetForm();
_hidenKeyboard(context);
})
: SizedBox(),
_.isEdit
? Expanded(
child: FlatButton(
onPressed: () {
var currentSupply = changeSelectedSupply.currentSupply;
if (currentSupply.id != null) {
var quantityWithCurrentSupplyUnit =
UtilAction.convertUnit(
inputValue: _quantityController.text
.parseDoubleThousand(),
oldUnit: changeUnit.selectedUnit,
newUnit:
changeSelectedSupply.currentSupply.unit);
SuppliesUsing newSup = SuppliesUsing()
..dosage = _dosageController.text
..quantity = quantityWithCurrentSupplyUnit
..tbSuppliesInWarehouseId = currentSupply.id
..suppliesInWarehouseId = currentSupply.id
..supplyName = currentSupply.tbSuppliesName
..supplyUnit = currentSupply.unit
..unit = currentSupply.unit;
changeSupplyUsing.editSupply(
changeSupplyUsing.currentIndex, newSup);
_resetForm();
_hidenKeyboard(context);
}
},
child: Text(
"Sửa người thực hiện",
style: TextStyle(color: Colors.blue),
)),
)
: Expanded(
child: FlatButton(
onPressed: () {
var currentSupply = changeSelectedSupply.currentSupply;
if (currentSupply.id != null) {
var quantityWithCurrentSupplyUnit =
UtilAction.convertUnit(
inputValue: _quantityController.text
.parseDoubleThousand(),
oldUnit: changeUnit.selectedUnit,
newUnit:
changeSelectedSupply.currentSupply.unit);
SuppliesUsing newSup = SuppliesUsing()
..dosage = _dosageController.text
..quantity = quantityWithCurrentSupplyUnit
..tbSuppliesInWarehouseId = currentSupply.id
..suppliesInWarehouseId = currentSupply.id
..supplyName = currentSupply.tbSuppliesName
..supplyUnit = currentSupply.unit
..unit = currentSupply.unit;
changeSupplyUsing.addSupply(newSup);
_resetForm();
_hidenKeyboard(context);
}
},
child: Text(
"+ Thêm người thực hiện",
style: TextStyle(color: Colors.blue),
)),
)
],
); );
}); });
} }
Widget _formEdit() { Widget _formEdit() {
return Container( return Container(
padding: EdgeInsets.all(8.0), padding: EdgeInsets.all(8.0),
margin: EdgeInsets.all(8.0),
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.rectangle, shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
color: Colors.white, color: Colors.white,
border: Border.all(color: AppColors.DEFAULT)),
border: Border.all(color: Colors.grey[300])),
child: Column( child: Column(
children: [ children: [
Container( Container(
Expanded( Expanded(
flex: 2, flex: 2,
child: Container( child: Container(
height: 70,
height: 82,
child: _quantityField(), child: _quantityField(),
), ),
), ),
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(
children: [ children: [
SizedBox(
height: 8.0,
),
_buildListSupply(), _buildListSupply(),
SizedBox( SizedBox(
height: 8.0, height: 8.0,

Loading…
Cancel
Save