diff --git a/lib/screens/shared/sliver_screen/screen_sliver.dart b/lib/screens/shared/sliver_screen/screen_sliver.dart index f9fc4e6..b4ae69d 100644 --- a/lib/screens/shared/sliver_screen/screen_sliver.dart +++ b/lib/screens/shared/sliver_screen/screen_sliver.dart @@ -22,19 +22,23 @@ class SliverScreen extends StatelessWidget { bottom: false, child: CustomScrollView( slivers: [ - 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, ), - child: title, ), ), actions: [ @@ -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()!; + 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(begin: 1.5, end: 1.0).transform(extentScale); + } +}