mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 03:06:59 +08:00
stateless DynamicSliverAppBar
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -202,7 +202,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DynamicSliverAppBar extends StatefulWidget {
|
class DynamicSliverAppBar extends StatelessWidget {
|
||||||
const DynamicSliverAppBar.medium({
|
const DynamicSliverAppBar.medium({
|
||||||
super.key,
|
super.key,
|
||||||
this.leading,
|
this.leading,
|
||||||
@@ -297,62 +297,57 @@ class DynamicSliverAppBar extends StatefulWidget {
|
|||||||
|
|
||||||
final EdgeInsetsGeometry? actionsPadding;
|
final EdgeInsetsGeometry? actionsPadding;
|
||||||
|
|
||||||
@override
|
|
||||||
State<DynamicSliverAppBar> createState() => _DynamicSliverAppBarState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _DynamicSliverAppBarState extends State<DynamicSliverAppBar> {
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final double bottomHeight = widget.bottom?.preferredSize.height ?? 0.0;
|
final double bottomHeight = bottom?.preferredSize.height ?? 0.0;
|
||||||
final double topPadding = widget.primary
|
final double topPadding = primary
|
||||||
? MediaQuery.viewPaddingOf(context).top
|
? MediaQuery.viewPaddingOf(context).top
|
||||||
: 0.0;
|
: 0.0;
|
||||||
final double effectiveCollapsedHeight =
|
final double effectiveCollapsedHeight =
|
||||||
topPadding + kToolbarHeight + bottomHeight + 1;
|
topPadding + kToolbarHeight + bottomHeight + 1;
|
||||||
|
|
||||||
return SliverPinnedHeader(
|
return SliverPinnedHeader(
|
||||||
onPerformLayout: widget.onPerformLayout,
|
onPerformLayout: onPerformLayout,
|
||||||
delegate: _SliverAppBarDelegate(
|
delegate: _SliverAppBarDelegate(
|
||||||
leading: widget.leading,
|
leading: leading,
|
||||||
automaticallyImplyLeading: widget.automaticallyImplyLeading,
|
automaticallyImplyLeading: automaticallyImplyLeading,
|
||||||
title: widget.title,
|
title: title,
|
||||||
actions: widget.actions,
|
actions: actions,
|
||||||
automaticallyImplyActions: widget.automaticallyImplyActions,
|
automaticallyImplyActions: automaticallyImplyActions,
|
||||||
flexibleSpace: widget.flexibleSpace,
|
flexibleSpace: flexibleSpace,
|
||||||
bottom: widget.bottom,
|
bottom: bottom,
|
||||||
elevation: widget.elevation,
|
elevation: elevation,
|
||||||
scrolledUnderElevation: widget.scrolledUnderElevation,
|
scrolledUnderElevation: scrolledUnderElevation,
|
||||||
shadowColor: widget.shadowColor,
|
shadowColor: shadowColor,
|
||||||
surfaceTintColor: widget.surfaceTintColor,
|
surfaceTintColor: surfaceTintColor,
|
||||||
forceElevated: widget.forceElevated,
|
forceElevated: forceElevated,
|
||||||
backgroundColor: widget.backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
foregroundColor: widget.foregroundColor,
|
foregroundColor: foregroundColor,
|
||||||
iconTheme: widget.iconTheme,
|
iconTheme: iconTheme,
|
||||||
actionsIconTheme: widget.actionsIconTheme,
|
actionsIconTheme: actionsIconTheme,
|
||||||
primary: widget.primary,
|
primary: primary,
|
||||||
centerTitle: widget.centerTitle,
|
centerTitle: centerTitle,
|
||||||
excludeHeaderSemantics: widget.excludeHeaderSemantics,
|
excludeHeaderSemantics: excludeHeaderSemantics,
|
||||||
titleSpacing: widget.titleSpacing,
|
titleSpacing: titleSpacing,
|
||||||
collapsedHeight: effectiveCollapsedHeight,
|
collapsedHeight: effectiveCollapsedHeight,
|
||||||
topPadding: topPadding,
|
topPadding: topPadding,
|
||||||
shape: widget.shape,
|
shape: shape,
|
||||||
toolbarHeight: kToolbarHeight,
|
toolbarHeight: kToolbarHeight,
|
||||||
leadingWidth: widget.leadingWidth,
|
leadingWidth: leadingWidth,
|
||||||
toolbarTextStyle: widget.toolbarTextStyle,
|
toolbarTextStyle: toolbarTextStyle,
|
||||||
titleTextStyle: widget.titleTextStyle,
|
titleTextStyle: titleTextStyle,
|
||||||
systemOverlayStyle: widget.systemOverlayStyle,
|
systemOverlayStyle: systemOverlayStyle,
|
||||||
forceMaterialTransparency: widget.forceMaterialTransparency,
|
forceMaterialTransparency: forceMaterialTransparency,
|
||||||
useDefaultSemanticsOrder: widget.useDefaultSemanticsOrder,
|
useDefaultSemanticsOrder: useDefaultSemanticsOrder,
|
||||||
clipBehavior: widget.clipBehavior,
|
clipBehavior: clipBehavior,
|
||||||
actionsPadding: widget.actionsPadding,
|
actionsPadding: actionsPadding,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ref [FlexibleSpaceBar]
|
/// ref [FlexibleSpaceBar]
|
||||||
class DynamicFlexibleSpaceBar extends StatefulWidget {
|
class DynamicFlexibleSpaceBar extends StatelessWidget {
|
||||||
const DynamicFlexibleSpaceBar({
|
const DynamicFlexibleSpaceBar({
|
||||||
super.key,
|
super.key,
|
||||||
required this.background,
|
required this.background,
|
||||||
@@ -363,14 +358,8 @@ class DynamicFlexibleSpaceBar extends StatefulWidget {
|
|||||||
|
|
||||||
final CollapseMode collapseMode;
|
final CollapseMode collapseMode;
|
||||||
|
|
||||||
@override
|
|
||||||
State<DynamicFlexibleSpaceBar> createState() =>
|
|
||||||
_DynamicFlexibleSpaceBarState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _DynamicFlexibleSpaceBarState extends State<DynamicFlexibleSpaceBar> {
|
|
||||||
double _getCollapsePadding(double t, FlexibleSpaceBarSettings settings) {
|
double _getCollapsePadding(double t, FlexibleSpaceBarSettings settings) {
|
||||||
switch (widget.collapseMode) {
|
switch (collapseMode) {
|
||||||
case CollapseMode.pin:
|
case CollapseMode.pin:
|
||||||
return -(settings.maxExtent - settings.currentExtent);
|
return -(settings.maxExtent - settings.currentExtent);
|
||||||
case CollapseMode.none:
|
case CollapseMode.none:
|
||||||
@@ -427,7 +416,7 @@ class _DynamicFlexibleSpaceBarState extends State<DynamicFlexibleSpaceBar> {
|
|||||||
// through the app bar when it is collapsed.
|
// through the app bar when it is collapsed.
|
||||||
alwaysIncludeSemantics: true,
|
alwaysIncludeSemantics: true,
|
||||||
opacity: opacity,
|
opacity: opacity,
|
||||||
child: widget.background,
|
child: background,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user