Simplify/Create the AlertDialog API
linxydmhg opened this issue · comments
It would be a good enhancement to create some common base classes/simple API for your AlertDialogs, so that much repeated, similar, mostly design boilerplate code can be eliminated from various places.
In the end we can go, for example, from this:
The entire DeleteWorkoutAlert.class
Plus
showDeleteWorkoutAlertDialog(BuildContext context) {
RaisedGradientButton okButton = RaisedGradientButton(
gradient: LinearGradient(
colors: <Color>[Color(0xFF34D1C2), Color(0xFF31A6DC)],
),
radius: 30,
child: Text(
"DELETE",
style: buttonTextSmall,
),
onPressed: () {
deleteWorkout(workoutData.workout);
Navigator.of(context).pop();
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => CalendarPage(
),
),
);
},
);
// set up the AlertDialog
DeleteWorkoutAlert alert = DeleteWorkoutAlert(okButton);
// show the dialog
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
To just these few lines of code
showDeleteWorkoutAlertDialog() async {
final response = await showConfirmationDialog(title: 'Are you sure you want to delete this workout?');
if(response) {
// Delete workout
// Navigate
}
}
Like this we can eliminate some then redundant classes, and greatly cleanup the code that is inside the Pages calling for AlertDialogs
Great suggestion! The entire code base can definitely be refactored quite a bit
Can I Work On This Issue?? or is it Solved
@vivekdusad I am not sure if this was solved completely in the #97 PR. @jorre127 what do you think?
@KalleHallden Hmm #97 did improve it by moving the alert to a mixin, but I don't think it's complete quite yet. currently. We still have separate methods to call different alerts like "showLogoutAlert", but this ideally should all be one method "showCustomAlert" or maybe a couple If we want really specific alerts. And then just customise the alert by passing the right properties like title, accept, cancel, body etc. So I don't think it's quite complete yet.
So yeah I think you can still work on this issue if you want @vivekdusad.
Okay nice then it's all yours if you still want it @vivekdusad
ok Thanks ;)
ok Thanks ;)
Did you start? I am already working on it since this morning. :/
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.