add dismiss handling. not perfect and prolly not final

This commit is contained in:
krawieck 2020-09-11 15:56:22 +02:00
parent c7baa125c4
commit e4e7f1d9a1
1 changed files with 28 additions and 11 deletions

View File

@ -14,7 +14,8 @@ class MediaView extends HookWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var showButtons = useState(true); final showButtons = useState(true);
final isZoomedOut = useState(true);
useEffect(() => () => SystemChrome.setEnabledSystemUIOverlays([ useEffect(() => () => SystemChrome.setEnabledSystemUIOverlays([
SystemUiOverlay.bottom, SystemUiOverlay.bottom,
@ -60,6 +61,8 @@ class MediaView extends HookWidget {
} }
return Scaffold( return Scaffold(
extendBodyBehindAppBar: true,
extendBody: true,
appBar: showButtons.value appBar: showButtons.value
? AppBar( ? AppBar(
backgroundColor: Colors.black38, backgroundColor: Colors.black38,
@ -79,16 +82,30 @@ class MediaView extends HookWidget {
], ],
) )
: null, : null,
extendBodyBehindAppBar: true, body: Dismissible(
body: GestureDetector( direction: DismissDirection.vertical,
onTapUp: (details) => showButtons.value = !showButtons.value, onDismissed: (_) => Navigator.of(context).pop(),
child: PhotoView( key: const Key('media view'),
minScale: PhotoViewComputedScale.contained, background: Container(color: Colors.black),
initialScale: PhotoViewComputedScale.contained, dismissThresholds: {
imageProvider: CachedNetworkImageProvider(url), DismissDirection.vertical: 0,
heroAttributes: PhotoViewHeroAttributes(tag: url), },
loadingBuilder: (context, event) => confirmDismiss: (direction) => Future.value(isZoomedOut.value),
Center(child: CircularProgressIndicator()), 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()),
),
), ),
), ),
); );