2023-03-30 19:24:18 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-09-18 14:59:53 +00:00
|
|
|
import 'package:lightmeter/generated/l10n.dart';
|
2023-03-30 19:24:18 +00:00
|
|
|
import 'package:lightmeter/res/dimens.dart';
|
2024-10-24 10:09:11 +00:00
|
|
|
import 'package:lightmeter/utils/text_height.dart';
|
2023-03-30 19:24:18 +00:00
|
|
|
|
|
|
|
class SliverScreen extends StatelessWidget {
|
2024-10-21 09:40:11 +00:00
|
|
|
final Widget title;
|
2023-03-30 19:24:18 +00:00
|
|
|
final List<Widget> appBarActions;
|
2024-10-24 10:09:11 +00:00
|
|
|
final PreferredSizeWidget? bottom;
|
2023-03-30 19:24:18 +00:00
|
|
|
final List<Widget> slivers;
|
|
|
|
|
|
|
|
const SliverScreen({
|
|
|
|
required this.title,
|
2023-09-18 14:59:53 +00:00
|
|
|
this.appBarActions = const [],
|
2024-10-24 10:09:11 +00:00
|
|
|
this.bottom,
|
2023-03-30 19:24:18 +00:00
|
|
|
required this.slivers,
|
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
body: SafeArea(
|
|
|
|
top: false,
|
|
|
|
bottom: false,
|
|
|
|
child: CustomScrollView(
|
|
|
|
slivers: <Widget>[
|
2024-10-26 10:55:55 +00:00
|
|
|
_AppBar(
|
|
|
|
title: title,
|
|
|
|
appBarActions: appBarActions,
|
2024-10-24 10:09:11 +00:00
|
|
|
bottom: bottom,
|
2023-03-30 19:24:18 +00:00
|
|
|
),
|
|
|
|
...slivers,
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-10-23 13:17:03 +00:00
|
|
|
|
2024-10-26 10:55:55 +00:00
|
|
|
class _AppBar extends StatelessWidget {
|
|
|
|
final Widget title;
|
|
|
|
final List<Widget> appBarActions;
|
|
|
|
final PreferredSizeWidget? bottom;
|
|
|
|
|
|
|
|
const _AppBar({
|
|
|
|
required this.title,
|
|
|
|
this.appBarActions = const [],
|
|
|
|
this.bottom,
|
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SliverAppBar.large(
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
expandedHeight: Dimens.sliverAppBarExpandedHeight + (bottom?.preferredSize.height ?? 0.0),
|
|
|
|
flexibleSpace: FlexibleSpaceBar(
|
|
|
|
centerTitle: false,
|
|
|
|
titlePadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
|
|
|
|
title: DefaultTextStyle(
|
|
|
|
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),
|
|
|
|
bottomSize: bottom?.preferredSize.height ?? 0.0,
|
|
|
|
child: title,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
bottom: bottom,
|
|
|
|
actions: [
|
|
|
|
...appBarActions,
|
|
|
|
if (Navigator.of(context).canPop())
|
|
|
|
IconButton(
|
|
|
|
onPressed: Navigator.of(context).pop,
|
|
|
|
icon: const Icon(Icons.close_outlined),
|
|
|
|
tooltip: S.of(context).tooltipClose,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-23 13:17:03 +00:00
|
|
|
class _Title extends StatelessWidget {
|
|
|
|
final Widget child;
|
|
|
|
final int actionsCount;
|
2024-10-24 10:09:11 +00:00
|
|
|
final double bottomSize;
|
2024-10-23 13:17:03 +00:00
|
|
|
final double actionsPadding;
|
|
|
|
|
|
|
|
const _Title({
|
|
|
|
required this.actionsCount,
|
2024-10-24 10:09:11 +00:00
|
|
|
required this.bottomSize,
|
2024-10-23 13:17:03 +00:00
|
|
|
required this.child,
|
|
|
|
}) : actionsPadding = Dimens.grid48 * actionsCount - Dimens.paddingM;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final settings = context.dependOnInheritedWidgetOfExactType<FlexibleSpaceBarSettings>()!;
|
2024-10-24 10:09:11 +00:00
|
|
|
final extentScale =
|
|
|
|
((settings.maxExtent - settings.currentExtent) / (settings.maxExtent - settings.minExtent)).clamp(0.0, 1.0);
|
|
|
|
final titleScale = Tween<double>(begin: 1.5, end: 1.0).transform(extentScale);
|
2024-10-23 13:17:03 +00:00
|
|
|
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(
|
2024-10-24 10:09:11 +00:00
|
|
|
builder: (context, constraints) => Padding(
|
|
|
|
padding: EdgeInsets.only(bottom: (Dimens.paddingM * (1 - actionsPaddingScale) + bottomSize) / titleScale),
|
|
|
|
child: SizedBox(
|
|
|
|
height: DefaultTextStyle.of(context).style.lineHeight * 2,
|
|
|
|
width: constraints.maxWidth - (actionsPadding * actionsPaddingScale) / titleScale,
|
|
|
|
child: Align(
|
|
|
|
alignment: FractionalOffset(0.0, 0.5 + 0.5 * (1 - extentScale)),
|
|
|
|
child: child,
|
|
|
|
),
|
2024-10-23 13:17:03 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|