Browse Source

action plant without supply

master
daivph 5 years ago
parent
commit
1a3a357ee8
6 changed files with 269 additions and 90 deletions
  1. +1
    -1
      ios/Flutter/.last_build_id
  2. +17
    -1
      lib/custom_model/Plant.dart
  3. +5
    -1
      lib/custom_model/SuppliesUsing.dart
  4. +228
    -85
      lib/presentation/screens/actions/plant/sc_edit_action_plant.dart
  5. +12
    -1
      lib/presentation/screens/plot_detail/sc_plot_action.dart
  6. +6
    -1
      lib/utils/const_common.dart

+ 1
- 1
ios/Flutter/.last_build_id View File

@@ -1 +1 @@
eb141365fb69a4e0decadd2584d53516
0d1f90510e22958a585802bb59f9c570

+ 17
- 1
lib/custom_model/Plant.dart View File

@@ -1,27 +1,39 @@
import 'SuppliesUsing.dart';

class Plant {
int id;
int cropId;
int activityId;
String executeDate;
String description;
String executeBy;
String density;
num quantity;
String media;
List<SuppliesUsing> suppliesUsing;

Plant(
{this.cropId,
{this.id,
this.activityId,
this.cropId,
this.executeDate,
this.description,
this.executeBy,
this.density,
this.quantity,
this.media,
this.suppliesUsing});

Plant.fromJson(Map<String, dynamic> json) {
id = json['id'];
activityId = json['activityId'];
cropId = json['cropId'];
executeDate = json['executeDate'];
description = json['description'];
executeBy = json['executeBy'];
density = json['density'];
quantity = json['quantity'];
media = json['media'];
if (json['suppliesUsing'] != null) {
suppliesUsing = new List<SuppliesUsing>();
json['suppliesUsing'].forEach((v) {
@@ -32,11 +44,15 @@ class Plant {

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['activityId'] = this.activityId;
data['cropId'] = this.cropId;
data['executeDate'] = this.executeDate;
data['description'] = this.description;
data['executeBy'] = this.executeBy;
data['density'] = this.density;
data['quantity'] = this.quantity;
data['media'] = this.media;
if (this.suppliesUsing != null) {
data['suppliesUsing'] =
this.suppliesUsing.map((v) => v.toJson()).toList();

+ 5
- 1
lib/custom_model/SuppliesUsing.dart View File

@@ -1,7 +1,8 @@
class SuppliesUsing {
int id;
String dosage;
int quantity;
num quantity;
String unit;
String howToUse;
int suppliesInWarehouseId;
int equipmentOfCustomerId;
@@ -10,6 +11,7 @@ class SuppliesUsing {
{this.id,
this.dosage,
this.quantity,
this.unit,
this.howToUse,
this.suppliesInWarehouseId,
this.equipmentOfCustomerId});
@@ -18,6 +20,7 @@ class SuppliesUsing {
id = json['id'];
dosage = json['dosage'];
quantity = json['quantity'];
unit = json['unit'];
howToUse = json['howToUse'];
suppliesInWarehouseId = json['suppliesInWarehouseId'];
equipmentOfCustomerId = json['equipmentOfCustomerId'];
@@ -28,6 +31,7 @@ class SuppliesUsing {
data['id'] = this.id;
data['dosage'] = this.dosage;
data['quantity'] = this.quantity;
data['unit'] = this.unit;
data['howToUse'] = this.howToUse;
data['suppliesInWarehouseId'] = this.suppliesInWarehouseId;
data['equipmentOfCustomerId'] = this.equipmentOfCustomerId;

+ 228
- 85
lib/presentation/screens/actions/plant/sc_edit_action_plant.dart View File

@@ -1,18 +1,36 @@
import 'dart:convert';

import 'package:farm_tpf/custom_model/Plant.dart';
import 'package:farm_tpf/custom_model/SuppliesUsing.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/bloc/media_helper_bloc.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/screens/actions/bloc/action_detail_bloc.dart';
import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_file_controller.dart';
import 'package:farm_tpf/utils/const_common.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_bloc/flutter_bloc.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.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';

import '../util_action.dart';

class EditActionPlantScreen extends StatefulWidget {
final int cropId;
final bool isEdit;
final int activityId;
EditActionPlantScreen(
{@required this.cropId, this.isEdit = false, this.activityId});
@override
_EditActionPlantScreenState createState() => _EditActionPlantScreenState();
}
@@ -24,30 +42,95 @@ class _EditActionPlantScreenState extends State<EditActionPlantScreen> {
bool _autoValidate = false;
Plant _plant = Plant();
var pref = LocalPref();
FlutterToast flutterToast;
TextEditingController _descriptionController = TextEditingController();
TextEditingController _quantityController = TextEditingController();
TextEditingController _densityController = TextEditingController();
final _descriptionController = TextEditingController();
final _quantityController = TextEditingController();
final _densityController = TextEditingController();
final _executeByController = TextEditingController();
List<SuppliesUsing> suppliesUsing;

String executeTimeView;
DateTime executeTime = DateTime.now();
List<String> filePaths = List<String>();
var changeFileController = Get.put(ChangeFileController());

Future<Null> getSharedPrefs() async {
var currentFullName = await pref.getString(DATA_CONST.CURRENT_FULL_NAME);
_executeByController.text = currentFullName ?? "";
}

@override
void initState() {
super.initState();
flutterToast = FlutterToast(context);
//UPDATE
if (_plant != null) {
try {
executeTime =
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse(_plant.executeDate);
} catch (_) {}
} else {
getSharedPrefs();
changeFileController.initValue();
_plant.suppliesUsing = new List<SuppliesUsing>();
var parsedExecuteDate =
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(executeTime);
_plant.executeDate = "$parsedExecuteDate";
executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(executeTime);
_plant.cropId = widget.cropId;
}

_validateInputs() async {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files;
var activityPlant = jsonEncode(_plant.toJson()).toString();
//ADD NEW
var parsedExecuteDate =
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(executeTime);
_plant.executeDate = "$parsedExecuteDate";
if (_plant.activityId == null) {
_repository.createAction((value) {
LoadingDialog.hideLoadingDialog(context);
Get.back(result: value);
Get.snackbar(label_add_success, "Hoạt động trồng",
snackPosition: SnackPosition.BOTTOM);
}, (error) {
LoadingDialog.hideLoadingDialog(context);
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(child: Text(AppException.handleError(error))),
Icon(Icons.error),
],
),
backgroundColor: Colors.red,
duration: Duration(seconds: 3),
));
},
apiAddAction: ConstCommon.apiAddPlant,
paramActivity: ConstCommon.paramsActionPlant,
activityAction: activityPlant,
filePaths: filePaths);
} else {
//UPDATE
_repository.updateAction((value) {
LoadingDialog.hideLoadingDialog(context);
Get.back(result: value);
Get.snackbar(label_update_success, "Hoạt động trồng",
snackPosition: SnackPosition.BOTTOM);
}, (error) {
LoadingDialog.hideLoadingDialog(context);
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(child: Text(AppException.handleError(error))),
Icon(Icons.error),
],
),
backgroundColor: Colors.red,
duration: Duration(seconds: 3),
));
},
apiUpdateAction: ConstCommon.apiUpdatePlant,
paramActivity: ConstCommon.paramsActionPlant,
activityAction: activityPlant,
filePaths: filePaths);
}
} else {
_autoValidate = true;
}
executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(executeTime);
}

Widget _btnExecuteTimePicker() {
@@ -86,31 +169,6 @@ class _EditActionPlantScreenState extends State<EditActionPlantScreen> {
)));
}

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 _quantityField() {
return TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
@@ -151,6 +209,16 @@ class _EditActionPlantScreenState extends State<EditActionPlantScreen> {
);
}

Widget _executeByField() {
return TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(labelText: "Người thực hiện"),
enabled: false,
controller: _executeByController,
onSaved: (newValue) {},
);
}

_actionAppBar() {
IconButton iconButton;
if (1 == 1) {
@@ -159,7 +227,13 @@ class _EditActionPlantScreenState extends State<EditActionPlantScreen> {
Icons.done,
color: Colors.black,
),
onPressed: () {},
onPressed: () {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
_validateInputs();
},
);
return <Widget>[iconButton];
}
@@ -179,54 +253,123 @@ class _EditActionPlantScreenState extends State<EditActionPlantScreen> {
title: Text(plot_action_plant),
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,
),
_quantityField(),
SizedBox(
height: 8.0,
),
_densityField(),
SizedBox(
height: 8.0,
child: MultiBlocProvider(
providers: [
BlocProvider<ActionDetailBloc>(
create: (context) =>
ActionDetailBloc(repository: Repository())
..add(FetchData(
isNeedFetchData: widget.isEdit,
apiActivity: ConstCommon.apiDetailPlant,
activityId: widget.activityId))),
BlocProvider<MediaHelperBloc>(
create: (context) =>
MediaHelperBloc()..add(ChangeListMedia(items: [])),
)
],
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) {
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;
try {
executeTime =
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.parse(_plant.executeDate);
} catch (_) {}
executeTimeView =
DateFormat("dd/MM/yyyy HH:mm")
.format(executeTime);
//Show media
if (_plant.media != null) {
await UtilAction.cacheFiles(_plant.media)
.then((value) {
BlocProvider.of<MediaHelperBloc>(context)
.add(ChangeListMedia(items: value));
}).whenComplete(() {
print("completed");
});
}
} 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),
),
),
_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,
),
BlocBuilder<MediaHelperBloc,
MediaHelperState>(
builder: (context, state) {
if (state is MediaHelperSuccess) {
return WidgetMediaPicker(
currentItems: state.items,
onChangeFiles: (filePaths) async {
Get.find<ChangeFileController>()
.addAllFile(filePaths);
});
} else {
return Center(
child: CircularProgressIndicator());
}
}),
],
);
},
),
_desciptionField()
],
),
)))));
))))));
@override
void dispose() {
_quantityController.dispose();
_densityController.dispose();
_descriptionController.dispose();
_executeByController.dispose();
super.dispose();
}
}

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

@@ -52,7 +52,12 @@ class _PlotActionScreenState extends State<PlotActionScreen> {
EditActionNurseryScreen(
cropId: widget.cropId,
)));
actions.add(ActionType(plot_action_plant, null, EditActionPlantScreen()));
actions.add(ActionType(
plot_action_plant,
null,
EditActionPlantScreen(
cropId: widget.cropId,
)));
actions.add(ActionType(
plot_action_crop_status,
null,
@@ -444,6 +449,12 @@ class ItemInfinityWidget extends StatelessWidget {
activityId: item.id,
isEdit: true,
));
} else if (item.activityTypeName == "ACTIVE_TYPE_STATUS_GROW") {
Get.to(EditActionPlantScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else {
//TODO: Check other types
Get.to(EditActionOtherScreen(

+ 6
- 1
lib/utils/const_common.dart View File

@@ -15,6 +15,7 @@ class ConstCommon {
static const String apiDetailSell = "api/activity-sell";
static const String apiDetailEnd = "api/activity-end";
static const String apiDetailOther = "api/activity-other";
static const String apiDetailPlant = "api/activity-planting";

//nursery
static const String paramsActionNursery = "activityNursery";
@@ -52,10 +53,14 @@ class ConstCommon {
static const String paramsActionEnd = "activityEnd";
static const String apiUpdateEnd = "api/updateActivityEnd";
static const String apiAddEnd = "api/createActivityEnd";
//End
//Other
static const String paramsActionOther = "activityOther";
static const String apiUpdateOther = "api/updateActivityOther";
static const String apiAddOther = "api/createActivityOther";
//Plant
static const String paramsActionPlant = "activityPlanting";
static const String apiUpdatePlant = "api/updatePlanting";
static const String apiAddPlant = "api/createPlanting";

static const String supplyTypeSeed = "GIONG";
static const String supplyTypeDung = "PHANBON";

Loading…
Cancel
Save