diff --git a/lib/utilities/dialogs/cannot_share_empty_note_dialog.dart b/lib/utilities/dialogs/cannot_share_empty_note_dialog.dart new file mode 100644 index 0000000..976448a --- /dev/null +++ b/lib/utilities/dialogs/cannot_share_empty_note_dialog.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; +import 'package:mynotes/utilities/dialogs/generic_dialog.dart'; + +Future showCannotShareEmptyNoteDialog(BuildContext context) { + return showGenericDialog( + context: context, + title: 'Sharing', + content: 'You cannot share an empty note!', + optionsBuilder: () => { + 'OK': null, + }, + ); +} diff --git a/lib/views/notes/create_update_note_view.dart b/lib/views/notes/create_update_note_view.dart index 2bd6f36..3ce74f5 100644 --- a/lib/views/notes/create_update_note_view.dart +++ b/lib/views/notes/create_update_note_view.dart @@ -1,9 +1,11 @@ import 'package:flutter/material.dart'; import 'package:mynotes/services/auth/auth_service.dart'; +import 'package:mynotes/utilities/dialogs/cannot_share_empty_note_dialog.dart'; import 'package:mynotes/utilities/generics/get_arguments.dart'; import 'package:mynotes/services/cloud/cloud_note.dart'; import 'package:mynotes/services/cloud/cloud_storage_exceptions.dart'; import 'package:mynotes/services/cloud/firebase_cloud_storage.dart'; +import 'package:share_plus/share_plus.dart'; class CreateUpdateNoteView extends StatefulWidget { const CreateUpdateNoteView({Key? key}) : super(key: key); @@ -92,6 +94,19 @@ class _CreateUpdateNoteViewState extends State { return Scaffold( appBar: AppBar( title: const Text('New Note'), + actions: [ + IconButton( + onPressed: () async { + final text = _textController.text; + if (_note == null || text.isEmpty) { + await showCannotShareEmptyNoteDialog(context); + } else { + Share.share(text); + } + }, + icon: const Icon(Icons.share), + ), + ], ), body: FutureBuilder( future: createOrGetExistingNote(context), diff --git a/pubspec.lock b/pubspec.lock index 4802b54..47b5bef 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -422,6 +422,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + share_plus: + dependency: "direct main" + description: + name: share_plus + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.4" + share_plus_linux: + dependency: transitive + description: + name: share_plus_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.4" + share_plus_macos: + dependency: transitive + description: + name: share_plus_macos + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + share_plus_platform_interface: + dependency: transitive + description: + name: share_plus_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + share_plus_web: + dependency: transitive + description: + name: share_plus_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.4" + share_plus_windows: + dependency: transitive + description: + name: share_plus_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.3" shelf: dependency: transitive description: @@ -553,6 +595,62 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" + url_launcher: + dependency: transitive + description: + name: url_launcher + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.17" + url_launcher_android: + dependency: transitive + description: + name: url_launcher_android + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.13" + url_launcher_ios: + dependency: transitive + description: + name: url_launcher_ios + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.13" + url_launcher_linux: + dependency: transitive + description: + name: url_launcher_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + url_launcher_macos: + dependency: transitive + description: + name: url_launcher_macos + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + url_launcher_platform_interface: + dependency: transitive + description: + name: url_launcher_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.4" + url_launcher_web: + dependency: transitive + description: + name: url_launcher_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 02869a7..1c327e2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,6 +41,7 @@ dependencies: sqflite: ^2.0.1 path_provider: ^2.0.8 path: ^1.8.0 + share_plus: ^3.0.4 dev_dependencies: flutter_test: