fixed title overflow for SliverScreen

This commit is contained in:
Vadim 2024-10-23 15:17:03 +02:00
parent 1eebc7008e
commit e781bb38ac

View file

@ -22,21 +22,25 @@ class SliverScreen extends StatelessWidget {
bottom: false,
child: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
pinned: true,
SliverAppBar.large(
automaticallyImplyLeading: false,
expandedHeight: Dimens.sliverAppBarExpandedHeight,
flexibleSpace: FlexibleSpaceBar(
centerTitle: false,
titlePadding: const EdgeInsets.all(Dimens.paddingM),
titlePadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
title: DefaultTextStyle(
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
fontSize: Dimens.grid24,
),
style: Theme.of(context)
.textTheme
.headlineSmall!
.copyWith(color: Theme.of(context).colorScheme.onSurface),
maxLines: 2,
overflow: TextOverflow.ellipsis,
child: _Title(
actionsCount: appBarActions.length + (Navigator.of(context).canPop() ? 1 : 0),
child: title,
),
),
),
actions: [
...appBarActions,
if (Navigator.of(context).canPop())
@ -54,3 +58,39 @@ class SliverScreen extends StatelessWidget {
);
}
}
class _Title extends StatelessWidget {
final Widget child;
final int actionsCount;
final double actionsPadding;
const _Title({
required this.actionsCount,
required this.child,
}) : actionsPadding = Dimens.grid48 * actionsCount - Dimens.paddingM;
@override
Widget build(BuildContext context) {
final settings = context.dependOnInheritedWidgetOfExactType<FlexibleSpaceBarSettings>()!;
final titleScale = _titleScale(settings);
final maxFromTextToAppbar = settings.maxExtent - settings.minExtent - Dimens.paddingM;
final currentFromTextToAppbar = settings.currentExtent - settings.minExtent - Dimens.paddingM;
final actionsPaddingScale = (1 - currentFromTextToAppbar / maxFromTextToAppbar).clamp(0.0, 1.0);
return LayoutBuilder(
builder: (context, constraints) => SizedBox(
height: settings.minExtent - MediaQuery.paddingOf(context).top,
width: constraints.maxWidth - (actionsPadding * actionsPaddingScale) / titleScale,
child: Align(
alignment: Alignment.centerLeft,
child: child,
),
),
);
}
double _titleScale(FlexibleSpaceBarSettings s) {
final extentScale = ((s.maxExtent - s.currentExtent) / (s.maxExtent - s.minExtent)).clamp(0.0, 1.0);
return Tween<double>(begin: 1.5, end: 1.0).transform(extentScale);
}
}