From a5cc7d8f3f87fe6daa43ef6fd53e982a907f6cc6 Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Sun, 11 Aug 2024 12:57:24 -0700 Subject: [PATCH] Add photo view for thumbnails, emotes, and badges (#372) * Add photo view for emotes and badges * Add photo view to stream thumbnails * Remove dismissable and use close button * Use cached network image provider * Add dismissible --- lib/models/irc.dart | 9 +++- lib/screens/home/stream_list/stream_card.dart | 15 ++++++- lib/widgets/photo_view.dart | 43 +++++++++++++++++++ pubspec.lock | 8 ++++ pubspec.yaml | 1 + 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 lib/widgets/photo_view.dart diff --git a/lib/models/irc.dart b/lib/models/irc.dart index 46a1e26a..b9e44ea1 100644 --- a/lib/models/irc.dart +++ b/lib/models/irc.dart @@ -10,6 +10,7 @@ import 'package:frosty/screens/channel/chat/stores/chat_assets_store.dart'; import 'package:frosty/screens/settings/stores/settings_store.dart'; import 'package:frosty/utils.dart'; import 'package:frosty/widgets/cached_image.dart'; +import 'package:frosty/widgets/photo_view.dart'; import 'package:intl/intl.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -695,7 +696,13 @@ class IRCMessage { primary: false, children: [ ListTile( - leading: leading, + leading: InkWell( + onTap: () => showDialog( + context: context, + builder: (context) => FrostyPhotoViewDialog(imageUrl: url), + ), + child: leading, + ), title: Text( title, style: const TextStyle( diff --git a/lib/screens/home/stream_list/stream_card.dart b/lib/screens/home/stream_list/stream_card.dart index 03f45e27..4cffdba2 100644 --- a/lib/screens/home/stream_list/stream_card.dart +++ b/lib/screens/home/stream_list/stream_card.dart @@ -10,6 +10,7 @@ import 'package:frosty/utils.dart'; import 'package:frosty/widgets/block_report_modal.dart'; import 'package:frosty/widgets/cached_image.dart'; import 'package:frosty/widgets/loading_indicator.dart'; +import 'package:frosty/widgets/photo_view.dart'; import 'package:frosty/widgets/profile_picture.dart'; import 'package:frosty/widgets/uptime.dart'; import 'package:intl/intl.dart'; @@ -72,7 +73,19 @@ class StreamCard extends StatelessWidget { child: Stack( alignment: AlignmentDirectional.bottomEnd, children: [ - thumbnail, + GestureDetector( + onLongPress: () => showDialog( + context: context, + builder: (context) => FrostyPhotoViewDialog( + imageUrl: streamInfo.thumbnailUrl.replaceFirst( + '-{width}x{height}', + '', + ) + + cacheUrlExtension, + ), + ), + child: thumbnail, + ), Container( padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2), decoration: const BoxDecoration( diff --git a/lib/widgets/photo_view.dart b/lib/widgets/photo_view.dart new file mode 100644 index 00000000..dfa44aab --- /dev/null +++ b/lib/widgets/photo_view.dart @@ -0,0 +1,43 @@ +import 'package:cached_network_image/cached_network_image.dart'; +import 'package:flutter/material.dart'; +import 'package:photo_view/photo_view.dart'; + +class FrostyPhotoViewDialog extends StatefulWidget { + final String imageUrl; + + const FrostyPhotoViewDialog({super.key, required this.imageUrl}); + + @override + State createState() => _FrostyPhotoViewDialogState(); +} + +class _FrostyPhotoViewDialogState extends State { + PhotoViewScaleState photoViewScaleState = PhotoViewScaleState.initial; + + @override + Widget build(BuildContext context) { + return Stack( + alignment: Alignment.topCenter, + children: [ + Dismissible( + key: const Key('photo_view_dismissible'), + direction: photoViewScaleState == PhotoViewScaleState.initial + ? DismissDirection.vertical + : DismissDirection.none, + onDismissed: Navigator.of(context).pop, + child: PhotoView( + imageProvider: CachedNetworkImageProvider(widget.imageUrl), + scaleStateChangedCallback: (value) => + setState(() => photoViewScaleState = value), + backgroundDecoration: + const BoxDecoration(color: Colors.transparent), + ), + ), + IconButton( + icon: const Icon(Icons.close, color: Colors.white), + onPressed: Navigator.of(context).pop, + ), + ], + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index fa0c2731..f91664a8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -837,6 +837,14 @@ packages: url: "https://pub.dev" source: hosted version: "6.0.2" + photo_view: + dependency: "direct main" + description: + name: photo_view + sha256: "1fc3d970a91295fbd1364296575f854c9863f225505c28c46e0a03e48960c75e" + url: "https://pub.dev" + source: hosted + version: "0.15.0" platform: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 5af67801..1294b63d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -64,6 +64,7 @@ dependencies: advanced_in_app_review: ^1.1.3 webview_flutter_android: ^3.7.0 webview_flutter_wkwebview: ^3.4.3 + photo_view: ^0.15.0 dev_dependencies: flutter_test: