fix: Image viewer routing

This commit is contained in:
Christian Pauly 2021-06-06 10:09:13 +02:00
parent 2b83e69c1f
commit 7d6cbeec26
3 changed files with 17 additions and 28 deletions

View File

@ -25,7 +25,7 @@ class ImageViewerController extends State<ImageViewer> {
} }
/// Open this file with a system call. /// Open this file with a system call.
void openFileAction() => widget.event.openFile(context, downloadOnly: true); void openFileAction() => widget.event.openFile(context);
/// Go back if user swiped it away /// Go back if user swiped it away
void onInteractionEnds(ScaleEndDetails endDetails) { void onInteractionEnds(ScaleEndDetails endDetails) {

View File

@ -4,18 +4,9 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart'; import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'matrix_file_extension.dart'; import 'matrix_file_extension.dart';
import '../../pages/image_viewer.dart';
import '../../widgets/matrix.dart';
extension LocalizedBody on Event { extension LocalizedBody on Event {
void openFile(BuildContext context, {bool downloadOnly = false}) async { void openFile(BuildContext context) async {
if (!downloadOnly &&
[MessageTypes.Image, MessageTypes.Sticker].contains(messageType)) {
await Navigator.of(Matrix.of(context).navigatorContext).push(
MaterialPageRoute(builder: (_) => ImageViewer(this)),
);
return;
}
final matrixFile = await showFutureLoadingDialog( final matrixFile = await showFutureLoadingDialog(
context: context, context: context,
future: () => downloadAndDecryptAttachmentCached(), future: () => downloadAndDecryptAttachmentCached(),

View File

@ -7,7 +7,6 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import '../../utils/matrix_sdk_extensions.dart/event_extension.dart'; import '../../utils/matrix_sdk_extensions.dart/event_extension.dart';
import '../matrix.dart';
class ImageBubble extends StatefulWidget { class ImageBubble extends StatefulWidget {
final Event event; final Event event;
@ -238,22 +237,21 @@ class _ImageBubbleState extends State<ImageBubble> {
child: InkWell( child: InkWell(
onTap: () { onTap: () {
if (!widget.tapToView) return; if (!widget.tapToView) return;
Navigator.of(Matrix.of(context).navigatorContext).push( showDialog(
MaterialPageRoute( context: context,
builder: (_) => ImageViewer(widget.event, onLoaded: () { builder: (_) => ImageViewer(widget.event, onLoaded: () {
// If the original file didn't load yet, we want to do that now. // If the original file didn't load yet, we want to do that now.
// This is so that the original file displays after going on the image viewer, // This is so that the original file displays after going on the image viewer,
// waiting for it to load, and then hitting back. This ensures that we always // waiting for it to load, and then hitting back. This ensures that we always
// display the best image available, with requiring as little network as possible // display the best image available, with requiring as little network as possible
if (_file == null) { if (_file == null) {
widget.event.isAttachmentCached().then((cached) { widget.event.isAttachmentCached().then((cached) {
if (cached) { if (cached) {
_requestFile(); _requestFile();
} }
}); });
} }
}), }),
),
); );
}, },
child: Hero( child: Hero(