Remove class acting as a namespace

This commit is contained in:
shilangyu 2021-03-20 15:50:49 +01:00
parent 5db7a8e509
commit 048e347e43
8 changed files with 29 additions and 32 deletions

View File

@ -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(

View File

@ -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<CommentView>(

View File

@ -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(

View File

@ -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),

View File

@ -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,
),

View File

@ -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<void> share(
String text, {
String subject,
Rect sharePositionOrigin,
@required BuildContext context,
}) async {
assert(context != null);
Future<void> 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!')),
);
}
}

View File

@ -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:

View File

@ -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),