-
Notifications
You must be signed in to change notification settings - Fork 80
chore: Alert dialog implementation #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: alpha
Are you sure you want to change the base?
Conversation
tenshiAMD
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dinurymomshad hi, can you rebase and check if all works fine? thanks
| required this.setExerciseName, | ||
| }); | ||
|
|
||
| final Function(String) setExerciseName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add return type and name of the parameter, so final void Function(String name) setExerciseName;
| // set up the AlertDialog | ||
| RedoWorkoutAlert alert = RedoWorkoutAlert(viewButton, redoButton); | ||
| Future<void> _showViewOrRedoAlertDialog(BuildContext context) async { | ||
| if (await showViewOrRedoAlertDialog(context)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe work with an enum here that is returned instead of a bool, because now its not entirely clear when "true" is returned for example if this means a redo or a view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Work with guard clauses when you can to make code less cluttered and more readable, here for example:
Future<void> _showViewOrRedoAlertDialog(BuildContext context) async {
if (!await showViewOrRedoAlertDialog(context)) return addExercises(widget.workout);
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => WorkoutPage(widget.workout),
),
);
}
| ); | ||
| /// Alert Dialogs | ||
| void _showAddNewExerciseDialog(BuildContext context) async { | ||
| ExerciseInputField exerciseNameSelectionWidget = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use final for fields that don't change + guard clause, also be consistent when you want to declare variables, exerciseNameSelection widget gets stored into a variable before being used in the dialog, but the SaveWorkoutContent widget just gets send directly to the dialog.
void _showAddNewExerciseDialog(BuildContext context) async {
final exerciseNameSelectionWidget = ExerciseInputField(setExerciseName: setExerciseName);
if (!await showAddNewExerciseDialog(context, exerciseNameSelectionWidget)) return;
addExercise();
}
| required this.title, | ||
| this.subtitle, | ||
| this.content, | ||
| required this.buttons, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put required parameters first
| final Map<String, T> buttons; | ||
| } | ||
|
|
||
| extension Present<T> on AlertDialogModel<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name it something like PresentExtension so you know its an extension from the name.
| return ThemeProvider(builder: (context, AppTheme theme) { | ||
| return AlertDialog( | ||
| backgroundColor: theme.colorTheme.backgroundColorVariation, | ||
| titleTextStyle: Theme.of(context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Store the theme in a variable at the top of this method so you don't have to call .of(context) every time.
| backgroundColor: theme.colorTheme.backgroundColorVariation, | ||
| titleTextStyle: Theme.of(context) | ||
| .textTheme | ||
| .headline6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not for this PR immediately, but we should store the different textThemes in the theme provided by themeProvider ass well so we don't have 2 themes.
| context: context, | ||
| barrierDismissible: barrierDismissible, | ||
| builder: (context) { | ||
| return ThemeProvider(builder: (context, AppTheme theme) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defining the type of theme here isn't necessary .
| } | ||
|
|
||
| Future<bool> showDeleteWorkoutDialog(BuildContext context) { | ||
| return const _DeleteDialog(objName: 'workout').present(context).then( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I think using await is clearer and looks better than using then + const isn't needed here since you're not storing the dialog. Same for the rest of the dialogs (the await not the const)
Future<bool> showDeleteWorkoutDialog(BuildContext context) async {
final result = await _DeleteDialog(objName: 'workout').present(context);
return result ?? false;
}
Or maybe better
Future<bool> showDeleteWorkoutDialog(BuildContext context) async => await _DeleteDialog(objName: 'workout').present(context) ?? false;
|
|
||
| Future<bool> showAddNewExerciseDialog(BuildContext context, Widget? content) { | ||
| return _AddNewExerciseDialog( | ||
| objName: 'Exercise', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would maybe have the objName as an optional parameter to the showAddNewExerciesDialog method because otherwise I don't really see the reason it isn't just hardcoded in the constructor above, same for the rest of the dialogs.
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
|
Lines of code have too many changes. It should be under 500 lines of addtions and deletions. |
1 similar comment
|
Lines of code have too many changes. It should be under 500 lines of addtions and deletions. |
Summary
This MR aims to close #84 .
Other Information
Some unused code was removed.