Skip to content

Commit

Permalink
Merge pull request #169 from codeforpakistan/handle-in-or-and
Browse files Browse the repository at this point in the history
Handle in or and
  • Loading branch information
sohail0992 authored Oct 26, 2023
2 parents 5000e82 + c104ed0 commit c35ff80
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
49 changes: 34 additions & 15 deletions lib/hcai_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
return WillPopScope(
onWillPop: () async {
this._showDialog(context, 'Do you want to close?',
'Your Progress will be saved as Draft.', true);
'Your Progress will be saved as Draft.', true, false);
return false;
},
child: Scaffold(
Expand All @@ -119,7 +119,7 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
child: GestureDetector(
onTap: () {
this._showDialog(context, 'Do you want to close?',
'Your progress will be Saved as Draft.', true);
'Your progress will be Saved as Draft.', true, false);
},
child: Icon(Icons.cancel_sharp, color: Colors.white),
)),
Expand Down Expand Up @@ -420,7 +420,7 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
return CoolStepper(
showErrorSnackbar: true,
onCompleted: () {
sendData(context, this._values);
sendData(context, this._values, false);
},
steps: steps,
config: CoolStepperConfig(
Expand Down Expand Up @@ -475,7 +475,8 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
? IconButton(
icon: Icon(Icons.info_outline),
onPressed: () {
_showDialog(context, "Information", helpLabelText, false);
_showDialog(
context, "Information", helpLabelText, false, false);
},
)
: null),
Expand Down Expand Up @@ -531,7 +532,8 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
? IconButton(
icon: Icon(Icons.info_outline),
onPressed: () {
_showDialog(context, "Information", helpLabelText, false);
_showDialog(
context, "Information", helpLabelText, false, false);
},
)
: null),
Expand Down Expand Up @@ -624,7 +626,11 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
),
buttonText: Text(''),
title: hasHelpLabel
? Text(helpLabelText != '' ? helpLabelText : 'Please Select')
? Text(
helpLabelText != '' ? helpLabelText : 'Please Select',
maxLines: 4,
softWrap: true,
)
: Text('Please Select'),
dialogWidth: MediaQuery.of(context).size.width * 0.9,
searchable: true,
Expand Down Expand Up @@ -692,8 +698,8 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
? IconButton(
icon: Icon(Icons.info_outline),
onPressed: () {
_showDialog(
context, "Information", helpLabelText, false);
_showDialog(context, "Information", helpLabelText,
false, false);
},
)
: null),
Expand Down Expand Up @@ -757,7 +763,8 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
? IconButton(
icon: Icon(Icons.info_outline),
onPressed: () {
_showDialog(context, "Information", helpLabelText, false);
_showDialog(
context, "Information", helpLabelText, false, false);
},
)
: null),
Expand Down Expand Up @@ -1111,6 +1118,14 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
_selectedRole['isSSI'] = this._values['isSSI'];
});
// show simple alert
if (this._values['isSSI'] == 'No') {
this._showDialog(
context,
'If SSI Event Criteria is No, you dont need to fill the other data',
'Your Progress will be saved.',
true,
true);
}
// if (this._values['isSSI'] == 'No') {
// this.updateFlagForAll(this.allSteps, true, 'SSIDetected');
// } else if (this._values['isSSI'] == 'Yes') {
Expand Down Expand Up @@ -1198,15 +1213,15 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
return data.toList();
}

sendData(context, Map values) async {
sendData(context, Map values, bool forcedSubmit) async {
try {
if (isSubmitted) {
print('stopping duplicate submission');
return;
}
values['isVerified'] = false;
values['isSubmitted'] = true;
if (!Helper.isValidData(this._values)) {
if (!Helper.isValidData(this._values) && !forcedSubmit) {
Helper.showMsg(
context,
'Please select ' + Helper.missingFields(this._values)!.join(', '),
Expand Down Expand Up @@ -1241,8 +1256,7 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
debugPrint('Dialog Dissmiss from callback $type');
Navigator.of(context).pushNamed(HomePage.tag);
})
..show()
.then((value) => Navigator.of(context).pushNamed(HomePage.tag));
..show();
} else {
Helper.showMsg(context, jsonDecode(response.body).toString(), true);
}
Expand All @@ -1251,7 +1265,8 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
}
}

_showDialog(context, String alertTitle, String alertMsg, bool showCancel) {
_showDialog(context, String alertTitle, String alertMsg, bool showCancel,
bool shouldSave) {
List<Widget> buttons = [];
if (showCancel) {
buttons.add(new MaterialButton(
Expand All @@ -1263,7 +1278,11 @@ class _HcaiFormPageState extends State<HcaiFormPage> {
buttons.add(new MaterialButton(
child: Text("Close Anyway"),
onPressed: () {
handleDraft();
if (shouldSave) {
sendData(context, this._values, true);
} else {
handleDraft();
}
Navigator.of(context, rootNavigator: true).pop('dialog');
Navigator.pop(context);
},
Expand Down
1 change: 1 addition & 0 deletions lib/utils/WidgetHelper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class WidgetHelper {
text: isRequired ? " *" : "",
style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold)),
]),
softWrap: true, // Allow text
),
SizedBox(height: 4)
]);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Helper {
animType: AnimType.leftSlide,
headerAnimationLoop: false,
dialogType: isError ? DialogType.error : DialogType.success,
showCloseIcon: false,
showCloseIcon: true,
title: isError ? 'ERROR' : 'Success',
desc: msg,
)..show();
Expand Down
4 changes: 0 additions & 4 deletions lib/utils/validation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ class Validation {
if (!isValid) {
break;
}
print(isValid);
print(eachOR?['type']);
print(eachOR?['selecteds']);
}
;
return returnType == 'bool' ? isValid : (isValid ? 'Yes' : 'No');
} catch (err) {
print(err);
Expand Down

0 comments on commit c35ff80

Please sign in to comment.