Browse Source

crop status screen

master
daivph 5 years ago
parent
commit
7d17556011
3 changed files with 398 additions and 1 deletions
  1. +60
    -0
      lib/custom_model/CropStatus.dart
  2. +335
    -0
      lib/presentation/screens/actions/crop_status/sc_edit_action_crop_status.dart
  3. +3
    -1
      lib/presentation/screens/plot_detail/sc_plot_action.dart

+ 60
- 0
lib/custom_model/CropStatus.dart View File

@@ -0,0 +1,60 @@
class CropStatus {
int id;
int cropId;
String executeDate;
num cropRate;
num numberOfTreeToGrow;
num hightOfTree;
num numberOfLeaf;
num leafSize;
String leafColor;
String abilityProduceBuds;
num bodySize;
String note;

CropStatus(
{this.id,
this.cropId,
this.executeDate,
this.cropRate,
this.numberOfTreeToGrow,
this.hightOfTree,
this.numberOfLeaf,
this.leafSize,
this.leafColor,
this.abilityProduceBuds,
this.bodySize,
this.note});

CropStatus.fromJson(Map<String, dynamic> json) {
id = json['id'];
cropId = json['cropId'];
executeDate = json['executeDate'];
cropRate = json['cropRate'];
numberOfTreeToGrow = json['numberOfTreeToGrow'];
hightOfTree = json['hightOfTree'];
numberOfLeaf = json['numberOfLeaf'];
leafSize = json['leafSize'];
leafColor = json['leafColor'];
abilityProduceBuds = json['abilityProduceBuds'];
bodySize = json['bodySize'];
note = json['note'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['cropId'] = this.cropId;
data['executeDate'] = this.executeDate;
data['cropRate'] = this.cropRate;
data['numberOfTreeToGrow'] = this.numberOfTreeToGrow;
data['hightOfTree'] = this.hightOfTree;
data['numberOfLeaf'] = this.numberOfLeaf;
data['leafSize'] = this.leafSize;
data['leafColor'] = this.leafColor;
data['abilityProduceBuds'] = this.abilityProduceBuds;
data['bodySize'] = this.bodySize;
data['note'] = this.note;
return data;
}
}

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

@@ -0,0 +1,335 @@
import 'package:farm_tpf/custom_model/CropStatus.dart';
import 'package:farm_tpf/data/repository/repository.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_datetime_picker/flutter_datetime_picker.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:intl/intl.dart';
import 'package:keyboard_dismisser/keyboard_dismisser.dart';
import 'package:pattern_formatter/pattern_formatter.dart';
import 'package:farm_tpf/utils/formatter.dart';

class EditActionCropStatusScreen extends StatefulWidget {
@override
_EditActionCropStatusScreenState createState() =>
_EditActionCropStatusScreenState();
}

class _EditActionCropStatusScreenState
extends State<EditActionCropStatusScreen> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
final _repository = Repository();
GlobalKey<FormState> _formKey = GlobalKey();
bool _autoValidate = false;
CropStatus _cropStatus = CropStatus();
var pref = LocalPref();
FlutterToast flutterToast;
TextEditingController _cropRateController = TextEditingController();
TextEditingController _numTreeController = TextEditingController();
TextEditingController _hightOfTreeController = TextEditingController();
TextEditingController _numberOfLeafController = TextEditingController();
TextEditingController _leafSizeController = TextEditingController();
TextEditingController _leafColorController = TextEditingController();
TextEditingController _abilityProduceBudsController = TextEditingController();
TextEditingController _bodySizeController = TextEditingController();
TextEditingController _descriptionController = TextEditingController();

String executeTimeView;
DateTime executeTime = DateTime.now();

@override
void initState() {
super.initState();
flutterToast = FlutterToast(context);
//UPDATE
if (_cropStatus != null) {
try {
executeTime = DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.parse(_cropStatus.executeDate);
} catch (_) {}
} else {
//ADD NEW
var parsedExecuteDate =
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(executeTime);
_cropStatus.executeDate = "$parsedExecuteDate";
}
executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(executeTime);
}

Widget _btnExecuteTimePicker() {
return FlatButton(
padding: EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
onPressed: () {
DatePicker.showDateTimePicker(context,
showTitleActions: true, onChanged: (date) {}, onConfirm: (date) {
setState(() {
var parsedDate =
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(date);
_cropStatus.executeDate = "$parsedDate";
executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(date);
});
}, currentTime: executeTime, locale: LocaleType.vi);
},
child: Container(
padding:
EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0),
decoration: BoxDecoration(
border: kBorderTextField,
),
child: Row(
children: [
Expanded(
child: Text(
//TODO: check condition
executeTimeView == null ? "$executeTime" : executeTimeView,
style: TextStyle(fontSize: 14.0, color: Colors.black87),
)),
Icon(
Icons.date_range,
color: Colors.blue,
),
],
)));
}

Widget _cropRateField() {
return TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
ThousandsFormatter(
formatter: NumberFormat("#,###.##", "es"), allowFraction: true)
],
decoration: InputDecoration(labelText: "Tỉ lệ lên cây"),
controller: _cropRateController,
validator: (String value) {
return Validators.validNumber(value, "Tỉ lệ lên cây");
},
onSaved: (newValue) {
_cropStatus.cropRate = newValue.parseDoubleThousand();
},
);
}

Widget _numTreeField() {
return TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
ThousandsFormatter(
formatter: NumberFormat("#,###.##", "es"), allowFraction: true)
],
decoration: InputDecoration(labelText: "Số lượng lên cây"),
controller: _numTreeController,
validator: (String value) {
return Validators.validNumber(value, "Số lượng lên cây");
},
onSaved: (newValue) {
_cropStatus.numberOfTreeToGrow = newValue.parseDoubleThousand();
},
);
}

Widget _hightOfTreeField() {
return TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
ThousandsFormatter(
formatter: NumberFormat("#,###.##", "es"), allowFraction: true)
],
decoration: InputDecoration(labelText: "Chiều cao cây"),
controller: _hightOfTreeController,
validator: (String value) {
return Validators.validNumber(value, "Chiều cao cây");
},
onSaved: (newValue) {
_cropStatus.hightOfTree = newValue.parseDoubleThousand();
},
);
}

Widget _numberOfLeafField() {
return TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
ThousandsFormatter(
formatter: NumberFormat("#,###.##", "es"), allowFraction: true)
],
decoration: InputDecoration(labelText: "Số lá"),
controller: _numberOfLeafController,
validator: (String value) {
return Validators.validNumber(value, "Số lá");
},
onSaved: (newValue) {
_cropStatus.numberOfLeaf = newValue.parseDoubleThousand();
},
);
}

Widget _leafSizeField() {
return TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
ThousandsFormatter(
formatter: NumberFormat("#,###.##", "es"), allowFraction: true)
],
decoration: InputDecoration(labelText: "Kích thước lá"),
controller: _leafSizeController,
validator: (String value) {
return Validators.validNumber(value, "Kích thước lá");
},
onSaved: (newValue) {
_cropStatus.leafSize = newValue.parseDoubleThousand();
},
);
}

Widget _leafColorField() {
return TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(labelText: "Màu lá"),
controller: _leafColorController,
onSaved: (newValue) {
_cropStatus.leafColor = newValue;
},
);
}

Widget _bodySizeField() {
return TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
ThousandsFormatter(
formatter: NumberFormat("#,###.##", "es"), allowFraction: true)
],
decoration: InputDecoration(labelText: "Dài đốt thân"),
controller: _bodySizeController,
validator: (String value) {
return Validators.validNumber(value, "Dài đốt thân");
},
onSaved: (newValue) {
_cropStatus.bodySize = newValue.parseDoubleThousand();
},
);
}

Widget _abilityProduceBudsField() {
return TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(labelText: "Khả năng sinh chồi"),
controller: _abilityProduceBudsController,
onSaved: (newValue) {
_cropStatus.abilityProduceBuds = newValue;
},
);
}

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

_actionAppBar() {
IconButton iconButton;
if (1 == 1) {
iconButton = IconButton(
icon: Icon(
Icons.done,
color: Colors.black,
),
onPressed: () {},
);
return <Widget>[iconButton];
}
return <Widget>[Container()];
}

@override
Widget build(BuildContext context) => KeyboardDismisser(
gestures: [
GestureType.onTap,
GestureType.onPanUpdateDownDirection,
],
child: Scaffold(
key: _scaffoldKey,
appBar: AppBar(
centerTitle: true,
title: Text(plot_action_crop_status),
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,
),
_cropRateField(),
SizedBox(
height: 8.0,
),
_numTreeField(),
SizedBox(
height: 8.0,
),
_hightOfTreeField(),
SizedBox(
height: 8.0,
),
_numberOfLeafField(),
SizedBox(
height: 8.0,
),
_leafSizeField(),
SizedBox(
height: 8.0,
),
_leafColorField(),
SizedBox(
height: 8.0,
),
_bodySizeField(),
SizedBox(
height: 8.0,
),
_abilityProduceBudsField(),
SizedBox(
height: 8.0,
),
_desciptionField()
],
),
)))));
@override
void dispose() {
_cropRateController.dispose();
_numTreeController.dispose();
_hightOfTreeController.dispose();
_numberOfLeafController.dispose();
_leafSizeController.dispose();
_leafColorController.dispose();
_abilityProduceBudsController.dispose();
_bodySizeController.dispose();
_descriptionController.dispose();
super.dispose();
}
}

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

@@ -2,6 +2,7 @@ import 'package:farm_tpf/custom_model/CropPlot.dart';
import 'package:farm_tpf/data/repository/repository.dart';
import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart';
import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart';
import 'package:farm_tpf/presentation/screens/actions/crop_status/sc_edit_action_crop_status.dart';
import 'package:farm_tpf/presentation/screens/actions/nursery/sc_edit_action_nursery.dart';
import 'package:farm_tpf/presentation/screens/actions/other/sc_edit_action_other.dart';
import 'package:farm_tpf/presentation/screens/actions/plant/sc_edit_action_plant.dart';
@@ -35,7 +36,8 @@ class _PlotActionScreenState extends State<PlotActionScreen> {
actions
.add(ActionType(plot_action_nursery, null, EditActionNurseryScreen()));
actions.add(ActionType(plot_action_plant, null, EditActionPlantScreen()));
actions.add(ActionType(plot_action_crop_status, null, null));
actions.add(ActionType(
plot_action_crop_status, null, EditActionCropStatusScreen()));
actions.add(ActionType(plot_action_environment_update, null, null));
actions.add(ActionType(plot_action_dung, null, null));
actions.add(ActionType(plot_action_spraying, null, null));

Loading…
Cancel
Save