diff --git a/lib/common/widgets/dynamic_sliver_app_bar/dynamic_sliver_app_bar.dart b/lib/common/widgets/dynamic_sliver_app_bar/dynamic_sliver_app_bar.dart index e64acbcbe..79934b7bf 100644 --- a/lib/common/widgets/dynamic_sliver_app_bar/dynamic_sliver_app_bar.dart +++ b/lib/common/widgets/dynamic_sliver_app_bar/dynamic_sliver_app_bar.dart @@ -202,7 +202,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { } } -class DynamicSliverAppBar extends StatefulWidget { +class DynamicSliverAppBar extends StatelessWidget { const DynamicSliverAppBar.medium({ super.key, this.leading, @@ -297,62 +297,57 @@ class DynamicSliverAppBar extends StatefulWidget { final EdgeInsetsGeometry? actionsPadding; - @override - State createState() => _DynamicSliverAppBarState(); -} - -class _DynamicSliverAppBarState extends State { @override Widget build(BuildContext context) { - final double bottomHeight = widget.bottom?.preferredSize.height ?? 0.0; - final double topPadding = widget.primary + final double bottomHeight = bottom?.preferredSize.height ?? 0.0; + final double topPadding = primary ? MediaQuery.viewPaddingOf(context).top : 0.0; final double effectiveCollapsedHeight = topPadding + kToolbarHeight + bottomHeight + 1; return SliverPinnedHeader( - onPerformLayout: widget.onPerformLayout, + onPerformLayout: onPerformLayout, delegate: _SliverAppBarDelegate( - leading: widget.leading, - automaticallyImplyLeading: widget.automaticallyImplyLeading, - title: widget.title, - actions: widget.actions, - automaticallyImplyActions: widget.automaticallyImplyActions, - flexibleSpace: widget.flexibleSpace, - bottom: widget.bottom, - elevation: widget.elevation, - scrolledUnderElevation: widget.scrolledUnderElevation, - shadowColor: widget.shadowColor, - surfaceTintColor: widget.surfaceTintColor, - forceElevated: widget.forceElevated, - backgroundColor: widget.backgroundColor, - foregroundColor: widget.foregroundColor, - iconTheme: widget.iconTheme, - actionsIconTheme: widget.actionsIconTheme, - primary: widget.primary, - centerTitle: widget.centerTitle, - excludeHeaderSemantics: widget.excludeHeaderSemantics, - titleSpacing: widget.titleSpacing, + leading: leading, + automaticallyImplyLeading: automaticallyImplyLeading, + title: title, + actions: actions, + automaticallyImplyActions: automaticallyImplyActions, + flexibleSpace: flexibleSpace, + bottom: bottom, + elevation: elevation, + scrolledUnderElevation: scrolledUnderElevation, + shadowColor: shadowColor, + surfaceTintColor: surfaceTintColor, + forceElevated: forceElevated, + backgroundColor: backgroundColor, + foregroundColor: foregroundColor, + iconTheme: iconTheme, + actionsIconTheme: actionsIconTheme, + primary: primary, + centerTitle: centerTitle, + excludeHeaderSemantics: excludeHeaderSemantics, + titleSpacing: titleSpacing, collapsedHeight: effectiveCollapsedHeight, topPadding: topPadding, - shape: widget.shape, + shape: shape, toolbarHeight: kToolbarHeight, - leadingWidth: widget.leadingWidth, - toolbarTextStyle: widget.toolbarTextStyle, - titleTextStyle: widget.titleTextStyle, - systemOverlayStyle: widget.systemOverlayStyle, - forceMaterialTransparency: widget.forceMaterialTransparency, - useDefaultSemanticsOrder: widget.useDefaultSemanticsOrder, - clipBehavior: widget.clipBehavior, - actionsPadding: widget.actionsPadding, + leadingWidth: leadingWidth, + toolbarTextStyle: toolbarTextStyle, + titleTextStyle: titleTextStyle, + systemOverlayStyle: systemOverlayStyle, + forceMaterialTransparency: forceMaterialTransparency, + useDefaultSemanticsOrder: useDefaultSemanticsOrder, + clipBehavior: clipBehavior, + actionsPadding: actionsPadding, ), ); } } /// ref [FlexibleSpaceBar] -class DynamicFlexibleSpaceBar extends StatefulWidget { +class DynamicFlexibleSpaceBar extends StatelessWidget { const DynamicFlexibleSpaceBar({ super.key, required this.background, @@ -363,14 +358,8 @@ class DynamicFlexibleSpaceBar extends StatefulWidget { final CollapseMode collapseMode; - @override - State createState() => - _DynamicFlexibleSpaceBarState(); -} - -class _DynamicFlexibleSpaceBarState extends State { double _getCollapsePadding(double t, FlexibleSpaceBarSettings settings) { - switch (widget.collapseMode) { + switch (collapseMode) { case CollapseMode.pin: return -(settings.maxExtent - settings.currentExtent); case CollapseMode.none: @@ -427,7 +416,7 @@ class _DynamicFlexibleSpaceBarState extends State { // through the app bar when it is collapsed. alwaysIncludeSemantics: true, opacity: opacity, - child: widget.background, + child: background, ), ), );