daivph 5 years ago
parent
commit
ba7d5b60b1
5 changed files with 141 additions and 3 deletions
  1. +112
    -1
      lib/presentation/screens/actions/other/sc_edit_action_other.dart
  2. +2
    -1
      lib/presentation/screens/plot_detail/sc_plot_action.dart
  3. +17
    -0
      lib/utils/const_style.dart
  4. +8
    -1
      pubspec.lock
  5. +2
    -0
      pubspec.yaml

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

@@ -1,4 +1,13 @@
import 'package:farm_tpf/data/repository/repository.dart';
import 'package:farm_tpf/models/index.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';

class EditActionOtherScreen extends StatefulWidget {
@override
@@ -6,8 +15,110 @@ class EditActionOtherScreen extends StatefulWidget {
}

class _EditActionOtherScreenState extends State<EditActionOtherScreen> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
final _repository = Repository();
GlobalKey<FormState> _formKey = GlobalKey();
bool _autoValidate = false;
OtherAction _otherAction = OtherAction();
var pref = LocalPref();
FlutterToast flutterToast;
TextEditingController _descriptionController = TextEditingController();
TextEditingController _workerNameController = TextEditingController();
String executeTimeView;
DateTime executeTime = DateTime.now();

@override
void initState() {
super.initState();
flutterToast = FlutterToast(context);
//UPDATE
if (_otherAction != null) {
try {
executeTime = DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.parse(_otherAction.executeDate);
} catch (_) {}
} else {
//ADD NEW
var parsedExecuteDate =
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(executeTime);
_otherAction.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);
_otherAction.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: 15.0, color: Colors.black54),
)),
Icon(
Icons.date_range,
color: Colors.blue,
),
],
)));
}

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

Widget _workerNameField() {
return TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(labelText: "Người thực hiện"),
controller: _workerNameController,
validator: (String value) {
return Validators.validateNotNullOrEmpty(value, "Người thực hiện");
},
onSaved: (newValue) {
_otherAction.workerName = newValue;
},
);
}

@override
Widget build(BuildContext context) {
return Container();
return Scaffold(
appBar: AppBar(
title: Text(plot_action_other),
actions: <Widget>[
IconButton(
icon: Icon(Icons.done),
disabledColor: Colors.grey,
onPressed: 1 == 1 ? null : () {})
],
),
);
}
}

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

@@ -1,3 +1,4 @@
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/utils/const_color.dart';
import 'package:farm_tpf/utils/const_string.dart';
@@ -28,7 +29,7 @@ class _PlotActionScreenState extends State<PlotActionScreen> {
actions.add(ActionType(plot_action_spraying, null, null));
actions.add(ActionType(plot_action_disease, null, null));
actions.add(ActionType(plot_action_use_water, null, null));
actions.add(ActionType(plot_action_other, null, null));
actions.add(ActionType(plot_action_other, null, EditActionOtherScreen()));
actions.add(ActionType(plot_action_harvest, null, null));
actions.add(ActionType(plot_action_finish, null, null));
}

+ 17
- 0
lib/utils/const_style.dart View File

@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';

const Border kBorderTextField =
Border(bottom: BorderSide(width: 0.5, color: Colors.grey));
const TextStyle kTextStyleNormal =
TextStyle(fontSize: 15.0, color: Colors.black);
const Color kColorNormalIcon = Colors.lightBlue;
const TextStyle kTextHintStyle = TextStyle(fontSize: 15.0, color: Colors.grey);
const EdgeInsetsGeometry kContentPaddingNormalTextField =
EdgeInsets.only(top: 5.0, right: 10.0, bottom: 5.0, left: 10.0);
const BorderRadius kButtonBorder = BorderRadius.all(Radius.circular(30.0));
const Color kColorShadowNormalButton = Colors.lightBlueAccent;
const Color kColorNormalButton = Colors.green;
const TextStyle kTextButtonStyleLarge =
TextStyle(fontSize: 18.0, color: Colors.white);
const TextStyle kTextButtonStyleNormal =
TextStyle(fontSize: 15.0, color: Colors.black54);

+ 8
- 1
pubspec.lock View File

@@ -265,6 +265,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.1"
flutter_datetime_picker:
dependency: "direct main"
description:
name: flutter_datetime_picker
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
flutter_plugin_android_lifecycle:
dependency: "direct main"
description:
@@ -374,7 +381,7 @@ packages:
source: hosted
version: "1.1.0"
intl:
dependency: transitive
dependency: "direct main"
description:
name: intl
url: "https://pub.dartlang.org"

+ 2
- 0
pubspec.yaml View File

@@ -35,6 +35,8 @@ dependencies:
change_app_package_name: ^0.1.2
firebase_messaging: ^7.0.0
get: ^3.8.0
intl: ^0.16.1
flutter_datetime_picker: ^1.3.8

dev_dependencies:
flutter_test:

Loading…
Cancel
Save