From e4e7f1d9a1768202297ac86b6602bb24b443a309 Mon Sep 17 00:00:00 2001 From: krawieck Date: Fri, 11 Sep 2020 15:56:22 +0200 Subject: [PATCH] add dismiss handling. not perfect and prolly not final --- lib/widgets/media_view.dart | 39 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/lib/widgets/media_view.dart b/lib/widgets/media_view.dart index 96d91c2..ccc0b19 100644 --- a/lib/widgets/media_view.dart +++ b/lib/widgets/media_view.dart @@ -14,7 +14,8 @@ class MediaView extends HookWidget { @override Widget build(BuildContext context) { - var showButtons = useState(true); + final showButtons = useState(true); + final isZoomedOut = useState(true); useEffect(() => () => SystemChrome.setEnabledSystemUIOverlays([ SystemUiOverlay.bottom, @@ -60,6 +61,8 @@ class MediaView extends HookWidget { } return Scaffold( + extendBodyBehindAppBar: true, + extendBody: true, appBar: showButtons.value ? AppBar( backgroundColor: Colors.black38, @@ -79,16 +82,30 @@ class MediaView extends HookWidget { ], ) : null, - extendBodyBehindAppBar: true, - body: GestureDetector( - onTapUp: (details) => showButtons.value = !showButtons.value, - child: PhotoView( - minScale: PhotoViewComputedScale.contained, - initialScale: PhotoViewComputedScale.contained, - imageProvider: CachedNetworkImageProvider(url), - heroAttributes: PhotoViewHeroAttributes(tag: url), - loadingBuilder: (context, event) => - Center(child: CircularProgressIndicator()), + 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()), + ), ), ), );