Browse Source

screen nursery action

master
daivph 5 years ago
parent
commit
6ed1629039
4 changed files with 363 additions and 2 deletions
  1. +71
    -0
      lib/custom_model/Nursery.dart
  2. +283
    -0
      lib/presentation/screens/actions/nursery/sc_edit_action_nursery.dart
  3. +7
    -1
      lib/presentation/screens/actions/other/sc_edit_action_other.dart
  4. +2
    -1
      lib/presentation/screens/plot_detail/sc_plot_action.dart

+ 71
- 0
lib/custom_model/Nursery.dart View File

class Nursery {
int cropId;
String executeDate;
String description;
String substrates;
num quantity;
num seedLength;
num seedIncubationTime;
List<NurseryDetail> nurseryDetail;

Nursery(
{this.cropId,
this.executeDate,
this.description,
this.substrates,
this.quantity,
this.seedLength,
this.seedIncubationTime,
this.nurseryDetail});

Nursery.fromJson(Map<String, dynamic> json) {
cropId = json['cropId'];
executeDate = json['executeDate'];
description = json['description'];
substrates = json['substrates'];
quantity = json['quantity'];
seedLength = json['seedLength'];
seedIncubationTime = json['seedIncubationTime'];
if (json['nurseryDetail'] != null) {
nurseryDetail = new List<NurseryDetail>();
json['nurseryDetail'].forEach((v) {
nurseryDetail.add(new NurseryDetail.fromJson(v));
});
}
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['cropId'] = this.cropId;
data['executeDate'] = this.executeDate;
data['description'] = this.description;
data['substrates'] = this.substrates;
data['quantity'] = this.quantity;
data['seedLength'] = this.seedLength;
data['seedIncubationTime'] = this.seedIncubationTime;
if (this.nurseryDetail != null) {
data['nurseryDetail'] =
this.nurseryDetail.map((v) => v.toJson()).toList();
}
return data;
}
}

class NurseryDetail {
String workerName;
String trayNumber;

NurseryDetail({this.workerName, this.trayNumber});

NurseryDetail.fromJson(Map<String, dynamic> json) {
workerName = json['workerName'];
trayNumber = json['trayNumber'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['workerName'] = this.workerName;
data['trayNumber'] = this.trayNumber;
return data;
}
}

+ 283
- 0
lib/presentation/screens/actions/nursery/sc_edit_action_nursery.dart View File

import 'package:farm_tpf/custom_model/Nursery.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 EditActionNursery extends StatefulWidget {
@override
_EditActionNurseryState createState() => _EditActionNurseryState();
}

class _EditActionNurseryState extends State<EditActionNursery> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
final _repository = Repository();
GlobalKey<FormState> _formKey = GlobalKey();
bool _autoValidate = false;
Nursery _nursery = Nursery();
var pref = LocalPref();
FlutterToast flutterToast;
TextEditingController _substrateController = TextEditingController();
TextEditingController _seedLengthController = TextEditingController();
TextEditingController _quantityController = TextEditingController();
TextEditingController _seedIncubationTimeController = TextEditingController();
TextEditingController _descriptionController = TextEditingController();
String executeTimeView;
DateTime executeTime = DateTime.now();

@override
void initState() {
super.initState();
flutterToast = FlutterToast(context);
//UPDATE
if (_nursery != null) {
try {
executeTime =
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse(_nursery.executeDate);
} catch (_) {}
} else {
//ADD NEW
var parsedExecuteDate =
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(executeTime);
_nursery.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);
_nursery.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 _btnSelectSeed() {
return FlatButton(
padding: EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
onPressed: () {},
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(
"Tên giống",
style: TextStyle(fontSize: 14.0, color: Colors.black87),
)),
Icon(
Icons.arrow_drop_down,
color: Colors.grey,
),
],
)));
}

Widget _subStratesField() {
return TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(labelText: "Loại giá thể"),
controller: _substrateController,
validator: (String value) {
return Validators.validateNotNullOrEmpty(value, "Loại giá thể");
},
onSaved: (newValue) {
_nursery.substrates = newValue;
},
);
}

Widget _seedLengthField() {
return TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
ThousandsFormatter(
formatter: NumberFormat("#,###.##", "es"), allowFraction: true)
],
decoration: InputDecoration(labelText: "Chiều dài mần"),
controller: _seedLengthController,
validator: (String value) {
return Validators.validNumber(value, "Chiều dài mần");
},
onSaved: (newValue) {
_nursery.seedLength = newValue.parseDoubleThousand();
},
);
}

Widget _quantityField() {
return TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
ThousandsFormatter(
formatter: NumberFormat("#,###.##", "es"), allowFraction: true)
],
decoration: InputDecoration(labelText: "Số lượng hạt gieo"),
controller: _quantityController,
validator: (String value) {
return Validators.validNumber(value, "Số lượng hạt gieo");
},
onSaved: (newValue) {
_nursery.quantity = newValue.parseDoubleThousand();
},
);
}

Widget _seedIncubationTimeField() {
return TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
ThousandsFormatter(
formatter: NumberFormat("#,###.##", "es"), allowFraction: true)
],
decoration: InputDecoration(labelText: "Thời gian ngâm hạt"),
controller: _seedIncubationTimeController,
validator: (String value) {
return Validators.validNumber(value, "Thời gian ngâm hạt");
},
onSaved: (newValue) {
_nursery.seedIncubationTime = newValue.parseDoubleThousand();
},
);
}

Widget _desciptionField() {
return TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(labelText: "Ghi chú"),
controller: _descriptionController,
onSaved: (newValue) {
_nursery.description = 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_nursery),
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,
),
Container(
width: double.infinity,
child: Text(
"Tên giống",
style: TextStyle(
color: Colors.black54, fontSize: 13.0),
),
),
_btnSelectSeed(),
SizedBox(
height: 8.0,
),
_subStratesField(),
SizedBox(
height: 8.0,
),
_seedLengthField(),
SizedBox(
height: 8.0,
),
_quantityField(),
SizedBox(
height: 8.0,
),
_seedIncubationTimeField(),
SizedBox(
height: 8.0,
),
_desciptionField()
],
),
)))));
@override
void dispose() {
_substrateController.dispose();
_seedLengthController.dispose();
_quantityController.dispose();
_seedIncubationTimeController.dispose();
_descriptionController.dispose();
super.dispose();
}
}

+ 7
- 1
lib/presentation/screens/actions/other/sc_edit_action_other.dart View File

List<DropdownMenuItem<ActionType>> _buildDropMenu(List<ActionType> actions) { List<DropdownMenuItem<ActionType>> _buildDropMenu(List<ActionType> actions) {
return actions return actions
.map((action) => DropdownMenuItem<ActionType>( .map((action) => DropdownMenuItem<ActionType>(
child: Text(action.name.toString()),
child: Text(action.description.toString()),
value: action, value: action,
)) ))
.toList(); .toList();
], ],
), ),
))))); )))));
@override
void dispose() {
_descriptionController.dispose();
_workerNameController.dispose();
super.dispose();
}
} }

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

import 'package:farm_tpf/data/repository/repository.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/bottom_loader.dart';
import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.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/other/sc_edit_action_other.dart';
import 'package:farm_tpf/presentation/screens/plot/sc_plot.dart'; import 'package:farm_tpf/presentation/screens/plot/sc_plot.dart';
import 'package:farm_tpf/presentation/screens/plot_detail/bloc/plot_detail_bloc.dart'; import 'package:farm_tpf/presentation/screens/plot_detail/bloc/plot_detail_bloc.dart';
} }


_initActionButtons() { _initActionButtons() {
actions.add(ActionType(plot_action_nursery, null, PlotListScreen()));
actions.add(ActionType(plot_action_nursery, null, EditActionNursery()));
actions.add(ActionType(plot_action_plant, null, null)); actions.add(ActionType(plot_action_plant, null, null));
actions.add(ActionType(plot_action_crop_status, null, null)); actions.add(ActionType(plot_action_crop_status, null, null));
actions.add(ActionType(plot_action_environment_update, null, null)); actions.add(ActionType(plot_action_environment_update, null, null));

Loading…
Cancel
Save