Skip to content

Commit

Permalink
PAINTROID-763: RedoStack not cleared for new project - add ValueKey t…
Browse files Browse the repository at this point in the history
…o genericDialogActionButtons for identification
  • Loading branch information
Lenkomotive committed Oct 5, 2024
1 parent 7c96175 commit 3e5d9cb
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 31 deletions.
12 changes: 12 additions & 0 deletions lib/core/utils/widget_identifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,16 @@ class WidgetIdentifier {
static const newImageActionButton = 'NewImageActionButton';
static const circleShapeTypeChip = 'CircleShapeTypeChip';
static const backButton = 'BackButton';

// GenericDialogAction
static const genericDialogActionDone = 'GenericDialogActionDone';
static const genericDialogActionDiscard = 'GenericDialogActionDiscard';
static const genericDialogActionSave = 'GenericDialogActionSave';
static const genericDialogActionPhotos = 'GenericDialogActionPhotos';
static const genericDialogActionFiles = 'GenericDialogActionFiles';
static const genericDialogActionCancel = 'GenericDialogActionCancel';
static const genericDialogActionDelete = 'GenericDialogActionDelete';
static const genericDialogActionOk = 'GenericDialogActionOk';
static const genericDialogActionRename = 'GenericDialogActionRename';
static const genericDialogActionYes = 'GenericDialogActionYes';
}
8 changes: 5 additions & 3 deletions lib/ui/shared/dialogs/about_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'package:paintroid/core/utils/open_url.dart';
import 'package:paintroid/core/utils/widget_identifier.dart';
import 'package:paintroid/ui/shared/dialogs/generic_dialog.dart';
import 'package:paintroid/ui/shared/images/pocketpaint_logo_small.dart';
import 'package:paintroid/ui/theme/theme.dart';
Expand Down Expand Up @@ -54,7 +53,10 @@ class _MyAboutDialogState extends ConsumerState<MyAboutDialog> {
title: 'About',
actions: [
GenericDialogAction(
title: 'DONE', onPressed: () => Navigator.of(context).pop(true)),
title: 'DONE',
onPressed: () => Navigator.of(context).pop(true),
key: const ValueKey(WidgetIdentifier.genericDialogActionDone),
),
],
content: Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down
18 changes: 13 additions & 5 deletions lib/ui/shared/dialogs/delete_project_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';

import 'package:paintroid/core/utils/widget_identifier.dart';
import 'package:paintroid/ui/shared/dialogs/generic_dialog.dart';

Future<bool?> showDeleteDialog(BuildContext context, String name) =>
Expand All @@ -10,11 +10,19 @@ Future<bool?> showDeleteDialog(BuildContext context, String name) =>
text: 'Do you really want to delete your project?',
actions: [
GenericDialogAction(
title: 'Cancel',
onPressed: () => Navigator.of(context).pop(false)),
title: 'Cancel',
onPressed: () => Navigator.of(context).pop(false),
key: const ValueKey(
WidgetIdentifier.genericDialogActionCancel,
),
),
GenericDialogAction(
title: 'Delete',
onPressed: () => Navigator.of(context).pop(true)),
title: 'Delete',
onPressed: () => Navigator.of(context).pop(true),
key: const ValueKey(
WidgetIdentifier.genericDialogActionDelete,
),
),
]),
barrierDismissible: true,
barrierLabel: 'Show delete project dialog box');
18 changes: 13 additions & 5 deletions lib/ui/shared/dialogs/discard_changes_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';

import 'package:paintroid/core/utils/widget_identifier.dart';
import 'package:paintroid/ui/shared/dialogs/generic_dialog.dart';

Future<bool?> showDiscardChangesDialog(BuildContext context) =>
Expand All @@ -11,11 +11,19 @@ Future<bool?> showDiscardChangesDialog(BuildContext context) =>
'You have not saved your last changes. They will be lost!',
actions: [
GenericDialogAction(
title: 'Discard',
onPressed: () => Navigator.of(context).pop(true)),
title: 'Discard',
onPressed: () => Navigator.of(context).pop(true),
key: const ValueKey(
WidgetIdentifier.genericDialogActionDiscard,
),
),
GenericDialogAction(
title: 'Save',
onPressed: () => Navigator.of(context).pop(false)),
title: 'Save',
onPressed: () => Navigator.of(context).pop(false),
key: const ValueKey(
WidgetIdentifier.genericDialogActionSave,
),
),
]),
barrierDismissible: true,
barrierLabel: 'Dismiss discard changes dialog box');
8 changes: 6 additions & 2 deletions lib/ui/shared/dialogs/generic_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';

import 'package:paintroid/ui/theme/theme.dart';

class GenericDialogActionButton extends StatelessWidget {
Expand All @@ -26,8 +25,13 @@ class GenericDialogActionButton extends StatelessWidget {
class GenericDialogAction {
final Function? onPressed;
final String title;
final ValueKey key;

const GenericDialogAction({Key? key, this.onPressed, required this.title});
const GenericDialogAction({
this.onPressed,
required this.title,
required this.key,
});
}

class GenericDialog extends StatelessWidget {
Expand Down
22 changes: 15 additions & 7 deletions lib/ui/shared/dialogs/load_image_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';

import 'package:paintroid/core/enums/image_location.dart';
import 'package:paintroid/core/utils/widget_identifier.dart';
import 'package:paintroid/ui/shared/dialogs/generic_dialog.dart';

Future<ImageLocation?> showLoadImageDialog(BuildContext context) =>
Expand All @@ -11,13 +11,21 @@ Future<ImageLocation?> showLoadImageDialog(BuildContext context) =>
text: 'Where do you want to load the image from?',
actions: [
GenericDialogAction(
title: 'Photos',
onPressed: () =>
Navigator.of(context).pop(ImageLocation.photos)),
title: 'Photos',
onPressed: () =>
Navigator.of(context).pop(ImageLocation.photos),
key: const ValueKey(
WidgetIdentifier.genericDialogActionPhotos,
),
),
GenericDialogAction(
title: 'Files',
onPressed: () =>
Navigator.of(context).pop(ImageLocation.files))
title: 'Files',
onPressed: () =>
Navigator.of(context).pop(ImageLocation.files),
key: const ValueKey(
WidgetIdentifier.genericDialogActionFiles,
),
),
],
),
barrierDismissible: true,
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/shared/dialogs/overwrite_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';

import 'package:paintroid/core/utils/widget_identifier.dart';
import 'package:paintroid/ui/shared/dialogs/generic_dialog.dart';

Future<bool?> showOverwriteDialog(BuildContext context) =>
Expand All @@ -13,10 +13,12 @@ Future<bool?> showOverwriteDialog(BuildContext context) =>
GenericDialogAction(
title: 'Cancel',
onPressed: () => Navigator.of(context).pop(true),
key: const ValueKey(WidgetIdentifier.genericDialogActionCancel),
),
GenericDialogAction(
title: 'Yes',
onPressed: () => Navigator.of(context).pop(false),
key: const ValueKey(WidgetIdentifier.genericDialogActionYes),
),
],
),
Expand Down
10 changes: 6 additions & 4 deletions lib/ui/shared/dialogs/project_details_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'package:flutter/material.dart';

import 'package:filesize/filesize.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
import 'package:oxidized/oxidized.dart';

import 'package:paintroid/core/models/database/project.dart';
import 'package:paintroid/core/providers/object/file_service.dart';
import 'package:paintroid/core/providers/object/image_service.dart';
import 'package:paintroid/core/utils/widget_identifier.dart';
import 'package:paintroid/ui/shared/dialogs/generic_dialog.dart';
import 'package:paintroid/ui/theme/theme.dart';
import 'package:paintroid/ui/utils/toast_utils.dart';
Expand Down Expand Up @@ -44,7 +43,10 @@ class _ProjectDetailsDialogState extends ConsumerState<ProjectDetailsDialog> {
title: widget.project.name,
actions: [
GenericDialogAction(
title: 'OK', onPressed: () => Navigator.of(context).pop(false))
title: 'OK',
onPressed: () => Navigator.of(context).pop(false),
key: const ValueKey(WidgetIdentifier.genericDialogActionOk),
),
],
content: FutureBuilder(
future: _getImageDimensions(widget.project.imagePreviewPath),
Expand Down
9 changes: 5 additions & 4 deletions lib/ui/shared/dialogs/rename_project_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';

import 'package:paintroid/core/utils/widget_identifier.dart';
import 'package:paintroid/ui/shared/dialogs/generic_dialog.dart';
import 'package:paintroid/ui/shared/text_input_field.dart';

Expand All @@ -16,9 +16,9 @@ Future<String?> showRenameDialog(BuildContext context, String name) async {
title: 'Rename $name',
actions: [
GenericDialogAction(
title: 'CANCEL',
onPressed: () => Navigator.of(context).pop(),
),
title: 'CANCEL',
onPressed: () => Navigator.of(context).pop(),
key: const ValueKey(WidgetIdentifier.genericDialogActionCancel)),
GenericDialogAction(
title: 'RENAME',
onPressed: () {
Expand All @@ -28,6 +28,7 @@ Future<String?> showRenameDialog(BuildContext context, String name) async {
}
Navigator.of(context).pop(textFieldController.text);
},
key: const ValueKey(WidgetIdentifier.genericDialogActionRename),
),
],
content: Form(
Expand Down

0 comments on commit 3e5d9cb

Please sign in to comment.