Skip to content

Commit

Permalink
Fix a regression with TopBar2
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k committed Jan 30, 2025
1 parent ff02ec8 commit 351a329
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class SmoothSelectorScreen<T> extends StatelessWidget {
leadingAction: provider.autoValidate
? SmoothTopBarLeadingAction.minimize
: SmoothTopBarLeadingAction.close,
elevationOnScroll: false,
),
bottomBar: !provider.autoValidate
? _SmoothSelectorScreenBottomBar<T>(
Expand Down
23 changes: 14 additions & 9 deletions packages/smooth_app/lib/widgets/v2/smooth_topbar2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SmoothTopBar2 extends StatefulWidget implements PreferredSizeWidget {

class _SmoothTopBar2State extends State<SmoothTopBar2> {
late double _progress = 0.0;
late double _elevation = 0.0;

@override
void initState() {
Expand All @@ -66,6 +67,10 @@ class _SmoothTopBar2State extends State<SmoothTopBar2> {
),
);
}

if (!widget.elevationOnScroll) {
_elevation = widget.elevation;
}
}

void _onScroll() {
Expand All @@ -77,7 +82,14 @@ class _SmoothTopBar2State extends State<SmoothTopBar2> {
);

if (newProgress != _progress) {
setState(() => _progress = newProgress);
setState(() {
if (widget.elevationOnScroll) {
_elevation = widget.elevation * newProgress;
}
if (widget.reducedHeightOnScroll) {
_progress = newProgress;
}
});
}
}

Expand All @@ -99,7 +111,7 @@ class _SmoothTopBar2State extends State<SmoothTopBar2> {

return PhysicalModel(
color: Colors.transparent,
elevation: _computeElevation(),
elevation: _elevation,
shadowColor: widget.elevationColor ??
(darkTheme ? Colors.white10 : Colors.black12),
borderRadius: borderRadius,
Expand Down Expand Up @@ -182,13 +194,6 @@ class _SmoothTopBar2State extends State<SmoothTopBar2> {
);
}

double _computeElevation() {
if (!widget.elevationOnScroll) {
return widget.elevation;
}
return widget.elevation * _progress;
}

double _computeHeight() =>
kToolbarHeight +
((SmoothTopBar2.kTopBar2Height - kToolbarHeight) * (1 - _progress));
Expand Down

0 comments on commit 351a329

Please sign in to comment.