diff --git a/packages/flutter/lib/src/cupertino/nav_bar.dart b/packages/flutter/lib/src/cupertino/nav_bar.dart index 00b3c05eee..e7c2c37cd0 100644 --- a/packages/flutter/lib/src/cupertino/nav_bar.dart +++ b/packages/flutter/lib/src/cupertino/nav_bar.dart @@ -146,6 +146,7 @@ Widget _wrapWithBackground({ Brightness? brightness, required Widget child, bool updateSystemUiOverlay = true, + bool enableBackgroundFilterBlur = true, }) { Widget result = child; if (updateSystemUiOverlay) { @@ -182,7 +183,7 @@ Widget _wrapWithBackground({ return ClipRect( child: BackdropFilter( - enabled: backgroundColor.alpha != 0xFF, + enabled: backgroundColor.alpha != 0xFF && enableBackgroundFilterBlur, filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), child: childWithBackground, ), @@ -266,6 +267,7 @@ class CupertinoNavigationBar extends StatefulWidget implements ObstructingPrefer this.border = _kDefaultNavBarBorder, this.backgroundColor, this.automaticBackgroundVisibility = true, + this.enableBackgroundFilterBlur = true, this.brightness, this.padding, this.transitionBetweenRoutes = true, @@ -342,7 +344,8 @@ class CupertinoNavigationBar extends StatefulWidget implements ObstructingPrefer /// {@template flutter.cupertino.CupertinoNavigationBar.backgroundColor} /// The background color of the navigation bar. If it contains transparency, the /// tab bar will automatically produce a blurring effect to the content - /// behind it. + /// behind it. This behavior can be disabled by setting [enableBackgroundFilterBlur] + /// to false. /// /// By default, the navigation bar's background is visible only when scrolled under. /// This behavior can be controlled with [automaticBackgroundVisibility]. @@ -417,6 +420,17 @@ class CupertinoNavigationBar extends StatefulWidget implements ObstructingPrefer /// {@endtemplate} final bool transitionBetweenRoutes; + /// {@template flutter.cupertino.CupertinoNavigationBar.enableBackgroundFilterBlur} + /// Whether to have a blur effect when a non-opaque background color is used. + /// + /// When [enableBackgroundFilterBlur] is set to false, the blur effect will be + /// disabled. The behaviour of [enableBackgroundFilterBlur] will only be respected when + /// [automaticBackgroundVisibility] is false or until content scrolls under the navbar. + /// + /// This value defaults to true. + /// {@endtemplate} + final bool enableBackgroundFilterBlur; + /// {@template flutter.cupertino.CupertinoNavigationBar.heroTag} /// Tag for the navigation bar's Hero widget if [transitionBetweenRoutes] is true. /// @@ -552,6 +566,7 @@ class _CupertinoNavigationBarState extends State { border: effectiveBorder, backgroundColor: effectiveBackgroundColor, brightness: widget.brightness, + enableBackgroundFilterBlur: widget.enableBackgroundFilterBlur, child: DefaultTextStyle( style: CupertinoTheme.of(context).textTheme.textStyle, child: _PersistentNavigationBar( @@ -676,6 +691,7 @@ class CupertinoSliverNavigationBar extends StatefulWidget { this.border = _kDefaultNavBarBorder, this.backgroundColor, this.automaticBackgroundVisibility = true, + this.enableBackgroundFilterBlur = true, this.brightness, this.padding, this.transitionBetweenRoutes = true, @@ -760,6 +776,9 @@ class CupertinoSliverNavigationBar extends StatefulWidget { /// {@macro flutter.cupertino.CupertinoNavigationBar.automaticBackgroundVisibility} final bool automaticBackgroundVisibility; + /// {@macro flutter.cupertino.CupertinoNavigationBar.enableBackgroundFilterBlur} + final bool enableBackgroundFilterBlur; + /// {@macro flutter.cupertino.CupertinoNavigationBar.brightness} final Brightness? brightness; @@ -840,6 +859,7 @@ class _CupertinoSliverNavigationBarState extends State persistentHeight; @@ -922,6 +944,7 @@ class _LargeTitleNavigationBarSliverDelegate border: effectiveBorder, backgroundColor: effectiveBackgroundColor, brightness: brightness, + enableBackgroundFilterBlur: enableBackgroundFilterBlur, child: DefaultTextStyle( style: CupertinoTheme.of(context).textTheme.textStyle, child: Stack( @@ -1014,7 +1037,8 @@ class _LargeTitleNavigationBarSliverDelegate || transitionBetweenRoutes != oldDelegate.transitionBetweenRoutes || persistentHeight != oldDelegate.persistentHeight || alwaysShowMiddle != oldDelegate.alwaysShowMiddle - || heroTag != oldDelegate.heroTag; + || heroTag != oldDelegate.heroTag + || enableBackgroundFilterBlur != oldDelegate.enableBackgroundFilterBlur; } } diff --git a/packages/flutter/test/cupertino/nav_bar_test.dart b/packages/flutter/test/cupertino/nav_bar_test.dart index faf500e9d6..f87e3e12c8 100644 --- a/packages/flutter/test/cupertino/nav_bar_test.dart +++ b/packages/flutter/test/cupertino/nav_bar_test.dart @@ -157,6 +157,33 @@ void main() { ); }); + testWidgets('Blur affect is disabled when enableBackgroundFilterBlur is false', (WidgetTester test) async { + await test.pumpWidget( + CupertinoApp( + theme: const CupertinoThemeData(brightness: Brightness.light), + home: CupertinoPageScaffold( + navigationBar: CupertinoNavigationBar( + backgroundColor: const Color(0xFFFFFFFF).withOpacity(0), + middle: const Text('Title'), + automaticBackgroundVisibility: false, + enableBackgroundFilterBlur: false, + ), + child: const Column( + children: [ + Placeholder(), + ], + ), + ), + ), + ); + + expect( + test.widget(find.byType(BackdropFilter)), + isA().having( + (BackdropFilter filter) => filter.enabled, 'filter enabled', false), + ); + }); + testWidgets('Nav bar displays correctly', (WidgetTester tester) async { final GlobalKey navigator = GlobalKey(); await tester.pumpWidget(