Browse Source

update action

smf
daivp 4 years ago
parent
commit
ce3aa02c3f
4 changed files with 144 additions and 70 deletions
  1. +5
    -1
      lib/custom_model/action_form/RequestActivity.dart
  2. +2
    -3
      lib/data/repository/repository.dart
  3. +137
    -64
      lib/presentation/screens/actions/sc_action.dart
  4. +0
    -2
      lib/presentation/screens/splash/view/splash_page.dart

+ 5
- 1
lib/custom_model/action_form/RequestActivity.dart View File

import 'package:farm_tpf/custom_model/action_form/ActionUIField.dart'; import 'package:farm_tpf/custom_model/action_form/ActionUIField.dart';


class RequestActivity { class RequestActivity {
int id;
int tbActivityTypeId; int tbActivityTypeId;
int tbCropId; int tbCropId;
num totalCost; num totalCost;
List<String> deletedImages; List<String> deletedImages;


RequestActivity( RequestActivity(
{this.tbActivityTypeId,
{this.id,
this.tbActivityTypeId,
this.tbCropId, this.tbCropId,
this.totalCost, this.totalCost,
this.executeDate, this.executeDate,
this.deletedImages}); this.deletedImages});


RequestActivity.fromJson(Map<String, dynamic> json) { RequestActivity.fromJson(Map<String, dynamic> json) {
id = json['id'];
tbActivityTypeId = json['tbActivityTypeId']; tbActivityTypeId = json['tbActivityTypeId'];
tbCropId = json['tbCropId']; tbCropId = json['tbCropId'];
totalCost = json['totalCost']; totalCost = json['totalCost'];


Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>(); final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['tbActivityTypeId'] = this.tbActivityTypeId; data['tbActivityTypeId'] = this.tbActivityTypeId;
data['tbCropId'] = this.tbCropId; data['tbCropId'] = this.tbCropId;
data['totalCost'] = this.totalCost; data['totalCost'] = this.totalCost;

+ 2
- 3
lib/data/repository/repository.dart View File

Future<void> updateActionCommon( Future<void> updateActionCommon(
Function(dynamic) onSuccess, Function(dynamic) onError, Function(dynamic) onSuccess, Function(dynamic) onError,
{@required String activityType, {@required String activityType,
@required int activityId,
@required String activityData, @required String activityData,
List<String> filePaths}) async { List<String> filePaths}) async {
var formData = FormData(); var formData = FormData();
formData.fields.add(MapEntry('tbCommonActivityDTO', activityData)); formData.fields.add(MapEntry('tbCommonActivityDTO', activityData));
try { try {
await dio await dio
.put(
"${ConstCommon.baseUrl}/api/update-common-activity/$activityType/$activityId",
.post(
"${ConstCommon.baseUrl}/api/update-common-activity/$activityType",
data: formData) data: formData)
.then((value) { .then((value) {
onSuccess(value.data); onSuccess(value.data);

+ 137
- 64
lib/presentation/screens/actions/sc_action.dart View File

var _nurseryDetails = <TbNurseryDetailsDTO>[]; var _nurseryDetails = <TbNurseryDetailsDTO>[];
var _supplyUsings = <SuppliesUsing>[]; var _supplyUsings = <SuppliesUsing>[];


var _previousGroupFieldName = '';

Future<Null> getSharedPrefs() async { Future<Null> getSharedPrefs() async {
var currentFullName = await pref.getString(DATA_CONST.CURRENT_FULL_NAME); var currentFullName = await pref.getString(DATA_CONST.CURRENT_FULL_NAME);
_executeByController.text = currentFullName ?? ""; _executeByController.text = currentFullName ?? "";
widget.activityType == 'ACTIVE_TYPE_SPRAYING_PESTICIDES') { widget.activityType == 'ACTIVE_TYPE_SPRAYING_PESTICIDES') {
_requestActivity.tbSuppliesUsingDetailsDTOs = _supplyUsings; _requestActivity.tbSuppliesUsingDetailsDTOs = _supplyUsings;
} }
//delete images
_requestActivity.deletedImages =
Get.find<ChangeFileController>().deleteFiles;
//convert data to json //convert data to json
var activityCommonData = var activityCommonData =
jsonEncode(_requestActivity.toJson()).toString(); jsonEncode(_requestActivity.toJson()).toString();
}, },
activityType: widget.activityType, activityType: widget.activityType,
activityData: activityCommonData, activityData: activityCommonData,
activityId: widget.activityId,
filePaths: filePaths); filePaths: filePaths);
} }


// //
// GENERATE DYNAMIC FORM // GENERATE DYNAMIC FORM
// //
Widget groupName(String name) {
if (_previousGroupFieldName == name ||
!Validators.stringNotNullOrEmpty(name)) {
return SizedBox();
} else {
var isShowEndline = false;
if (Validators.stringNotNullOrEmpty(_previousGroupFieldName)) {
isShowEndline = true;
} else {
//isShowEndline = false;
}
_previousGroupFieldName = name ?? '';
return Container(
child: Column(
children: [
isShowEndline
? Container(
width: double.infinity,
height: 0.35,
color: Colors.grey[300],
)
: SizedBox(),
Row(
children: [
Container(
width: 24,
height: 0.35,
color: Colors.grey[300],
),
Text(' ${name ?? ''} '),
Expanded(
child: Container(
width: 5,
height: 0.35,
color: Colors.grey[300],
),
),
],
),
],
),
);
}
}


Widget generateTextField(List<ActionUIField> fields) {
Widget generateField(List<ActionUIField> fields) {
return Wrap( return Wrap(
children: [ children: [
ListView.separated( ListView.separated(
itemBuilder: (context, index) { itemBuilder: (context, index) {
var field = fields[index]; var field = fields[index];
if (field.tbControlTypeName == 'text') { if (field.tbControlTypeName == 'text') {
return TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(labelText: field.description),
controller: textFieldControllers[field.id.toString()],
onSaved: (newValue) {},
validator: field.isMandatory
? (String value) {
return Validators.validateNotNullOrEmpty(
value, 'Vui lòng nhập ${field.description}');
}
: null,
return Column(
children: [
groupName(field.groupName),
TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(labelText: field.description),
controller: textFieldControllers[field.id.toString()],
onSaved: (newValue) {},
validator: field.isMandatory
? (String value) {
return Validators.validateNotNullOrEmpty(
value, 'Vui lòng nhập ${field.description}');
}
: null,
),
],
); );
} else if (field.tbControlTypeName == 'number') { } else if (field.tbControlTypeName == 'number') {
return WidgetTextFormFieldNumber(
hintValue: field.description,
textController: textFieldControllers[field.id.toString()],
onSaved: (newValue) {},
validator: field.isMandatory
? (String value) {
return Validators.validNumberOrEmpty(
value, 'Vui lòng nhập ${field.description}');
}
: null,
return Column(
children: [
groupName(field.groupName),
WidgetTextFormFieldNumber(
hintValue: field.description,
textController: textFieldControllers[field.id.toString()],
onSaved: (newValue) {},
validator: field.isMandatory
? (String value) {
return Validators.validNumberOrEmpty(
value, 'Vui lòng nhập ${field.description}');
}
: null,
),
],
); );
} else if (field.tbControlTypeName == 'textarea') { } else if (field.tbControlTypeName == 'textarea') {
return TextFieldAreaWidget(
hint: field.description,
controller: textFieldControllers[field.id.toString()],
onSaved: (newValue) {});
return Column(
children: [
groupName(field.groupName),
TextFieldAreaWidget(
hint: field.description,
controller: textFieldControllers[field.id.toString()],
onSaved: (newValue) {}),
],
);
} else if (field.tbControlTypeName == 'dropdown' || } else if (field.tbControlTypeName == 'dropdown' ||
field.tbControlTypeName == 'radiobutton') { field.tbControlTypeName == 'radiobutton') {
return DropdownSupplyWidget(
titleName: field.description ?? '',
tbSupply: field.tbActivityExtendTypeExternalTable ?? '',
tag: field.name,
value: field.description,
hint:
'${field.description} ${field.isMandatory ? '*' : ''}',
condition: field.tbActivityExtendTypeCondition,
invalidMessage: '',
onPressed: (commonData) {
valueObjects[field.id.toString()] =
commonData.id.toString();
});
return Column(
children: [
groupName(field.groupName),
DropdownSupplyWidget(
titleName: field.description ?? '',
tbSupply: field.tbActivityExtendTypeExternalTable ?? '',
tag: field.name,
value: field.description,
hint:
'${field.description} ${field.isMandatory ? '*' : ''}',
condition: field.tbActivityExtendTypeCondition,
invalidMessage: '',
onPressed: (commonData) {
valueObjects[field.id.toString()] =
commonData.id.toString();
}),
],
);
} else if (field.tbControlTypeName == 'date') { } else if (field.tbControlTypeName == 'date') {
return FieldDateWidget(
tag: field.name,
value: field.description,
hint:
'${field.description} ${field.isMandatory ? '*' : ''}',
invalidMessage: '',
onPressed: (selectedDate) {
valueObjects[field.id.toString()] = selectedDate
.convertLocalDateTimeToStringUtcDateTime();
});
return Column(
children: [
groupName(field.groupName),
FieldDateWidget(
tag: field.name,
value: field.description,
hint:
'${field.description} ${field.isMandatory ? '*' : ''}',
invalidMessage: '',
onPressed: (selectedDate) {
valueObjects[field.id.toString()] = selectedDate
.convertLocalDateTimeToStringUtcDateTime();
}),
],
);
} else { } else {
return Container(); return Container();
} }
if (_requestActivity.tbObjectUpdateDTOList != null) { if (_requestActivity.tbObjectUpdateDTOList != null) {
print(textFieldControllers.keys.toList()); print(textFieldControllers.keys.toList());
_requestActivity.tbObjectUpdateDTOList.forEach((element) { _requestActivity.tbObjectUpdateDTOList.forEach((element) {
if (element.tbObjectParameterDTO.tbControlTypeName == 'text' ||
element.tbObjectParameterDTO.tbControlTypeName == 'textarea') {
if (element.tbObjectParameterDTO?.tbControlTypeName == 'text' ||
element.tbObjectParameterDTO?.tbControlTypeName == 'textarea') {
SchedulerBinding.instance.addPostFrameCallback((_) { SchedulerBinding.instance.addPostFrameCallback((_) {
textFieldControllers[element.tbObjectParameterId.toString()].text = textFieldControllers[element.tbObjectParameterId.toString()].text =
element.index; element.index;
}); });
} else if (element.tbObjectParameterDTO.tbControlTypeName == 'number') {
} else if (element.tbObjectParameterDTO?.tbControlTypeName ==
'number') {
SchedulerBinding.instance.addPostFrameCallback((_) { SchedulerBinding.instance.addPostFrameCallback((_) {
textFieldControllers[element.tbObjectParameterId.toString()].text = textFieldControllers[element.tbObjectParameterId.toString()].text =
element.index.formatStringToStringDecimal(); element.index.formatStringToStringDecimal();
}); });
} else { } else {
SchedulerBinding.instance.addPostFrameCallback((_) { SchedulerBinding.instance.addPostFrameCallback((_) {
print("SchedulerBinding");
if (element.tbObjectParameterDTO.tbControlTypeName == 'dropdown' ||
element.tbObjectParameterDTO.tbControlTypeName == 'radio') {
if (element.tbObjectParameterDTO?.tbControlTypeName == 'dropdown' ||
element.tbObjectParameterDTO?.tbControlTypeName == 'radio') {
var dropdownValueName = ''; var dropdownValueName = '';
if (element.tbObjectParameterDTO if (element.tbObjectParameterDTO
.tbActivityExtendTypeDropDownDTOList.isNotEmpty ||
?.tbActivityExtendTypeDropDownDTOList?.isNotEmpty ||
element.tbObjectParameterDTO element.tbObjectParameterDTO
.tbActivityExtendTypeDropDownDTOList !=
?.tbActivityExtendTypeDropDownDTOList !=
null) { null) {
element.tbObjectParameterDTO.tbActivityExtendTypeDropDownDTOList
element
.tbObjectParameterDTO?.tbActivityExtendTypeDropDownDTOList
.forEach((dropdownData) { .forEach((dropdownData) {
if (dropdownData.id == int.tryParse(element.index)) { if (dropdownData.id == int.tryParse(element.index)) {
dropdownValueName = dropdownData.name; dropdownValueName = dropdownData.name;
..id = int.tryParse(element.index) ..id = int.tryParse(element.index)
..name = dropdownValueName; ..name = dropdownValueName;
Get.find<ChangeDropdownController>( Get.find<ChangeDropdownController>(
tag: element.tbObjectParameterDTO.name)
tag: element.tbObjectParameterDTO?.name)
.change(commonData); .change(commonData);
} else if (element.tbObjectParameterDTO.tbControlTypeName ==
} else if (element.tbObjectParameterDTO?.tbControlTypeName ==
'date') { 'date') {
Get.find<ChangeDateTimePicker>( Get.find<ChangeDateTimePicker>(
tag: element.tbObjectParameterDTO.name)
tag: element.tbObjectParameterDTO?.name)
.change(element.index .change(element.index
.convertStringServerDateTimeToLocalDateTime()); .convertStringServerDateTimeToLocalDateTime());
} }
], ],
child: Scaffold( child: Scaffold(
backgroundColor: Colors.white, backgroundColor: Colors.white,
// key: _scaffoldKey,
appBar: AppBarWidget( appBar: AppBarWidget(
isBack: true, isBack: true,
action: InkWell( action: InkWell(
SizedBox( SizedBox(
height: 8.0, height: 8.0,
), ),
generateTextField(_actionUIForm
generateField(_actionUIForm
.objectParameterDTOList), .objectParameterDTOList),
_executeByField(), _executeByField(),
SizedBox( SizedBox(

+ 0
- 2
lib/presentation/screens/splash/view/splash_page.dart View File

import 'package:farm_tpf/utils/const_assets.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart';


class SplashPage extends StatelessWidget { class SplashPage extends StatelessWidget {
static Route route() { static Route route() {

Loading…
Cancel
Save