royalcat
0d7aac068c
All checks were successful
docker / build-docker (linux/amd64) (push) Successful in 1m39s
docker / build-docker (linux/386) (push) Successful in 1m46s
docker / build-docker (linux/arm64/v8) (push) Successful in 8m18s
docker / build-docker (linux/arm64) (push) Successful in 8m29s
docker / build-docker (linux/arm/v7) (push) Successful in 8m49s
91 lines
2.2 KiB
Dart
91 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class HideableHeaderSliver extends StatelessWidget {
|
|
final Widget? leading;
|
|
final Widget body;
|
|
final double height;
|
|
final List<Widget>? actions;
|
|
|
|
const HideableHeaderSliver({
|
|
super.key,
|
|
this.leading,
|
|
required this.body,
|
|
this.actions,
|
|
this.height = 150,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SliverPersistentHeader(
|
|
floating: true,
|
|
pinned: false,
|
|
delegate: _HideableHeaderSliverDelegate(
|
|
leading: leading,
|
|
body: body,
|
|
actions: actions,
|
|
height: height,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _HideableHeaderSliverDelegate extends SliverPersistentHeaderDelegate {
|
|
final Widget? leading;
|
|
final Widget body;
|
|
final List<Widget>? actions;
|
|
final double height;
|
|
|
|
const _HideableHeaderSliverDelegate({
|
|
required this.leading,
|
|
required this.body,
|
|
required this.actions,
|
|
required this.height,
|
|
});
|
|
|
|
@override
|
|
double get maxExtent => height;
|
|
|
|
@override
|
|
double get minExtent => height;
|
|
|
|
@override
|
|
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) => true;
|
|
|
|
@override
|
|
Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
|
|
final content = <Widget>[
|
|
if (leading != null) leading!,
|
|
Expanded(child: body),
|
|
if (actions != null && actions!.isNotEmpty) ButtonBar(children: actions!),
|
|
];
|
|
|
|
final appBarTheme = AppBarTheme.of(context);
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
final onTop = (shrinkOffset == 0);
|
|
|
|
return Material(
|
|
color:
|
|
onTop ? appBarTheme.backgroundColor ?? colorScheme.surface : colorScheme.surfaceContainer,
|
|
elevation: onTop ? 0 : appBarTheme.elevation ?? 3,
|
|
surfaceTintColor: appBarTheme.surfaceTintColor ?? colorScheme.surfaceTint,
|
|
child: ClipRect(
|
|
child: SizedBox(
|
|
height: maxExtent,
|
|
child: Column(
|
|
children: [
|
|
const Spacer(),
|
|
Row(
|
|
children: content,
|
|
),
|
|
const Spacer(),
|
|
const Divider(
|
|
height: 1,
|
|
thickness: 1,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|