From 048e347e431441c3da1c5d83f17dd2079fa0a5ee Mon Sep 17 00:00:00 2001 From: shilangyu Date: Sat, 20 Mar 2021 15:50:49 +0100 Subject: [PATCH] Remove class acting as a namespace --- lib/pages/community.dart | 2 +- lib/pages/full_post.dart | 2 +- lib/pages/instance.dart | 2 +- lib/pages/media_view.dart | 6 +++--- lib/pages/user.dart | 2 +- lib/util/share.dart | 40 +++++++++++++++++++-------------------- lib/widgets/comment.dart | 4 ++-- lib/widgets/post.dart | 3 +-- 8 files changed, 29 insertions(+), 32 deletions(-) diff --git a/lib/pages/community.dart b/lib/pages/community.dart index ac984da..781fa85 100644 --- a/lib/pages/community.dart +++ b/lib/pages/community.dart @@ -108,7 +108,7 @@ class CommunityPage extends HookWidget { } // FUNCTIONS - void _share() => Share.share(community.community.actorId, context: context); + void _share() => share(community.community.actorId, context: context); void _openMoreMenu() { showBottomModal( diff --git a/lib/pages/full_post.dart b/lib/pages/full_post.dart index cacce5f..2e1b847 100644 --- a/lib/pages/full_post.dart +++ b/lib/pages/full_post.dart @@ -84,7 +84,7 @@ class FullPostPage extends HookWidget { } } - sharePost() => Share.share(post.post.apId, context: context); + sharePost() => share(post.post.apId, context: context); comment() async { final newComment = await showCupertinoModalPopup( diff --git a/lib/pages/instance.dart b/lib/pages/instance.dart index 8a81b36..f35d11a 100644 --- a/lib/pages/instance.dart +++ b/lib/pages/instance.dart @@ -67,7 +67,7 @@ class InstancePage extends HookWidget { final site = siteSnap.data; - void _share() => Share.share('https://$instanceHost', context: context); + void _share() => share('https://$instanceHost', context: context); void _openMoreMenu(BuildContext c) { showBottomModal( diff --git a/lib/pages/media_view.dart b/lib/pages/media_view.dart index ac6d484..be9512e 100644 --- a/lib/pages/media_view.dart +++ b/lib/pages/media_view.dart @@ -35,7 +35,7 @@ class MediaViewPage extends HookWidget { // TODO: hide navbar and topbar on android without a content jump - share() { + sharePhoto() { showBottomModal( context: context, builder: (context) => Column( @@ -45,7 +45,7 @@ class MediaViewPage extends HookWidget { title: const Text('Share link'), onTap: () { Navigator.of(context).pop(); - Share.share(url, context: context); + share(url, context: context); }, ), ListTile( @@ -77,7 +77,7 @@ class MediaViewPage extends HookWidget { IconButton( icon: const Icon(Icons.share), tooltip: 'share', - onPressed: share, + onPressed: sharePhoto, ), IconButton( icon: const Icon(Icons.file_download), diff --git a/lib/pages/user.dart b/lib/pages/user.dart index 535c17c..e871546 100644 --- a/lib/pages/user.dart +++ b/lib/pages/user.dart @@ -49,7 +49,7 @@ class UserPage extends HookWidget { SendMessageButton(userDetailsSnap.data.userView.user), IconButton( icon: const Icon(Icons.share), - onPressed: () => Share.share( + onPressed: () => share( userDetailsSnap.data.userView.user.actorId, context: context, ), diff --git a/lib/util/share.dart b/lib/util/share.dart index eb1c765..4813fb7 100644 --- a/lib/util/share.dart +++ b/lib/util/share.dart @@ -1,29 +1,27 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:share/share.dart' as flutter_share; +import 'package:share/share.dart'; /// A `package:share` wrapper that fallbacks to copying contents to the clipboard /// on platforms that do not support native sharing -abstract class Share { - static Future share( - String text, { - String subject, - Rect sharePositionOrigin, - @required BuildContext context, - }) async { - assert(context != null); +Future share( + String text, { + String subject, + Rect sharePositionOrigin, + @required BuildContext context, +}) async { + assert(context != null); - try { - return await flutter_share.Share.share( - text, - subject: subject, - sharePositionOrigin: sharePositionOrigin, - ); - } on MissingPluginException { - await Clipboard.setData(ClipboardData(text: text)); - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Copied data to clipboard!')), - ); - } + try { + return await Share.share( + text, + subject: subject, + sharePositionOrigin: sharePositionOrigin, + ); + } on MissingPluginException { + await Clipboard.setData(ClipboardData(text: text)); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Copied data to clipboard!')), + ); } } diff --git a/lib/widgets/comment.dart b/lib/widgets/comment.dart index 299fda3..9ff96b7 100644 --- a/lib/widgets/comment.dart +++ b/lib/widgets/comment.dart @@ -149,12 +149,12 @@ class CommentWidget extends HookWidget { ListTile( leading: const Icon(Icons.share), title: const Text('Share url'), - onTap: () => Share.share(com.comment.link, context: context), + onTap: () => share(com.comment.link, context: context), ), ListTile( leading: const Icon(Icons.share), title: const Text('Share text'), - onTap: () => Share.share(com.comment.content, context: context), + onTap: () => share(com.comment.content, context: context), ), ListTile( leading: diff --git a/lib/widgets/post.dart b/lib/widgets/post.dart index 96c3387..d06c129 100644 --- a/lib/widgets/post.dart +++ b/lib/widgets/post.dart @@ -384,8 +384,7 @@ class PostWidget extends HookWidget { if (!fullPost) IconButton( icon: const Icon(Icons.share), - onPressed: () => - Share.share(post.post.apId, context: context), + onPressed: () => share(post.post.apId, context: context), ), if (!fullPost) SavePostButton(post), _Voting(post),