mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-21 15:00:40 +00:00
fixed title overflow for SliverScreen
This commit is contained in:
parent
1eebc7008e
commit
e781bb38ac
1 changed files with 47 additions and 7 deletions
|
@ -22,19 +22,23 @@ 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,
|
||||
),
|
||||
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<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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue