mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 07:20:39 +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,
|
bottom: false,
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
slivers: <Widget>[
|
slivers: <Widget>[
|
||||||
SliverAppBar(
|
SliverAppBar.large(
|
||||||
pinned: true,
|
|
||||||
automaticallyImplyLeading: false,
|
automaticallyImplyLeading: false,
|
||||||
expandedHeight: Dimens.sliverAppBarExpandedHeight,
|
expandedHeight: Dimens.sliverAppBarExpandedHeight,
|
||||||
flexibleSpace: FlexibleSpaceBar(
|
flexibleSpace: FlexibleSpaceBar(
|
||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
titlePadding: const EdgeInsets.all(Dimens.paddingM),
|
titlePadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
|
||||||
title: DefaultTextStyle(
|
title: DefaultTextStyle(
|
||||||
style: TextStyle(
|
style: Theme.of(context)
|
||||||
color: Theme.of(context).colorScheme.onSurface,
|
.textTheme
|
||||||
fontSize: Dimens.grid24,
|
.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: [
|
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