Browse Source

show init value dropdown

smf
daivp 4 years ago
parent
commit
c194a01122
3 changed files with 92 additions and 22 deletions
  1. +39
    -1
      lib/custom_model/action_form/ActionUIField.dart
  2. +5
    -4
      lib/data/repository/repository.dart
  3. +48
    -17
      lib/presentation/screens/actions/sc_action.dart

+ 39
- 1
lib/custom_model/action_form/ActionUIField.dart View File

@@ -17,6 +17,7 @@ class ActionUIField {
bool isGuidelineUsing;
bool isMandatory;
String groupName;
List<TbActivityExtendTypeDropDownDTO> tbActivityExtendTypeDropDownDTOList;

ActionUIField(
{this.id,
@@ -36,7 +37,8 @@ class ActionUIField {
this.foreignKey,
this.isGuidelineUsing,
this.isMandatory,
this.groupName});
this.groupName,
this.tbActivityExtendTypeDropDownDTOList});

ActionUIField.fromJson(Map<String, dynamic> json) {
id = json['id'];
@@ -58,6 +60,14 @@ class ActionUIField {
isGuidelineUsing = json['isGuidelineUsing'];
isMandatory = json['isMandatory'];
groupName = json['groupName'];
if (json['tbActivityExtendTypeDropDownDTOList'] != null) {
tbActivityExtendTypeDropDownDTOList =
new List<TbActivityExtendTypeDropDownDTO>();
json['tbActivityExtendTypeDropDownDTOList'].forEach((v) {
tbActivityExtendTypeDropDownDTOList
.add(new TbActivityExtendTypeDropDownDTO.fromJson(v));
});
}
}

Map<String, dynamic> toJson() {
@@ -82,6 +92,34 @@ class ActionUIField {
data['isGuidelineUsing'] = this.isGuidelineUsing;
data['isMandatory'] = this.isMandatory;
data['groupName'] = this.groupName;
if (this.tbActivityExtendTypeDropDownDTOList != null) {
data['tbActivityExtendTypeDropDownDTOList'] = this
.tbActivityExtendTypeDropDownDTOList
.map((v) => v.toJson())
.toList();
}
return data;
}
}

class TbActivityExtendTypeDropDownDTO {
int id;
String description;
String name;

TbActivityExtendTypeDropDownDTO({this.id, this.description, this.name});

TbActivityExtendTypeDropDownDTO.fromJson(Map<String, dynamic> json) {
id = json['id'];
description = json['description'];
name = json['name'];
}

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

+ 5
- 4
lib/data/repository/repository.dart View File

@@ -272,18 +272,19 @@ class Repository {

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

+ 48
- 17
lib/presentation/screens/actions/sc_action.dart View File

@@ -59,7 +59,6 @@ class ActionScreen extends StatefulWidget {
}

class _ActionScreenState extends State<ActionScreen> {
final _scaffoldKey = GlobalKey<ScaffoldState>();
var _formKey = GlobalKey<FormState>();
var pref = LocalPref();
final _executeByController = TextEditingController();
@@ -131,17 +130,36 @@ class _ActionScreenState extends State<ActionScreen> {
var activityCommonData =
jsonEncode(_requestActivity.toJson()).toString();
print(activityCommonData);
_repository.createActionCommon((data) {
LoadingDialog.hideLoadingDialog(context);
Get.back(result: 'ok');
Utils.showSnackBarSuccess(message: label_add_success);
}, (error) {
LoadingDialog.hideLoadingDialog(context);
Utils.showSnackBarError(message: AppException.handleError(error));
},
activityType: widget.activityType,
activityData: activityCommonData,
filePaths: filePaths);

if (widget.activityId < 0) {
//ADD New
_repository.createActionCommon((data) {
LoadingDialog.hideLoadingDialog(context);
Get.back(result: 'ok');
Utils.showSnackBarSuccess(message: label_add_success);
}, (error) {
LoadingDialog.hideLoadingDialog(context);
Utils.showSnackBarError(message: AppException.handleError(error));
},
activityType: widget.activityType,
activityData: activityCommonData,
filePaths: filePaths);
} else {
//UPDATE
_repository.updateActionCommon((data) {
LoadingDialog.hideLoadingDialog(context);
Get.back(result: 'ok');
Utils.showSnackBarSuccess(message: label_update_success);
}, (error) {
LoadingDialog.hideLoadingDialog(context);
Utils.showSnackBarError(message: AppException.handleError(error));
},
activityType: widget.activityType,
activityData: activityCommonData,
activityId: widget.activityId,
filePaths: filePaths);
}

//ADD NEW
//Update

@@ -360,9 +378,22 @@ class _ActionScreenState extends State<ActionScreen> {
print("SchedulerBinding");
if (element.tbObjectParameterDTO.tbControlTypeName == 'dropdown' ||
element.tbObjectParameterDTO.tbControlTypeName == 'radio') {
var dropdownValueName = '';
if (element.tbObjectParameterDTO
.tbActivityExtendTypeDropDownDTOList.isNotEmpty ||
element.tbObjectParameterDTO
.tbActivityExtendTypeDropDownDTOList !=
null) {
element.tbObjectParameterDTO.tbActivityExtendTypeDropDownDTOList
.forEach((dropdownData) {
if (dropdownData.id == int.tryParse(element.index)) {
dropdownValueName = dropdownData.name;
}
});
}
var commonData = CommonData()
..id = int.tryParse(element.index)
..name = '';
..name = dropdownValueName;
Get.find<ChangeDropdownController>(
tag: element.tbObjectParameterDTO.name)
.change(commonData);
@@ -399,10 +430,10 @@ class _ActionScreenState extends State<ActionScreen> {
color: Colors.red, fontWeight: FontWeight.normal),
),
onTap: () {
// FocusScopeNode currentFocus = FocusScope.of(context);
// if (!currentFocus.hasPrimaryFocus) {
// currentFocus.unfocus();
// }
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
_validateInputs();
},
),

Loading…
Cancel
Save