#1113 viewer: long descriptions are scrollable when overlay is expanded by tap

This commit is contained in:
Thibault Deckers 2024-08-05 21:01:55 +02:00
parent 867fb95426
commit 554e1faf88
2 changed files with 53 additions and 6 deletions

View file

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Added
- Viewer: display more items in tag/copy/move quick action choosers
- Viewer: long descriptions are scrollable when overlay is expanded by tap
- Collection: sort by duration
- Map: open external map app from map views

View file

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class OverlayRowExpander extends StatelessWidget {
class OverlayRowExpander extends StatefulWidget {
final ValueNotifier<bool> expandedNotifier;
final Widget child;
@ -10,24 +11,69 @@ class OverlayRowExpander extends StatelessWidget {
required this.child,
});
@override
State<OverlayRowExpander> createState() => _OverlayRowExpanderState();
}
class _OverlayRowExpanderState extends State<OverlayRowExpander> {
final ScrollController _scrollController = ScrollController();
@override
void didUpdateWidget(covariant OverlayRowExpander oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.child != widget.child) {
if (_scrollController.hasClients && _scrollController.positions.every((v) => v.hasContentDimensions)) {
_scrollController.jumpTo(0);
}
}
}
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<bool>(
valueListenable: expandedNotifier,
valueListenable: widget.expandedNotifier,
builder: (context, expanded, child) {
final parent = DefaultTextStyle.of(context);
return DefaultTextStyle(
key: key,
child = DefaultTextStyle(
style: parent.style,
textAlign: parent.textAlign,
softWrap: expanded,
overflow: parent.overflow,
maxLines: expanded ? 16 : 1,
maxLines: expanded ? null : 1,
textWidthBasis: parent.textWidthBasis,
child: child!,
);
},
if (expanded) {
child = ConstrainedBox(
constraints: BoxConstraints(
maxHeight: context.select<MediaQueryData, double>((mq) => mq.size.height / 5),
),
child: MediaQuery.removePadding(
// remove padding so that scroll bar is consistent with the scroll view
context: context,
removeTop: true,
removeBottom: true,
child: Scrollbar(
controller: _scrollController,
thumbVisibility: true,
radius: const Radius.circular(16),
child: SingleChildScrollView(
controller: _scrollController,
child: child,
),
),
),
);
}
return child;
},
child: widget.child,
);
}
}