kopia lustrzana https://gitlab.com/mysocialportal/relatica
Fix image viewer image sizing and move ALT text to a button driven dialog box
rodzic
d939a56f2b
commit
32f27001d5
|
@ -13,7 +13,6 @@ import '../globals.dart';
|
|||
import '../models/attachment_media_type_enum.dart';
|
||||
import '../models/media_attachment.dart';
|
||||
import '../services/auth_service.dart';
|
||||
import '../utils/clipboard_utils.dart';
|
||||
import '../utils/snackbar_builder.dart';
|
||||
|
||||
class MediaViewerScreen extends StatefulWidget {
|
||||
|
@ -96,25 +95,20 @@ class _MediaViewerScreenState extends State<MediaViewerScreen> {
|
|||
Widget build(BuildContext context) {
|
||||
final currentAttachment = widget.attachments[currentIndex];
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
final height = MediaQuery.of(context).size.height * 0.9;
|
||||
final descriptionHeightPct = widget.attachments.isEmpty ? 0.0 : 0.1;
|
||||
final mediaHeight = height * (1 - descriptionHeightPct);
|
||||
final descriptionHeight = height * descriptionHeightPct;
|
||||
final height = MediaQuery.of(context).size.height * 1.0;
|
||||
final mediaHeight = height;
|
||||
|
||||
late final bool canSave;
|
||||
late final Widget mediaViewer;
|
||||
switch (currentAttachment.explicitType) {
|
||||
case AttachmentMediaType.image:
|
||||
canSave = true;
|
||||
mediaViewer = SizedBox(
|
||||
width: width,
|
||||
height: mediaHeight,
|
||||
child: InteractiveViewer(
|
||||
maxScale: 10.0,
|
||||
scaleFactor: 400,
|
||||
child: LoginAwareCachedNetworkImage(
|
||||
imageUrl: currentAttachment.uri.toString()),
|
||||
));
|
||||
mediaViewer = InteractiveViewer(
|
||||
maxScale: 10.0,
|
||||
scaleFactor: 400,
|
||||
child: LoginAwareCachedNetworkImage(
|
||||
imageUrl: currentAttachment.uri.toString()),
|
||||
);
|
||||
break;
|
||||
case AttachmentMediaType.unknown:
|
||||
case AttachmentMediaType.video:
|
||||
|
@ -147,13 +141,10 @@ class _MediaViewerScreenState extends State<MediaViewerScreen> {
|
|||
body: SafeArea(
|
||||
child: Stack(
|
||||
children: [
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
mediaViewer,
|
||||
if (currentAttachment.description.isNotEmpty)
|
||||
buildTextArea(currentAttachment, descriptionHeight),
|
||||
],
|
||||
SizedBox(
|
||||
height: height,
|
||||
width: width,
|
||||
child: mediaViewer,
|
||||
),
|
||||
if (widget.attachments.length > 1) ...[
|
||||
Positioned(
|
||||
|
@ -189,43 +180,26 @@ class _MediaViewerScreenState extends State<MediaViewerScreen> {
|
|||
),
|
||||
),
|
||||
),
|
||||
if (currentAttachment.description.isNotEmpty)
|
||||
Positioned(
|
||||
bottom: 5.0,
|
||||
left: 5.0,
|
||||
child: ElevatedButton(
|
||||
onPressed: () async => await showConfirmDialog(
|
||||
context,
|
||||
currentAttachment.description,
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context)
|
||||
.scaffoldBackgroundColor
|
||||
.withOpacity(0.7)),
|
||||
child: const Text('ALT'),
|
||||
),
|
||||
),
|
||||
]
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildTextArea(MediaAttachment attachment, double height) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
||||
child: SizedBox(
|
||||
height: height,
|
||||
child: attachment.description.isEmpty
|
||||
? null
|
||||
: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Scrollbar(
|
||||
controller: ScrollController(),
|
||||
thumbVisibility: true,
|
||||
child: SingleChildScrollView(
|
||||
child: Text(attachment.description),
|
||||
),
|
||||
)),
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
await copyToClipboard(
|
||||
context: context,
|
||||
text: attachment.description,
|
||||
message: 'Image description copied to clipboard');
|
||||
},
|
||||
icon: const Icon(Icons.copy),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue