From 5d930a63004e8fab6f75146d6011d28216232738 Mon Sep 17 00:00:00 2001 From: vishad-tyagi <78733360+vishad-tyagi@users.noreply.github.com> Date: Thu, 29 Feb 2024 05:13:08 +0530 Subject: [PATCH 1/6] Add share menu option in paint view --- ios/Podfile.lock | 8 +++- .../src/components/top_bar/overflow_menu.dart | 47 +++++++++++++++---- .../l10n/lib/src/l10n/app_localizations.dart | 13 +++-- .../lib/src/l10n/app_localizations_en.dart | 4 ++ pubspec.lock | 8 ++++ pubspec.yaml | 1 + 6 files changed, 67 insertions(+), 14 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 62cb12ec..4fbcd90b 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -57,6 +57,8 @@ PODS: - SDWebImage (5.13.1): - SDWebImage/Core (= 5.13.1) - SDWebImage/Core (5.13.1) + - share (0.0.1): + - Flutter - shared_preferences_foundation (0.0.1): - Flutter - FlutterMacOS @@ -78,6 +80,7 @@ DEPENDENCIES: - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) + - share (from `.symlinks/plugins/share/ios`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) - sqflite (from `.symlinks/plugins/sqflite/ios`) - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) @@ -111,6 +114,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/path_provider_foundation/darwin" permission_handler_apple: :path: ".symlinks/plugins/permission_handler_apple/ios" + share: + :path: ".symlinks/plugins/share/ios" shared_preferences_foundation: :path: ".symlinks/plugins/shared_preferences_foundation/darwin" sqflite: @@ -133,6 +138,7 @@ SPEC CHECKSUMS: path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943 permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6 SDWebImage: fb26a455eeda4c7a55e4dcb6172dbb258af7a4ca + share: 0b2c3e82132f5888bccca3351c504d0003b3b410 shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126 sqflite: 31f7eba61e3074736dff8807a9b41581e4f7f15a SwiftyGif: 6c3eafd0ce693cad58bb63d2b2fb9bacb8552780 @@ -140,4 +146,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: a62623f56f2d1d0e85a4a3c73509cd2832d5c86f -COCOAPODS: 1.14.3 +COCOAPODS: 1.15.0 diff --git a/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart b/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart index 238c4863..53160cfb 100644 --- a/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart +++ b/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart @@ -7,13 +7,15 @@ import 'package:l10n/l10n.dart'; import 'package:oxidized/oxidized.dart'; import 'package:toast/toast.dart'; import 'package:workspace_screen/workspace_screen.dart'; +import 'package:share/share.dart'; enum OverflowMenuOption { fullscreen, saveImage, saveProject, loadImage, - newImage; + newImage, + share; String localizedLabel(BuildContext context) { final localizations = AppLocalizations.of(context); @@ -28,6 +30,9 @@ enum OverflowMenuOption { return localizations.newImage; case OverflowMenuOption.saveProject: return localizations.saveProject; + + case OverflowMenuOption.share: + return localizations.share; } } } @@ -48,11 +53,11 @@ class _OverflowMenuState extends ConsumerState { onSelected: _handleSelectedOption, itemBuilder: (BuildContext context) => OverflowMenuOption.values .map((option) => PopupMenuItem( - value: option, - child: Text( - option.localizedLabel(context), - style: TextThemes.menuItem, - ))) + value: option, + child: Text( + option.localizedLabel(context), + style: TextThemes.menuItem, + ))) .toList(), ); } @@ -75,6 +80,11 @@ class _OverflowMenuState extends ConsumerState { case OverflowMenuOption.newImage: ioHandler.newImage(context, this); break; + + // added case + case OverflowMenuOption.share: + _shareContent(); + break; } } @@ -114,7 +124,7 @@ class _OverflowMenuState extends ConsumerState { final fileService = ref.watch(IFileService.provider); final fileName = '${imageData.name}.${imageData.format.extension}'; final fileExists = - await fileService.checkIfFileExistsInApplicationDirectory(fileName); + await fileService.checkIfFileExistsInApplicationDirectory(fileName); if (fileExists) { final overWriteCanceled = await _showOverwriteDialog(); @@ -132,6 +142,27 @@ class _OverflowMenuState extends ConsumerState { return true; } + + + void _shareContent() { + + // final String imagePath = ioHandler.getCurrentImagePath(); + // + // if (imagePath.isNotEmpty) { + // + // Share.shareFiles([imagePath], text: 'Check out my creation'); + // } else { + // Toast.show( + // 'No image to share', + // duration: Toast.lengthShort, + // gravity: Toast.bottom, + // ); + // } + + Share.share('Check out this great app!'); + } + + Future _saveProject() async { final imageData = await showSaveImageDialog(context, true); @@ -151,7 +182,7 @@ class _OverflowMenuState extends ConsumerState { final savedProject = await ioHandler.saveProject(catrobatImageData); if (savedProject != null) { String? imagePreview = - await ioHandler.getPreviewPath(catrobatImageData); + await ioHandler.getPreviewPath(catrobatImageData); Project projectNew = Project( name: catrobatImageData.name, path: savedProject.path, diff --git a/packages/l10n/lib/src/l10n/app_localizations.dart b/packages/l10n/lib/src/l10n/app_localizations.dart index 86fb2fbb..a218c5ac 100644 --- a/packages/l10n/lib/src/l10n/app_localizations.dart +++ b/packages/l10n/lib/src/l10n/app_localizations.dart @@ -69,7 +69,7 @@ abstract class AppLocalizations { } static const LocalizationsDelegate delegate = - _AppLocalizationsDelegate(); + _AppLocalizationsDelegate(); /// A list of this localizations delegate along with the default localizations /// delegates. @@ -82,7 +82,7 @@ abstract class AppLocalizations { /// MaterialApp. This list does not have to be used at all if a custom list /// of delegates is preferred or required. static const List> localizationsDelegates = - >[ + >[ delegate, GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate, @@ -145,6 +145,9 @@ abstract class AppLocalizations { /// In en, this message translates to: /// **'Layers'** String get layers; + + + String get share; } class _AppLocalizationsDelegate @@ -173,7 +176,7 @@ AppLocalizations lookupAppLocalizations(Locale locale) { throw FlutterError( 'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely ' - 'an issue with the localizations generation tool. Please file an issue ' - 'on GitHub with a reproducible sample app and the gen-l10n configuration ' - 'that was used.'); + 'an issue with the localizations generation tool. Please file an issue ' + 'on GitHub with a reproducible sample app and the gen-l10n configuration ' + 'that was used.'); } diff --git a/packages/l10n/lib/src/l10n/app_localizations_en.dart b/packages/l10n/lib/src/l10n/app_localizations_en.dart index 3d07e5cc..8eaeaaf9 100644 --- a/packages/l10n/lib/src/l10n/app_localizations_en.dart +++ b/packages/l10n/lib/src/l10n/app_localizations_en.dart @@ -19,6 +19,10 @@ class AppLocalizationsEn extends AppLocalizations { @override String get saveProject => 'Save project'; + + @override + String get share => 'Share'; + @override String get tools => 'Tools'; diff --git a/pubspec.lock b/pubspec.lock index 23ee001e..386048ce 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1085,6 +1085,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.27.7" + share: + dependency: "direct main" + description: + name: share + sha256: "97e6403f564ed1051a01534c2fc919cb6e40ea55e60a18ec23cee6e0ce19f4be" + url: "https://pub.dev" + source: hosted + version: "2.0.4" shared_preferences: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 5a441042..080a48dc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -22,6 +22,7 @@ dependencies: shared_preferences: ^2.0.15 freezed_annotation: ^2.4.1 melos: ^3.4.0 + share: ^2.0.4 # Internal packages: component_library: From 6eac329bb3a080f42c5e47a7716e750513c2d94d Mon Sep 17 00:00:00 2001 From: vishad-tyagi <78733360+vishad-tyagi@users.noreply.github.com> Date: Wed, 6 Mar 2024 12:09:48 +0530 Subject: [PATCH 2/6] Made changes to share package --- .../src/components/top_bar/overflow_menu.dart | 16 ---------------- packages/features/workspace_screen/pubspec.yaml | 1 + .../l10n/lib/src/l10n/app_localizations_en.dart | 1 - pubspec.lock | 2 +- pubspec.yaml | 1 - 5 files changed, 2 insertions(+), 19 deletions(-) diff --git a/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart b/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart index 53160cfb..5b1cf602 100644 --- a/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart +++ b/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart @@ -30,7 +30,6 @@ enum OverflowMenuOption { return localizations.newImage; case OverflowMenuOption.saveProject: return localizations.saveProject; - case OverflowMenuOption.share: return localizations.share; } @@ -80,8 +79,6 @@ class _OverflowMenuState extends ConsumerState { case OverflowMenuOption.newImage: ioHandler.newImage(context, this); break; - - // added case case OverflowMenuOption.share: _shareContent(); break; @@ -146,19 +143,6 @@ class _OverflowMenuState extends ConsumerState { void _shareContent() { - // final String imagePath = ioHandler.getCurrentImagePath(); - // - // if (imagePath.isNotEmpty) { - // - // Share.shareFiles([imagePath], text: 'Check out my creation'); - // } else { - // Toast.show( - // 'No image to share', - // duration: Toast.lengthShort, - // gravity: Toast.bottom, - // ); - // } - Share.share('Check out this great app!'); } diff --git a/packages/features/workspace_screen/pubspec.yaml b/packages/features/workspace_screen/pubspec.yaml index a9f876a7..7219ae20 100644 --- a/packages/features/workspace_screen/pubspec.yaml +++ b/packages/features/workspace_screen/pubspec.yaml @@ -21,6 +21,7 @@ dependencies: toast: ^0.3.0 image: ^3.2.0 oxidized: ^5.2.0 + share: ^2.0.4 # Internal packages component_library: diff --git a/packages/l10n/lib/src/l10n/app_localizations_en.dart b/packages/l10n/lib/src/l10n/app_localizations_en.dart index 8eaeaaf9..5f4be1c0 100644 --- a/packages/l10n/lib/src/l10n/app_localizations_en.dart +++ b/packages/l10n/lib/src/l10n/app_localizations_en.dart @@ -19,7 +19,6 @@ class AppLocalizationsEn extends AppLocalizations { @override String get saveProject => 'Save project'; - @override String get share => 'Share'; diff --git a/pubspec.lock b/pubspec.lock index 386048ce..e600f2c9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1086,7 +1086,7 @@ packages: source: hosted version: "0.27.7" share: - dependency: "direct main" + dependency: transitive description: name: share sha256: "97e6403f564ed1051a01534c2fc919cb6e40ea55e60a18ec23cee6e0ce19f4be" diff --git a/pubspec.yaml b/pubspec.yaml index 080a48dc..5a441042 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -22,7 +22,6 @@ dependencies: shared_preferences: ^2.0.15 freezed_annotation: ^2.4.1 melos: ^3.4.0 - share: ^2.0.4 # Internal packages: component_library: From 09d4042f15718e490381d16df585ed879325a215 Mon Sep 17 00:00:00 2001 From: vishad-tyagi <78733360+vishad-tyagi@users.noreply.github.com> Date: Mon, 11 Mar 2024 16:45:07 +0530 Subject: [PATCH 3/6] Added share_plus package and remove depreciated share package --- ios/Podfile.lock | 10 +++++----- .../src/components/top_bar/overflow_menu.dart | 20 ++++++++----------- .../features/workspace_screen/pubspec.yaml | 2 +- .../l10n/lib/src/l10n/app_localizations.dart | 11 +++++----- pubspec.lock | 16 +++++++++++---- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 4fbcd90b..706a8ab3 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -57,7 +57,7 @@ PODS: - SDWebImage (5.13.1): - SDWebImage/Core (= 5.13.1) - SDWebImage/Core (5.13.1) - - share (0.0.1): + - share_plus (0.0.1): - Flutter - shared_preferences_foundation (0.0.1): - Flutter @@ -80,7 +80,7 @@ DEPENDENCIES: - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) - - share (from `.symlinks/plugins/share/ios`) + - share_plus (from `.symlinks/plugins/share_plus/ios`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) - sqflite (from `.symlinks/plugins/sqflite/ios`) - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) @@ -114,8 +114,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/path_provider_foundation/darwin" permission_handler_apple: :path: ".symlinks/plugins/permission_handler_apple/ios" - share: - :path: ".symlinks/plugins/share/ios" + share_plus: + :path: ".symlinks/plugins/share_plus/ios" shared_preferences_foundation: :path: ".symlinks/plugins/shared_preferences_foundation/darwin" sqflite: @@ -138,7 +138,7 @@ SPEC CHECKSUMS: path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943 permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6 SDWebImage: fb26a455eeda4c7a55e4dcb6172dbb258af7a4ca - share: 0b2c3e82132f5888bccca3351c504d0003b3b410 + share_plus: c3fef564749587fc939ef86ffb283ceac0baf9f5 shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126 sqflite: 31f7eba61e3074736dff8807a9b41581e4f7f15a SwiftyGif: 6c3eafd0ce693cad58bb63d2b2fb9bacb8552780 diff --git a/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart b/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart index 5b1cf602..147b5936 100644 --- a/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart +++ b/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart @@ -7,7 +7,7 @@ import 'package:l10n/l10n.dart'; import 'package:oxidized/oxidized.dart'; import 'package:toast/toast.dart'; import 'package:workspace_screen/workspace_screen.dart'; -import 'package:share/share.dart'; +import 'package:share_plus/share_plus.dart'; enum OverflowMenuOption { fullscreen, @@ -52,11 +52,11 @@ class _OverflowMenuState extends ConsumerState { onSelected: _handleSelectedOption, itemBuilder: (BuildContext context) => OverflowMenuOption.values .map((option) => PopupMenuItem( - value: option, - child: Text( - option.localizedLabel(context), - style: TextThemes.menuItem, - ))) + value: option, + child: Text( + option.localizedLabel(context), + style: TextThemes.menuItem, + ))) .toList(), ); } @@ -121,7 +121,7 @@ class _OverflowMenuState extends ConsumerState { final fileService = ref.watch(IFileService.provider); final fileName = '${imageData.name}.${imageData.format.extension}'; final fileExists = - await fileService.checkIfFileExistsInApplicationDirectory(fileName); + await fileService.checkIfFileExistsInApplicationDirectory(fileName); if (fileExists) { final overWriteCanceled = await _showOverwriteDialog(); @@ -139,14 +139,10 @@ class _OverflowMenuState extends ConsumerState { return true; } - - void _shareContent() { - Share.share('Check out this great app!'); } - Future _saveProject() async { final imageData = await showSaveImageDialog(context, true); @@ -166,7 +162,7 @@ class _OverflowMenuState extends ConsumerState { final savedProject = await ioHandler.saveProject(catrobatImageData); if (savedProject != null) { String? imagePreview = - await ioHandler.getPreviewPath(catrobatImageData); + await ioHandler.getPreviewPath(catrobatImageData); Project projectNew = Project( name: catrobatImageData.name, path: savedProject.path, diff --git a/packages/features/workspace_screen/pubspec.yaml b/packages/features/workspace_screen/pubspec.yaml index 7219ae20..b9575cf0 100644 --- a/packages/features/workspace_screen/pubspec.yaml +++ b/packages/features/workspace_screen/pubspec.yaml @@ -21,7 +21,7 @@ dependencies: toast: ^0.3.0 image: ^3.2.0 oxidized: ^5.2.0 - share: ^2.0.4 + share_plus: ^7.2.2 # Internal packages component_library: diff --git a/packages/l10n/lib/src/l10n/app_localizations.dart b/packages/l10n/lib/src/l10n/app_localizations.dart index a218c5ac..7bd61344 100644 --- a/packages/l10n/lib/src/l10n/app_localizations.dart +++ b/packages/l10n/lib/src/l10n/app_localizations.dart @@ -69,7 +69,7 @@ abstract class AppLocalizations { } static const LocalizationsDelegate delegate = - _AppLocalizationsDelegate(); + _AppLocalizationsDelegate(); /// A list of this localizations delegate along with the default localizations /// delegates. @@ -82,7 +82,7 @@ abstract class AppLocalizations { /// MaterialApp. This list does not have to be used at all if a custom list /// of delegates is preferred or required. static const List> localizationsDelegates = - >[ + >[ delegate, GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate, @@ -146,7 +146,6 @@ abstract class AppLocalizations { /// **'Layers'** String get layers; - String get share; } @@ -176,7 +175,7 @@ AppLocalizations lookupAppLocalizations(Locale locale) { throw FlutterError( 'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely ' - 'an issue with the localizations generation tool. Please file an issue ' - 'on GitHub with a reproducible sample app and the gen-l10n configuration ' - 'that was used.'); + 'an issue with the localizations generation tool. Please file an issue ' + 'on GitHub with a reproducible sample app and the gen-l10n configuration ' + 'that was used.'); } diff --git a/pubspec.lock b/pubspec.lock index e600f2c9..ea22a71c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1085,14 +1085,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.27.7" - share: + share_plus: dependency: transitive description: - name: share - sha256: "97e6403f564ed1051a01534c2fc919cb6e40ea55e60a18ec23cee6e0ce19f4be" + name: share_plus + sha256: "3ef39599b00059db0990ca2e30fca0a29d8b37aae924d60063f8e0184cf20900" url: "https://pub.dev" source: hosted - version: "2.0.4" + version: "7.2.2" + share_plus_platform_interface: + dependency: transitive + description: + name: share_plus_platform_interface + sha256: df08bc3a07d01f5ea47b45d03ffcba1fa9cd5370fb44b3f38c70e42cced0f956 + url: "https://pub.dev" + source: hosted + version: "3.3.1" shared_preferences: dependency: "direct main" description: From 1c89afa33ac7c6e82906448a2ee89209a61fe702 Mon Sep 17 00:00:00 2001 From: vishad-tyagi <78733360+vishad-tyagi@users.noreply.github.com> Date: Mon, 11 Mar 2024 18:51:14 +0530 Subject: [PATCH 4/6] Added tests for native share window. --- .../test/widget/workspace_screen_test.dart | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/features/workspace_screen/test/widget/workspace_screen_test.dart b/packages/features/workspace_screen/test/widget/workspace_screen_test.dart index bd05bca4..6694195b 100644 --- a/packages/features/workspace_screen/test/widget/workspace_screen_test.dart +++ b/packages/features/workspace_screen/test/widget/workspace_screen_test.dart @@ -47,6 +47,25 @@ void main() { expect(overflowMenuButtonFinder, findsOneWidget); }); + testWidgets('Tapping share option maintains UI stability', + (WidgetTester tester) async { + await tester.pumpWidget(sut); + + await tester.tap(find.byIcon(Icons.more_vert)); + await tester.pumpAndSettle(); // Wait for the menu to open + + final initialWidgetTree = tester.widgetList(find.byType(Widget)).toString(); + + final shareOptionFinder = find.text('Share'); + await tester.ensureVisible(shareOptionFinder); + await tester.tap(shareOptionFinder); + await tester.pumpAndSettle(); + + final updatedWidgetTree = tester.widgetList(find.byType(Widget)).toString(); + + expect(updatedWidgetTree, initialWidgetTree); + }); + group('Fullscreen functionality', () { late WorkspaceState testWorkspaceState; late FakeCommandManager fakeCommandManager; From 30d891d6ea74565f31033e36cbfa6d640cb76f5b Mon Sep 17 00:00:00 2001 From: vishad-tyagi <78733360+vishad-tyagi@users.noreply.github.com> Date: Sun, 21 Apr 2024 13:37:13 +0530 Subject: [PATCH 5/6] Removed Comment --- .../workspace_screen/test/widget/workspace_screen_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/features/workspace_screen/test/widget/workspace_screen_test.dart b/packages/features/workspace_screen/test/widget/workspace_screen_test.dart index 6694195b..b666b593 100644 --- a/packages/features/workspace_screen/test/widget/workspace_screen_test.dart +++ b/packages/features/workspace_screen/test/widget/workspace_screen_test.dart @@ -52,7 +52,7 @@ void main() { await tester.pumpWidget(sut); await tester.tap(find.byIcon(Icons.more_vert)); - await tester.pumpAndSettle(); // Wait for the menu to open + await tester.pumpAndSettle(); final initialWidgetTree = tester.widgetList(find.byType(Widget)).toString(); From 4fb115b8c1dd15c2827b839975d17bee58a8873f Mon Sep 17 00:00:00 2001 From: vishad-tyagi <78733360+vishad-tyagi@users.noreply.github.com> Date: Wed, 26 Jun 2024 21:25:46 +0530 Subject: [PATCH 6/6] Completed Shared Option --- .../drawing_surface/drawing_canvas.dart | 22 ++--- .../src/components/top_bar/overflow_menu.dart | 81 ++++++++++++++++--- .../features/workspace_screen/pubspec.yaml | 1 + 3 files changed, 83 insertions(+), 21 deletions(-) diff --git a/packages/features/workspace_screen/lib/src/components/drawing_surface/drawing_canvas.dart b/packages/features/workspace_screen/lib/src/components/drawing_surface/drawing_canvas.dart index 23c5d02e..8b491c76 100644 --- a/packages/features/workspace_screen/lib/src/components/drawing_surface/drawing_canvas.dart +++ b/packages/features/workspace_screen/lib/src/components/drawing_surface/drawing_canvas.dart @@ -14,7 +14,7 @@ class _DrawingCanvasState extends ConsumerState { late final _toolBoxStateNotifier = ref.read(toolBoxStateProvider.notifier); late final _canvasStateNotifier = ref.read(canvasStateProvider.notifier); late final _canvasDirtyNotifier = - ref.read(CanvasDirtyState.provider.notifier); + ref.read(CanvasDirtyState.provider.notifier); final _canvasPainterKey = GlobalKey(debugLabel: 'CanvasPainter'); final _transformationController = TransformationController(); @@ -54,7 +54,7 @@ class _DrawingCanvasState extends ConsumerState { Offset _globalToCanvas(Offset global) { final canvasBox = - _canvasPainterKey.currentContext!.findRenderObject() as RenderBox; + _canvasPainterKey.currentContext!.findRenderObject() as RenderBox; return canvasBox.globalToLocal(global); } @@ -106,7 +106,7 @@ class _DrawingCanvasState extends ConsumerState { Widget build(BuildContext context) { ref.listen( WorkspaceState.provider.select((state) => state.isFullscreen), - (wasFullscreen, isFullscreen) { + (wasFullscreen, isFullscreen) { _resetCanvasScale(fitToScreen: isFullscreen); }, ); @@ -121,19 +121,19 @@ class _DrawingCanvasState extends ConsumerState { boundaryMargin: const EdgeInsets.all(double.infinity), interactionEndFrictionCoefficient: double.minPositive, panEnabled: - ref.watch(toolBoxStateProvider).currentTool.type == ToolType.HAND, + ref.watch(toolBoxStateProvider).currentTool.type == ToolType.HAND, onInteractionStart: _onInteractionStart, onInteractionUpdate: _onInteractionUpdate, onInteractionEnd: _onInteractionEnd, child: Center( child: ref.watch(IDeviceService.sizeProvider).map( - data: (_) => FittedBox( - fit: BoxFit.contain, - child: CanvasPainter(key: _canvasPainterKey), - ), - error: (_) => Container(), - loading: (_) => Container(), - ), + data: (_) => FittedBox( + fit: BoxFit.contain, + child: CanvasPainter(key: _canvasPainterKey), + ), + error: (_) => Container(), + loading: (_) => Container(), + ), ), ), ); diff --git a/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart b/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart index 147b5936..f72cdbf0 100644 --- a/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart +++ b/packages/features/workspace_screen/lib/src/components/top_bar/overflow_menu.dart @@ -1,3 +1,5 @@ +import 'dart:ui' as ui; +import 'package:command/command_providers.dart'; import 'package:component_library/component_library.dart'; import 'package:database/database.dart'; import 'package:flutter/material.dart'; @@ -8,6 +10,9 @@ import 'package:oxidized/oxidized.dart'; import 'package:toast/toast.dart'; import 'package:workspace_screen/workspace_screen.dart'; import 'package:share_plus/share_plus.dart'; +import 'package:path_provider/path_provider.dart'; +import 'dart:io'; + enum OverflowMenuOption { fullscreen, @@ -52,11 +57,11 @@ class _OverflowMenuState extends ConsumerState { onSelected: _handleSelectedOption, itemBuilder: (BuildContext context) => OverflowMenuOption.values .map((option) => PopupMenuItem( - value: option, - child: Text( - option.localizedLabel(context), - style: TextThemes.menuItem, - ))) + value: option, + child: Text( + option.localizedLabel(context), + style: TextThemes.menuItem, + ))) .toList(), ); } @@ -80,7 +85,7 @@ class _OverflowMenuState extends ConsumerState { ioHandler.newImage(context, this); break; case OverflowMenuOption.share: - _shareContent(); + _shareContent(context); // Pass context to share content break; } } @@ -121,7 +126,7 @@ class _OverflowMenuState extends ConsumerState { final fileService = ref.watch(IFileService.provider); final fileName = '${imageData.name}.${imageData.format.extension}'; final fileExists = - await fileService.checkIfFileExistsInApplicationDirectory(fileName); + await fileService.checkIfFileExistsInApplicationDirectory(fileName); if (fileExists) { final overWriteCanceled = await _showOverwriteDialog(); @@ -139,8 +144,64 @@ class _OverflowMenuState extends ConsumerState { return true; } - void _shareContent() { - Share.share('Check out this great app!'); + Future _shareContent(BuildContext context) async { // Added method + try { + final img = await _captureCanvasImage(context); // Use _captureCanvasImage + final byteData = await img.toByteData(format: ui.ImageByteFormat.png); + final pngBytes = byteData?.buffer.asUint8List(); + + if (pngBytes != null) { + final tempDir = await getTemporaryDirectory(); + final file = await File('${tempDir.path}/shared_image.png').create(); + await file.writeAsBytes(pngBytes); + + Share.shareXFiles([XFile(file.path)]); // Updated method + } else { + Toast.show( + 'Failed to capture image from canvas.', + duration: Toast.lengthShort, + gravity: Toast.bottom, + ); + } + } catch (e) { + Toast.show( + 'Error sharing content: $e', + duration: Toast.lengthShort, + gravity: Toast.bottom, + ); + } + } + + Future _captureCanvasImage(BuildContext context) async { // Added method to capture canvas image + final canvasState = ref.read(canvasStateProvider); + final commands = ref.read(commandManagerProvider); + final recorder = ui.PictureRecorder(); + final canvas = Canvas(recorder); + + final size = canvasState.size; + if (canvasState.backgroundImage != null) { + paintImage( + canvas: canvas, + rect: Offset.zero & size, + image: canvasState.backgroundImage!, + fit: BoxFit.cover, + ); + } + + if (canvasState.cachedImage != null) { + paintImage( + canvas: canvas, + rect: Offset.zero & size, + image: canvasState.cachedImage!, + fit: BoxFit.cover, + ); + } + + commands.executeAllCommands(canvas); + + final picture = recorder.endRecording(); + final img = await picture.toImage(size.width.toInt(), size.height.toInt()); + return img; } Future _saveProject() async { @@ -162,7 +223,7 @@ class _OverflowMenuState extends ConsumerState { final savedProject = await ioHandler.saveProject(catrobatImageData); if (savedProject != null) { String? imagePreview = - await ioHandler.getPreviewPath(catrobatImageData); + await ioHandler.getPreviewPath(catrobatImageData); Project projectNew = Project( name: catrobatImageData.name, path: savedProject.path, diff --git a/packages/features/workspace_screen/pubspec.yaml b/packages/features/workspace_screen/pubspec.yaml index b9575cf0..4345e918 100644 --- a/packages/features/workspace_screen/pubspec.yaml +++ b/packages/features/workspace_screen/pubspec.yaml @@ -22,6 +22,7 @@ dependencies: image: ^3.2.0 oxidized: ^5.2.0 share_plus: ^7.2.2 + path_provider: ^2.1.3 # Internal packages component_library: