Skip to content

Commit

Permalink
Merge branch 'develop' into PAINTROID-768
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenkomotive committed Nov 21, 2024
2 parents bedd5a2 + 269d3c8 commit 1e106da
Show file tree
Hide file tree
Showing 16 changed files with 606 additions and 48 deletions.
5 changes: 2 additions & 3 deletions lib/core/providers/state/canvas_state_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import 'dart:ui';

import 'package:flutter/painting.dart';
import 'package:flutter/widgets.dart' as widgets;

import 'package:riverpod_annotation/riverpod_annotation.dart';

import 'package:paintroid/core/commands/command_implementation/command.dart';
import 'package:paintroid/core/commands/command_manager/command_manager_provider.dart';
import 'package:paintroid/core/commands/graphic_factory/graphic_factory_provider.dart';
import 'package:paintroid/core/providers/object/device_service.dart';
import 'package:paintroid/core/providers/state/canvas_state_data.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'canvas_state_provider.g.dart';

Expand Down Expand Up @@ -64,6 +62,7 @@ class CanvasStateProvider extends _$CanvasStateProvider {
}

Future<void> resetCanvasWithNewCommands(Iterable<Command> commands) async {
state.commandManager.clearRedoStack();
state.commandManager.clearUndoStack(newCommands: commands);
if (commands.isEmpty) {
state = state.copyWith(cachedImage: null);
Expand Down
13 changes: 13 additions & 0 deletions lib/core/utils/widget_identifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@ class WidgetIdentifier {
static const canvasPainter = 'CanvasPainter';
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';
}
4 changes: 1 addition & 3 deletions lib/ui/pages/workspace_page/workspace_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:toast/toast.dart';

import 'package:paintroid/core/providers/object/io_handler.dart';
import 'package:paintroid/core/providers/state/workspace_state_notifier.dart';
import 'package:paintroid/ui/pages/workspace_page/components/bottom_bar/bottom_nav_bar.dart';
Expand All @@ -12,6 +9,7 @@ import 'package:paintroid/ui/pages/workspace_page/components/drawing_surface/dra
import 'package:paintroid/ui/pages/workspace_page/components/drawing_surface/exit_fullscreen_button.dart';
import 'package:paintroid/ui/pages/workspace_page/components/top_bar/top_app_bar.dart';
import 'package:paintroid/ui/shared/dialogs/discard_changes_dialog.dart';
import 'package:toast/toast.dart';

class WorkspacePage extends ConsumerStatefulWidget {
const WorkspacePage({super.key});
Expand Down
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),
identifier: WidgetIdentifier.genericDialogActionDone,
),
],
content: Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down
14 changes: 9 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,15 @@ 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),
identifier: WidgetIdentifier.genericDialogActionCancel,
),
GenericDialogAction(
title: 'Delete',
onPressed: () => Navigator.of(context).pop(true)),
title: 'Delete',
onPressed: () => Navigator.of(context).pop(true),
identifier: WidgetIdentifier.genericDialogActionDelete,
),
]),
barrierDismissible: true,
barrierLabel: 'Show delete project dialog box');
14 changes: 9 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,15 @@ 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),
identifier: WidgetIdentifier.genericDialogActionDiscard,
),
GenericDialogAction(
title: 'Save',
onPressed: () => Navigator.of(context).pop(false)),
title: 'Save',
onPressed: () => Navigator.of(context).pop(false),
identifier: WidgetIdentifier.genericDialogActionSave,
),
]),
barrierDismissible: true,
barrierLabel: 'Dismiss discard changes dialog box');
32 changes: 22 additions & 10 deletions lib/ui/shared/dialogs/generic_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import 'package:flutter/material.dart';

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

class GenericDialogActionButton extends StatelessWidget {
final String text;
final Function? onPressed;
final String identifier;

const GenericDialogActionButton(
{super.key, required this.text, this.onPressed});
const GenericDialogActionButton({
super.key,
required this.text,
this.onPressed,
required this.identifier,
});

@override
Widget build(BuildContext context) => TextButton(
key: ValueKey(identifier),
style: ButtonStyle(
foregroundColor: WidgetStateProperty.all(
PaintroidTheme.of(context).primaryColor,
Expand All @@ -26,8 +31,13 @@ class GenericDialogActionButton extends StatelessWidget {
class GenericDialogAction {
final Function? onPressed;
final String title;
final String identifier;

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

class GenericDialog extends StatelessWidget {
Expand All @@ -36,12 +46,13 @@ class GenericDialog extends StatelessWidget {
final Widget? content;
final List<GenericDialogAction> actions;

const GenericDialog(
{super.key,
required this.title,
this.text,
this.content,
required this.actions});
const GenericDialog({
super.key,
required this.title,
this.text,
this.content,
required this.actions,
});

Widget? getContent(BuildContext context) {
if (content != null) {
Expand Down Expand Up @@ -71,6 +82,7 @@ class GenericDialog extends StatelessWidget {
.map((action) => GenericDialogActionButton(
text: action.title,
onPressed: action.onPressed,
identifier: action.identifier,
))
.toList(),
content: getContent(context),
Expand Down
18 changes: 11 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,17 @@ 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),
identifier: WidgetIdentifier.genericDialogActionPhotos,
),
GenericDialogAction(
title: 'Files',
onPressed: () =>
Navigator.of(context).pop(ImageLocation.files))
title: 'Files',
onPressed: () =>
Navigator.of(context).pop(ImageLocation.files),
identifier: 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),
identifier: WidgetIdentifier.genericDialogActionCancel,
),
GenericDialogAction(
title: 'Yes',
onPressed: () => Navigator.of(context).pop(false),
identifier: 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),
identifier: 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(),
identifier: 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);
},
identifier: WidgetIdentifier.genericDialogActionRename,
),
],
content: Form(
Expand Down
Loading

0 comments on commit 1e106da

Please sign in to comment.