From 9dad9e2847f95d696188ce457baf3ac7b7e3b737 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Fri, 20 Dec 2024 08:47:49 -0500 Subject: [PATCH] Add ALT image tags more pervasively --- lib/controls/image_control.dart | 31 +++++++++++++++++++++++++--- lib/globals.dart | 23 +++++++++++++++++++++ lib/screens/gallery_screen.dart | 26 +---------------------- lib/screens/media_viewer_screen.dart | 4 ++-- 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/lib/controls/image_control.dart b/lib/controls/image_control.dart index 0698c99..af0f4ce 100644 --- a/lib/controls/image_control.dart +++ b/lib/controls/image_control.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import '../globals.dart'; import '../riverpod_controllers/settings_services.dart'; import 'login_aware_cached_network_image.dart'; @@ -44,10 +45,34 @@ class _ImageControlState extends ConsumerState { if (shown && widget.imageUrl.isNotEmpty) { _shownImageUrls.add(widget.imageUrl); - image = LoginAwareCachedNetworkImage( - imageUrl: widget.imageUrl, - width: widget.width, + image = SizedBox( height: widget.height, + width: widget.width, + child: Stack( + children: [ + LoginAwareCachedNetworkImage( + imageUrl: widget.imageUrl, + width: widget.width, + height: widget.height, + ), + if (widget.altText.isNotEmpty) + Positioned( + bottom: 5.0, + left: 5.0, + child: ElevatedButton( + onPressed: () async => await showInfoDialog( + context, + widget.altText, + ), + style: ElevatedButton.styleFrom( + backgroundColor: Theme.of(context) + .scaffoldBackgroundColor + .withValues(alpha: 0.7)), + child: const Text('ALT'), + ), + ), + ], + ), ); } else { final icon = widget.iconOverride ?? diff --git a/lib/globals.dart b/lib/globals.dart index c07f841..c9ebf72 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -28,6 +28,29 @@ const processingSleep = Duration(milliseconds: 1); const apiCallTimeout = Duration(seconds: 90); const oauthTimeout = Duration(seconds: 30); +Future showInfoDialog(BuildContext context, String text) async { + await showDialog( + context: context, + barrierDismissible: true, + builder: (BuildContext context) { + return AlertDialog( + content: Text( + text, + softWrap: true, + ), + actions: [ + ElevatedButton( + child: const Text('Dismiss'), + onPressed: () { + Navigator.pop(context, true); // showDialog() returns true + }, + ), + ], + ); + }, + ); +} + Future showConfirmDialog(BuildContext context, String caption) { return showDialog( context: context, diff --git a/lib/screens/gallery_screen.dart b/lib/screens/gallery_screen.dart index ff988ee..57ef1bd 100644 --- a/lib/screens/gallery_screen.dart +++ b/lib/screens/gallery_screen.dart @@ -208,8 +208,7 @@ class _GalleryScreenBody extends ConsumerWidget { bottom: 5.0, left: 5.0, child: ElevatedButton( - onPressed: () async => - await showImageCaption( + onPressed: () async => await showInfoDialog( context, image.description, ), @@ -244,27 +243,4 @@ class _GalleryScreenBody extends ConsumerWidget { ); }); } - - Future showImageCaption(BuildContext context, String text) async { - await showDialog( - context: context, - barrierDismissible: true, - builder: (BuildContext context) { - return AlertDialog( - content: Text( - text, - softWrap: true, - ), - actions: [ - ElevatedButton( - child: const Text('Dismiss'), - onPressed: () { - Navigator.pop(context, true); // showDialog() returns true - }, - ), - ], - ); - }, - ); - } } diff --git a/lib/screens/media_viewer_screen.dart b/lib/screens/media_viewer_screen.dart index ebe108b..a447e27 100644 --- a/lib/screens/media_viewer_screen.dart +++ b/lib/screens/media_viewer_screen.dart @@ -187,10 +187,10 @@ class _MediaViewerScreenState extends ConsumerState { ), if (currentAttachment.description.isNotEmpty) Positioned( - bottom: 5.0, + bottom: 20.0, left: 5.0, child: ElevatedButton( - onPressed: () async => await showConfirmDialog( + onPressed: () async => await showInfoDialog( context, currentAttachment.description, ),