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