lemmur-app-android/lib/widgets/media_view.dart

114 lines
3.4 KiB
Dart
Raw Normal View History

2020-09-10 23:03:50 +02:00
import 'package:cached_network_image/cached_network_image.dart';
import 'package:esys_flutter_share/esys_flutter_share.dart';
2020-09-10 23:03:50 +02:00
import 'package:flutter/material.dart';
2020-09-11 10:54:03 +02:00
import 'package:flutter/services.dart';
2020-09-10 23:03:50 +02:00
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:photo_view/photo_view.dart';
import 'bottom_modal.dart';
2020-09-10 23:03:50 +02:00
class MediaView extends HookWidget {
final String url;
const MediaView(this.url);
@override
Widget build(BuildContext context) {
final showButtons = useState(true);
final isZoomedOut = useState(true);
2020-09-10 23:03:50 +02:00
2020-09-11 10:54:03 +02:00
useEffect(() => () => SystemChrome.setEnabledSystemUIOverlays([
SystemUiOverlay.bottom,
SystemUiOverlay.top,
]));
if (showButtons.value) {
SystemChrome.setEnabledSystemUIOverlays([
SystemUiOverlay.bottom,
SystemUiOverlay.top,
]);
} else {
SystemChrome.setEnabledSystemUIOverlays([]);
}
share() {
showModalBottomSheet(
backgroundColor: Colors.transparent,
context: context,
builder: (context) => BottomModal(
child: Column(
children: [
ListTile(
leading: Icon(Icons.link),
title: Text('Share link'),
onTap: () {
Navigator.of(context).pop();
Share.text('Share image url', url, 'text/plain');
},
),
ListTile(
leading: Icon(Icons.image),
title: Text('Share file'),
onTap: () {
Navigator.of(context).pop();
// TODO: share file
},
),
],
),
),
);
}
2020-09-10 23:03:50 +02:00
return Scaffold(
extendBodyBehindAppBar: true,
extendBody: true,
2020-09-11 11:00:04 +02:00
appBar: showButtons.value
? AppBar(
backgroundColor: Colors.black38,
shadowColor: Colors.transparent,
leading: CloseButton(),
actions: [
2020-09-10 23:03:50 +02:00
IconButton(
icon: Icon(Icons.share),
tooltip: 'share',
onPressed: share,
2020-09-10 23:03:50 +02:00
),
IconButton(
icon: Icon(Icons.file_download),
tooltip: 'download',
onPressed: () {},
),
2020-09-11 11:00:04 +02:00
],
)
: null,
body: Dismissible(
direction: DismissDirection.vertical,
onDismissed: (_) => Navigator.of(context).pop(),
key: const Key('media view'),
background: Container(color: Colors.black),
dismissThresholds: {
DismissDirection.vertical: 0,
},
confirmDismiss: (direction) => Future.value(isZoomedOut.value),
resizeDuration: null,
child: GestureDetector(
onTapUp: (details) => showButtons.value = !showButtons.value,
child: PhotoView(
scaleStateChangedCallback: (value) {
isZoomedOut.value = value == PhotoViewScaleState.zoomedOut ||
value == PhotoViewScaleState.initial;
},
minScale: PhotoViewComputedScale.contained,
initialScale: PhotoViewComputedScale.contained,
imageProvider: CachedNetworkImageProvider(url),
heroAttributes: PhotoViewHeroAttributes(tag: url),
loadingBuilder: (context, event) =>
Center(child: CircularProgressIndicator()),
),
2020-09-10 23:03:50 +02:00
),
),
);
}
}