Commit b28dd0c2 authored by 神楽坂花火's avatar 神楽坂花火 Committed by Flutter GitHub Bot

Reland "Add `brightness` to CupertinoNavigationBar (fixes #46216) (#47521)" (#47855)

parent cf00b969
...@@ -87,15 +87,24 @@ class _HeroTag { ...@@ -87,15 +87,24 @@ class _HeroTag {
Widget _wrapWithBackground({ Widget _wrapWithBackground({
Border border, Border border,
Color backgroundColor, Color backgroundColor,
Brightness brightness,
Widget child, Widget child,
bool updateSystemUiOverlay = true, bool updateSystemUiOverlay = true,
}) { }) {
Widget result = child; Widget result = child;
if (updateSystemUiOverlay) { if (updateSystemUiOverlay) {
final bool darkBackground = backgroundColor.computeLuminance() < 0.179; final bool isDark = backgroundColor.computeLuminance() < 0.179;
final SystemUiOverlayStyle overlayStyle = darkBackground final Brightness newBrightness = brightness ?? (isDark ? Brightness.dark : Brightness.light);
? SystemUiOverlayStyle.light SystemUiOverlayStyle overlayStyle;
: SystemUiOverlayStyle.dark; switch (newBrightness) {
case Brightness.dark:
overlayStyle = SystemUiOverlayStyle.light;
break;
case Brightness.light:
default:
overlayStyle = SystemUiOverlayStyle.dark;
break;
}
result = AnnotatedRegion<SystemUiOverlayStyle>( result = AnnotatedRegion<SystemUiOverlayStyle>(
value: overlayStyle, value: overlayStyle,
sized: true, sized: true,
...@@ -206,6 +215,7 @@ class CupertinoNavigationBar extends StatefulWidget implements ObstructingPrefer ...@@ -206,6 +215,7 @@ class CupertinoNavigationBar extends StatefulWidget implements ObstructingPrefer
this.trailing, this.trailing,
this.border = _kDefaultNavBarBorder, this.border = _kDefaultNavBarBorder,
this.backgroundColor, this.backgroundColor,
this.brightness,
this.padding, this.padding,
this.actionsForegroundColor, this.actionsForegroundColor,
this.transitionBetweenRoutes = true, this.transitionBetweenRoutes = true,
...@@ -301,6 +311,18 @@ class CupertinoNavigationBar extends StatefulWidget implements ObstructingPrefer ...@@ -301,6 +311,18 @@ class CupertinoNavigationBar extends StatefulWidget implements ObstructingPrefer
/// {@endtemplate} /// {@endtemplate}
final Color backgroundColor; final Color backgroundColor;
/// {@template flutter.cupertino.navBar.brightness}
/// The brightness of the specified [backgroundColor].
///
/// Setting this value changes the style of the system status bar. Typically
/// used to increase the contrast ratio of the system status bar over
/// [backgroundColor].
///
/// If set to null, the value of the property will be inferred from the relative
/// luminance of [backgroundColor].
/// {@endtemplate}
final Brightness brightness;
/// {@template flutter.cupertino.navBar.padding} /// {@template flutter.cupertino.navBar.padding}
/// Padding for the contents of the navigation bar. /// Padding for the contents of the navigation bar.
/// ///
...@@ -427,6 +449,7 @@ class _CupertinoNavigationBarState extends State<CupertinoNavigationBar> { ...@@ -427,6 +449,7 @@ class _CupertinoNavigationBarState extends State<CupertinoNavigationBar> {
final Widget navBar = _wrapWithBackground( final Widget navBar = _wrapWithBackground(
border: widget.border, border: widget.border,
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
brightness: widget.brightness,
child: DefaultTextStyle( child: DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.textStyle, style: CupertinoTheme.of(context).textTheme.textStyle,
child: _PersistentNavigationBar( child: _PersistentNavigationBar(
...@@ -547,6 +570,7 @@ class CupertinoSliverNavigationBar extends StatefulWidget { ...@@ -547,6 +570,7 @@ class CupertinoSliverNavigationBar extends StatefulWidget {
this.trailing, this.trailing,
this.border = _kDefaultNavBarBorder, this.border = _kDefaultNavBarBorder,
this.backgroundColor, this.backgroundColor,
this.brightness,
this.padding, this.padding,
this.actionsForegroundColor, this.actionsForegroundColor,
this.transitionBetweenRoutes = true, this.transitionBetweenRoutes = true,
...@@ -620,6 +644,9 @@ class CupertinoSliverNavigationBar extends StatefulWidget { ...@@ -620,6 +644,9 @@ class CupertinoSliverNavigationBar extends StatefulWidget {
/// {@macro flutter.cupertino.navBar.backgroundColor} /// {@macro flutter.cupertino.navBar.backgroundColor}
final Color backgroundColor; final Color backgroundColor;
/// {@macro flutter.cupertino.navBar.brightness}
final Brightness brightness;
/// {@macro flutter.cupertino.navBar.padding} /// {@macro flutter.cupertino.navBar.padding}
final EdgeInsetsDirectional padding; final EdgeInsetsDirectional padding;
...@@ -694,6 +721,7 @@ class _CupertinoSliverNavigationBarState extends State<CupertinoSliverNavigation ...@@ -694,6 +721,7 @@ class _CupertinoSliverNavigationBarState extends State<CupertinoSliverNavigation
components: components, components: components,
userMiddle: widget.middle, userMiddle: widget.middle,
backgroundColor: CupertinoDynamicColor.resolve(widget.backgroundColor, context) ?? CupertinoTheme.of(context).barBackgroundColor, backgroundColor: CupertinoDynamicColor.resolve(widget.backgroundColor, context) ?? CupertinoTheme.of(context).barBackgroundColor,
brightness: widget.brightness,
border: widget.border, border: widget.border,
padding: widget.padding, padding: widget.padding,
actionsForegroundColor: actionsForegroundColor, actionsForegroundColor: actionsForegroundColor,
...@@ -715,6 +743,7 @@ class _LargeTitleNavigationBarSliverDelegate ...@@ -715,6 +743,7 @@ class _LargeTitleNavigationBarSliverDelegate
@required this.components, @required this.components,
@required this.userMiddle, @required this.userMiddle,
@required this.backgroundColor, @required this.backgroundColor,
@required this.brightness,
@required this.border, @required this.border,
@required this.padding, @required this.padding,
@required this.actionsForegroundColor, @required this.actionsForegroundColor,
...@@ -730,6 +759,7 @@ class _LargeTitleNavigationBarSliverDelegate ...@@ -730,6 +759,7 @@ class _LargeTitleNavigationBarSliverDelegate
final _NavigationBarStaticComponents components; final _NavigationBarStaticComponents components;
final Widget userMiddle; final Widget userMiddle;
final Color backgroundColor; final Color backgroundColor;
final Brightness brightness;
final Border border; final Border border;
final EdgeInsetsDirectional padding; final EdgeInsetsDirectional padding;
final Color actionsForegroundColor; final Color actionsForegroundColor;
...@@ -760,6 +790,7 @@ class _LargeTitleNavigationBarSliverDelegate ...@@ -760,6 +790,7 @@ class _LargeTitleNavigationBarSliverDelegate
final Widget navBar = _wrapWithBackground( final Widget navBar = _wrapWithBackground(
border: border, border: border,
backgroundColor: CupertinoDynamicColor.resolve(backgroundColor, context), backgroundColor: CupertinoDynamicColor.resolve(backgroundColor, context),
brightness: brightness,
child: DefaultTextStyle( child: DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.textStyle, style: CupertinoTheme.of(context).textTheme.textStyle,
child: Stack( child: Stack(
......
...@@ -136,6 +136,74 @@ void main() { ...@@ -136,6 +136,74 @@ void main() {
expect(tester.getCenter(find.text('Title')).dx, 400.0); expect(tester.getCenter(find.text('Title')).dx, 400.0);
}); });
testWidgets('Can specify custom brightness', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
home: CupertinoNavigationBar(
backgroundColor: Color(0xF0F9F9F9),
brightness: Brightness.dark,
),
),
);
final AnnotatedRegion<SystemUiOverlayStyle> region1 = tester.allWidgets
.whereType<AnnotatedRegion<SystemUiOverlayStyle>>()
.single;
expect(region1.value, SystemUiOverlayStyle.light);
await tester.pumpWidget(
const CupertinoApp(
home: CupertinoNavigationBar(
backgroundColor: Color(0xF01D1D1D),
brightness: Brightness.light,
),
),
);
final AnnotatedRegion<SystemUiOverlayStyle> region2 = tester.allWidgets
.whereType<AnnotatedRegion<SystemUiOverlayStyle>>()
.single;
expect(region2.value, SystemUiOverlayStyle.dark);
await tester.pumpWidget(
const CupertinoApp(
home: CustomScrollView(
slivers: <Widget>[
CupertinoSliverNavigationBar(
largeTitle: Text('Title'),
backgroundColor: Color(0xF0F9F9F9),
brightness: Brightness.dark,
)
],
),
),
);
final AnnotatedRegion<SystemUiOverlayStyle> region3 = tester.allWidgets
.whereType<AnnotatedRegion<SystemUiOverlayStyle>>()
.single;
expect(region3.value, SystemUiOverlayStyle.light);
await tester.pumpWidget(
const CupertinoApp(
home: CustomScrollView(
slivers: <Widget>[
CupertinoSliverNavigationBar(
largeTitle: Text('Title'),
backgroundColor: Color(0xF01D1D1D),
brightness: Brightness.light,
)
],
),
),
);
final AnnotatedRegion<SystemUiOverlayStyle> region4 = tester.allWidgets
.whereType<AnnotatedRegion<SystemUiOverlayStyle>>()
.single;
expect(region4.value, SystemUiOverlayStyle.dark);
});
testWidgets('Padding works in RTL', (WidgetTester tester) async { testWidgets('Padding works in RTL', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const CupertinoApp( const CupertinoApp(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment