fix: Sharing on iPad

This commit is contained in:
Christian Pauly 2022-08-21 08:42:02 +02:00
parent 1eba0e5dbe
commit 67f5a76f16
8 changed files with 30 additions and 19 deletions

View File

@ -108,7 +108,7 @@ class ChatController extends State<Chat> {
MessageTypes.File,
}.contains(selectedEvents.single.messageType);
void saveSelectedEvent() => selectedEvents.single.saveFile(context);
void saveSelectedEvent(context) => selectedEvents.single.saveFile(context);
List<Event> selectedEvents = [];

View File

@ -46,11 +46,13 @@ class ChatView extends StatelessWidget {
onPressed: controller.copyEventsAction,
),
if (controller.canSaveSelectedEvent)
IconButton(
icon: Icon(Icons.adaptive.share),
tooltip: L10n.of(context)!.share,
onPressed: controller.saveSelectedEvent,
),
// Use builder context to correctly position the share dialog on iPad
Builder(
builder: (context) => IconButton(
icon: Icon(Icons.adaptive.share),
tooltip: L10n.of(context)!.share,
onPressed: () => controller.saveSelectedEvent(context),
)),
if (controller.canRedactSelectedEvents)
IconButton(
icon: const Icon(Icons.delete_outlined),

View File

@ -18,6 +18,8 @@ class HomeserverPickerView extends StatelessWidget {
final benchmarkResults = controller.benchmarkResults;
return LoginScaffold(
appBar: AppBar(
elevation: 0,
scrolledUnderElevation: 0,
backgroundColor: Colors.transparent,
actions: [
IconButton(

View File

@ -25,10 +25,10 @@ class ImageViewerController extends State<ImageViewer> {
}
/// Save this file with a system call.
void saveFileAction() => widget.event.saveFile(context);
void saveFileAction(BuildContext context) => widget.event.saveFile(context);
/// Save this file with a system call.
void shareFileAction() => widget.event.shareFile(context);
void shareFileAction(BuildContext context) => widget.event.shareFile(context);
static const maxScaleFactor = 1.5;

View File

@ -35,17 +35,19 @@ class ImageViewerView extends StatelessWidget {
if (!PlatformInfos.isIOS)
IconButton(
icon: const Icon(Icons.download_outlined),
onPressed: controller.saveFileAction,
onPressed: () => controller.saveFileAction(context),
color: Colors.white,
tooltip: L10n.of(context)!.downloadFile,
),
if (PlatformInfos.isMobile)
IconButton(
onPressed: controller.shareFileAction,
tooltip: L10n.of(context)!.share,
color: Colors.white,
icon: Icon(Icons.adaptive.share_outlined),
)
// Use builder context to correctly position the share dialog on iPad
Builder(
builder: (context) => IconButton(
onPressed: () => controller.shareFileAction(context),
tooltip: L10n.of(context)!.share,
color: Colors.white,
icon: Icon(Icons.adaptive.share_outlined),
))
],
),
body: InteractiveViewer(

View File

@ -26,10 +26,15 @@ extension MatrixFileExtension on MatrixFile {
final tmpDirectory = await getTemporaryDirectory();
final path = '${tmpDirectory.path}$fileName';
await File(path).writeAsBytes(bytes);
final box = context.findRenderObject() as RenderBox;
// Workaround for iPad from
// https://github.com/fluttercommunity/plus_plugins/tree/main/packages/share_plus/share_plus#ipad
final box = context.findRenderObject() as RenderBox?;
await Share.shareFiles(
[path],
sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size,
sharePositionOrigin:
box == null ? null : box.localToGlobal(Offset.zero) & box.size,
);
return;
}

View File

@ -1506,7 +1506,7 @@ packages:
name: share_plus
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.9"
version: "4.0.10+1"
share_plus_linux:
dependency: transitive
description:

View File

@ -78,7 +78,7 @@ dependencies:
receive_sharing_intent: ^1.4.5
record: ^4.3.2
scroll_to_index: ^3.0.1
share_plus: ^4.0.9
share_plus: ^4.0.10+1
shared_preferences: ^2.0.13
slugify: ^2.0.0
swipe_to_action: ^0.2.0