From 5fa9e22cd518aba90ab65c6f49742ec9bb82bcd0 Mon Sep 17 00:00:00 2001 From: krawieck Date: Thu, 10 Sep 2020 23:03:50 +0200 Subject: [PATCH] Add media view widget --- lib/widgets/media_view.dart | 50 +++++++++++++++++++++++++++++++++++++ pubspec.lock | 7 ++++++ pubspec.yaml | 2 +- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 lib/widgets/media_view.dart diff --git a/lib/widgets/media_view.dart b/lib/widgets/media_view.dart new file mode 100644 index 0000000..ae40dda --- /dev/null +++ b/lib/widgets/media_view.dart @@ -0,0 +1,50 @@ +import 'package:cached_network_image/cached_network_image.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_hooks/flutter_hooks.dart'; +import 'package:photo_view/photo_view.dart'; + +class MediaView extends HookWidget { + final String url; + + const MediaView(this.url); + + @override + Widget build(BuildContext context) { + var showButtons = useState(true); + + return Scaffold( + appBar: AppBar( + backgroundColor: + showButtons.value ? Colors.black38 : Colors.transparent, + shadowColor: Colors.transparent, + leading: showButtons.value ? CloseButton() : Container(), + actions: showButtons.value + ? [ + IconButton( + icon: Icon(Icons.share), + tooltip: 'share', + onPressed: () {}, + ), + IconButton( + icon: Icon(Icons.file_download), + tooltip: 'download', + onPressed: () {}, + ), + ] + : 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()), + ), + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 1b60dcf..ca46e23 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -471,6 +471,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.9.0" + photo_view: + dependency: "direct main" + description: + name: photo_view + url: "https://pub.dartlang.org" + source: hosted + version: "0.10.2" platform: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index e22a9d3..f511dea 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,6 +21,7 @@ environment: sdk: '>=2.7.0 <3.0.0' dependencies: + photo_view: ^0.10.2 url_launcher: ^5.5.1 markdown: ^2.1.8 flutter_markdown: ^0.4.3 @@ -51,7 +52,6 @@ dev_dependencies: mobx_codegen: ^1.1.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec - # The following section is specific to Flutter. flutter: # The following line ensures that the Material Icons font is