From ed07ff086f9e24477587140c7beeeea7d9ca7167 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Sat, 2 Nov 2019 21:44:26 +0800 Subject: [PATCH] feat: open image view on avatar tap --- lib/widgets/avatar.dart | 27 ++++++++++++++++++--------- lib/widgets/image_view.dart | 20 ++++++++++++++++++++ pubspec.yaml | 1 + 3 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 lib/widgets/image_view.dart diff --git a/lib/widgets/avatar.dart b/lib/widgets/avatar.dart index 2394c54..64dd559 100644 --- a/lib/widgets/avatar.dart +++ b/lib/widgets/avatar.dart @@ -1,4 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:git_touch/models/theme.dart'; +import 'package:git_touch/widgets/image_view.dart'; +import 'package:provider/provider.dart'; class Avatar extends StatelessWidget { final String url; @@ -21,16 +24,22 @@ class Avatar extends StatelessWidget { @override Widget build(BuildContext context) { - return ClipRRect( - borderRadius: BorderRadius.circular(4), - child: FadeInImage.assetNetwork( - placeholder: 'images/octoface.png', - image: url, - width: size, - height: size, - fadeInDuration: Duration(milliseconds: 200), - fadeOutDuration: Duration(milliseconds: 100), + return GestureDetector( + child: ClipRRect( + borderRadius: BorderRadius.circular(4), + child: FadeInImage.assetNetwork( + placeholder: 'images/octoface.png', + image: url, + width: size, + height: size, + fadeInDuration: Duration(milliseconds: 200), + fadeOutDuration: Duration(milliseconds: 100), + ), ), + onTap: () { + Provider.of(context) + .pushRoute(context, (_) => ImageView(url), fullscreenDialog: true); + }, ); } } diff --git a/lib/widgets/image_view.dart b/lib/widgets/image_view.dart new file mode 100644 index 0000000..5cb106e --- /dev/null +++ b/lib/widgets/image_view.dart @@ -0,0 +1,20 @@ +import 'package:flutter/material.dart'; +import 'package:git_touch/scaffolds/common.dart'; +import 'package:photo_view/photo_view.dart'; + +class ImageView extends StatelessWidget { + final String url; + + ImageView(this.url); + + @override + Widget build(BuildContext context) { + return CommonScaffold( + title: Text('Image'), + body: PhotoView( + imageProvider: NetworkImage(url), + backgroundDecoration: BoxDecoration(color: Colors.white), + ), + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 101d39b..0f59e73 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -36,6 +36,7 @@ dependencies: tuple: ^1.0.2 uri: ^0.11.3 fimber: ^0.3.2 + photo_view: ^0.7.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.