fluffychat/lib/views/image_view.dart

74 lines
2.2 KiB
Dart
Raw Normal View History

2021-01-16 12:46:38 +01:00
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
2020-05-16 08:02:33 +02:00
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/image_bubble.dart';
import 'package:fluffychat/components/matrix.dart';
import 'package:flutter/material.dart';
import '../utils/event_extension.dart';
import '../utils/platform_infos.dart';
2020-05-16 08:02:33 +02:00
class ImageView extends StatelessWidget {
final Event event;
final void Function() onLoaded;
2020-05-16 08:02:33 +02:00
const ImageView(this.event, {Key key, this.onLoaded}) : super(key: key);
2020-05-16 08:02:33 +02:00
void _forwardAction(BuildContext context) async {
Matrix.of(context).shareContent = event.content;
2021-01-16 12:46:38 +01:00
AdaptivePageLayout.of(context).popUntilIsFirst();
2020-05-16 08:02:33 +02:00
}
@override
Widget build(BuildContext context) {
var calcVelocity = MediaQuery.of(context).size.height * 1.50;
2020-05-16 08:02:33 +02:00
return Scaffold(
backgroundColor: Colors.black,
2020-05-20 19:29:26 +02:00
extendBodyBehindAppBar: true,
2020-05-16 08:02:33 +02:00
appBar: AppBar(
2020-05-20 19:29:26 +02:00
elevation: 0,
2020-05-16 08:02:33 +02:00
leading: IconButton(
icon: Icon(Icons.close),
onPressed: () => Navigator.of(context).pop(),
color: Colors.white,
),
2020-05-20 19:29:26 +02:00
backgroundColor: Color(0x44000000),
2020-05-16 08:02:33 +02:00
actions: [
IconButton(
2020-12-06 10:31:35 +01:00
icon: Icon(Icons.reply_outlined),
2020-05-16 08:02:33 +02:00
onPressed: () => _forwardAction(context),
color: Colors.white,
),
IconButton(
2020-12-06 10:31:35 +01:00
icon: Icon(Icons.download_outlined),
2020-09-03 12:58:54 +02:00
onPressed: () => event.openFile(context, downloadOnly: true),
2020-05-16 08:02:33 +02:00
color: Colors.white,
),
],
),
body: InteractiveViewer(
child: Center(
child: ImageBubble(
event,
tapToView: false,
onLoaded: onLoaded,
fit: BoxFit.contain,
backgroundColor: Colors.black,
maxSize: false,
radius: 0.0,
thumbnailOnly: false,
),
),
2020-05-16 09:12:57 +02:00
minScale: 1.0,
2020-05-16 09:13:37 +02:00
maxScale: 10.0,
onInteractionEnd: (ScaleEndDetails endDetails) {
if (PlatformInfos.usesTouchscreen == false) {
if (endDetails.velocity.pixelsPerSecond.dy > calcVelocity) {
Navigator.of(context).pop();
}
}
},
2020-05-16 08:02:33 +02:00
),
);
}
}