2021-04-10 09:06:24 +02:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
2021-05-22 09:08:23 +02:00
|
|
|
import 'package:fluffychat/pages/views/image_viewer_view.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
2021-04-10 09:06:24 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-05-23 13:11:55 +02:00
|
|
|
import 'package:vrouter/vrouter.dart';
|
2021-04-10 09:06:24 +02:00
|
|
|
|
2021-05-22 09:24:39 +02:00
|
|
|
import '../utils/matrix_sdk_extensions.dart/event_extension.dart';
|
2021-04-10 09:06:24 +02:00
|
|
|
|
|
|
|
class ImageViewer extends StatefulWidget {
|
|
|
|
final void Function() onLoaded;
|
|
|
|
|
2021-05-25 15:35:14 +02:00
|
|
|
const ImageViewer({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 15:35:14 +02:00
|
|
|
void forwardAction(Event event) {
|
|
|
|
Matrix.of(context).shareContent = event.content;
|
2021-05-23 13:11:55 +02:00
|
|
|
VRouter.of(context).push('/rooms');
|
2021-04-10 09:06:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Open this file with a system call.
|
2021-05-25 15:35:14 +02:00
|
|
|
void openFileAction(Event event) =>
|
|
|
|
event.openFile(context, downloadOnly: true);
|
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 >
|
|
|
|
MediaQuery.of(context).size.height * 1.50) {
|
|
|
|
Navigator.of(context, rootNavigator: false).pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-25 15:35:14 +02:00
|
|
|
Future<Event> getEvent() {
|
|
|
|
final roomId = VRouter.of(context).pathParameters['roomid'];
|
|
|
|
final eventId = VRouter.of(context).pathParameters['eventid'];
|
|
|
|
return Matrix.of(context).client.database.getEventById(
|
|
|
|
Matrix.of(context).client.id,
|
|
|
|
eventId,
|
|
|
|
Matrix.of(context).client.getRoomById(roomId),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-10 09:06:24 +02:00
|
|
|
@override
|
2021-05-22 09:13:47 +02:00
|
|
|
Widget build(BuildContext context) => ImageViewerView(this);
|
2021-04-10 09:06:24 +02:00
|
|
|
}
|