fluffychat/lib/pages/image_viewer/image_viewer.dart

46 lines
1.4 KiB
Dart
Raw Normal View History

2021-04-10 09:06:24 +02:00
import 'package:flutter/material.dart';
2021-10-26 18:50:34 +02:00
import 'package:matrix/matrix.dart';
2021-05-23 13:11:55 +02:00
import 'package:vrouter/vrouter.dart';
2021-04-10 09:06:24 +02:00
2021-11-09 21:32:16 +01:00
import 'package:fluffychat/pages/image_viewer/image_viewer_view.dart';
2021-10-26 18:50:34 +02:00
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/matrix.dart';
2021-11-09 21:32:16 +01:00
import '../../utils/matrix_sdk_extensions.dart/event_extension.dart';
2021-04-10 09:06:24 +02:00
class ImageViewer extends StatefulWidget {
2021-05-25 20:41:37 +02:00
final Event event;
2022-01-29 12:35:03 +01:00
final void Function()? onLoaded;
2021-04-10 09:06:24 +02:00
2022-01-29 12:35:03 +01:00
const ImageViewer(this.event, {Key? key, this.onLoaded}) : super(key: key);
2021-04-10 09:06:24 +02:00
@override
ImageViewerController createState() => ImageViewerController();
}
class ImageViewerController extends State<ImageViewer> {
/// Forward this image to another room.
2021-05-25 20:41:37 +02:00
void forwardAction() {
Matrix.of(context).shareContent = widget.event.content;
2021-07-08 17:10:20 +02:00
VRouter.of(context).to('/rooms');
2021-04-10 09:06:24 +02:00
}
2021-07-11 17:12:56 +02:00
/// Save this file with a system call.
void saveFileAction() => widget.event.saveFile(context);
2021-04-10 09:06:24 +02:00
2021-10-26 18:47:05 +02:00
static const maxScaleFactor = 1.5;
2021-04-10 09:06:24 +02:00
/// Go back if user swiped it away
void onInteractionEnds(ScaleEndDetails endDetails) {
if (PlatformInfos.usesTouchscreen == false) {
if (endDetails.velocity.pixelsPerSecond.dy >
2021-10-26 18:47:05 +02:00
MediaQuery.of(context).size.height * maxScaleFactor) {
2021-04-10 09:06:24 +02:00
Navigator.of(context, rootNavigator: false).pop();
}
}
}
@override
2021-05-22 09:13:47 +02:00
Widget build(BuildContext context) => ImageViewerView(this);
2021-04-10 09:06:24 +02:00
}