2020-09-10 23:03:50 +02:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2020-09-11 11:24:06 +02:00
|
|
|
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';
|
|
|
|
|
2020-09-11 19:20:00 +02:00
|
|
|
import '../widgets/bottom_modal.dart';
|
2020-09-11 11:24:06 +02:00
|
|
|
|
2020-09-30 19:05:00 +02:00
|
|
|
/// View to interact with a media object. Zoom in/out, download, share, etc.
|
2020-09-11 19:20:00 +02:00
|
|
|
class MediaViewPage extends HookWidget {
|
2020-09-10 23:03:50 +02:00
|
|
|
final String url;
|
2020-10-06 22:37:24 +02:00
|
|
|
final GlobalKey<ScaffoldState> _key = GlobalKey();
|
2020-09-10 23:03:50 +02:00
|
|
|
|
2020-10-06 22:37:24 +02:00
|
|
|
MediaViewPage(this.url);
|
2020-09-10 23:03:50 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-11 15:56:22 +02:00
|
|
|
final showButtons = useState(true);
|
|
|
|
final isZoomedOut = useState(true);
|
2020-09-10 23:03:50 +02:00
|
|
|
|
2020-10-06 22:37:24 +02:00
|
|
|
notImplemented() {
|
|
|
|
_key.currentState.showSnackBar(SnackBar(
|
|
|
|
content: Text("this feature hasn't been implemented yet 😰")));
|
|
|
|
}
|
|
|
|
|
2020-09-13 16:48:40 +02:00
|
|
|
useEffect(() {
|
|
|
|
if (showButtons.value) {
|
|
|
|
SystemChrome.setEnabledSystemUIOverlays([
|
2020-09-11 10:54:03 +02:00
|
|
|
SystemUiOverlay.bottom,
|
|
|
|
SystemUiOverlay.top,
|
2020-09-13 16:48:40 +02:00
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
SystemChrome.setEnabledSystemUIOverlays([]);
|
|
|
|
}
|
2020-09-13 21:15:20 +02:00
|
|
|
return null;
|
2020-09-13 18:16:53 +02:00
|
|
|
}, [showButtons.value]);
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
() => () => SystemChrome.setEnabledSystemUIOverlays([
|
|
|
|
SystemUiOverlay.bottom,
|
|
|
|
SystemUiOverlay.top,
|
|
|
|
]),
|
|
|
|
[]);
|
2020-09-11 10:54:03 +02:00
|
|
|
|
2020-09-11 11:24:06 +02:00
|
|
|
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();
|
2020-10-06 22:37:24 +02:00
|
|
|
notImplemented();
|
2020-09-11 11:24:06 +02:00
|
|
|
// TODO: share file
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-10 23:03:50 +02:00
|
|
|
return Scaffold(
|
2020-10-06 22:37:24 +02:00
|
|
|
key: _key,
|
2020-09-11 15:56:22 +02:00
|
|
|
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',
|
2020-09-11 11:24:06 +02:00
|
|
|
onPressed: share,
|
2020-09-10 23:03:50 +02:00
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.file_download),
|
|
|
|
tooltip: 'download',
|
2020-10-06 22:37:24 +02:00
|
|
|
onPressed: notImplemented,
|
2020-09-10 23:03:50 +02:00
|
|
|
),
|
2020-09-11 11:00:04 +02:00
|
|
|
],
|
|
|
|
)
|
|
|
|
: null,
|
2020-09-15 16:03:52 +02:00
|
|
|
body: GestureDetector(
|
|
|
|
onTapUp: (details) => showButtons.value = !showButtons.value,
|
|
|
|
onVerticalDragEnd: isZoomedOut.value
|
|
|
|
? (details) {
|
|
|
|
if (details.primaryVelocity.abs() > 1000) {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
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
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|