Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
b28dd0c2
Commit
b28dd0c2
authored
Dec 28, 2019
by
神楽坂花火
Committed by
Flutter GitHub Bot
Dec 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reland "Add `brightness` to CupertinoNavigationBar (fixes #46216) (#47521)" (#47855)
parent
cf00b969
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
4 deletions
+103
-4
nav_bar.dart
packages/flutter/lib/src/cupertino/nav_bar.dart
+35
-4
nav_bar_test.dart
packages/flutter/test/cupertino/nav_bar_test.dart
+68
-0
No files found.
packages/flutter/lib/src/cupertino/nav_bar.dart
View file @
b28dd0c2
...
...
@@ -87,15 +87,24 @@ class _HeroTag {
Widget
_wrapWithBackground
(
{
Border
border
,
Color
backgroundColor
,
Brightness
brightness
,
Widget
child
,
bool
updateSystemUiOverlay
=
true
,
})
{
Widget
result
=
child
;
if
(
updateSystemUiOverlay
)
{
final
bool
darkBackground
=
backgroundColor
.
computeLuminance
()
<
0.179
;
final
SystemUiOverlayStyle
overlayStyle
=
darkBackground
?
SystemUiOverlayStyle
.
light
:
SystemUiOverlayStyle
.
dark
;
final
bool
isDark
=
backgroundColor
.
computeLuminance
()
<
0.179
;
final
Brightness
newBrightness
=
brightness
??
(
isDark
?
Brightness
.
dark
:
Brightness
.
light
);
SystemUiOverlayStyle
overlayStyle
;
switch
(
newBrightness
)
{
case
Brightness
.
dark
:
overlayStyle
=
SystemUiOverlayStyle
.
light
;
break
;
case
Brightness
.
light
:
default
:
overlayStyle
=
SystemUiOverlayStyle
.
dark
;
break
;
}
result
=
AnnotatedRegion
<
SystemUiOverlayStyle
>(
value:
overlayStyle
,
sized:
true
,
...
...
@@ -206,6 +215,7 @@ class CupertinoNavigationBar extends StatefulWidget implements ObstructingPrefer
this
.
trailing
,
this
.
border
=
_kDefaultNavBarBorder
,
this
.
backgroundColor
,
this
.
brightness
,
this
.
padding
,
this
.
actionsForegroundColor
,
this
.
transitionBetweenRoutes
=
true
,
...
...
@@ -301,6 +311,18 @@ class CupertinoNavigationBar extends StatefulWidget implements ObstructingPrefer
/// {@endtemplate}
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}
/// Padding for the contents of the navigation bar.
///
...
...
@@ -427,6 +449,7 @@ class _CupertinoNavigationBarState extends State<CupertinoNavigationBar> {
final
Widget
navBar
=
_wrapWithBackground
(
border:
widget
.
border
,
backgroundColor:
backgroundColor
,
brightness:
widget
.
brightness
,
child:
DefaultTextStyle
(
style:
CupertinoTheme
.
of
(
context
).
textTheme
.
textStyle
,
child:
_PersistentNavigationBar
(
...
...
@@ -547,6 +570,7 @@ class CupertinoSliverNavigationBar extends StatefulWidget {
this
.
trailing
,
this
.
border
=
_kDefaultNavBarBorder
,
this
.
backgroundColor
,
this
.
brightness
,
this
.
padding
,
this
.
actionsForegroundColor
,
this
.
transitionBetweenRoutes
=
true
,
...
...
@@ -620,6 +644,9 @@ class CupertinoSliverNavigationBar extends StatefulWidget {
/// {@macro flutter.cupertino.navBar.backgroundColor}
final
Color
backgroundColor
;
/// {@macro flutter.cupertino.navBar.brightness}
final
Brightness
brightness
;
/// {@macro flutter.cupertino.navBar.padding}
final
EdgeInsetsDirectional
padding
;
...
...
@@ -694,6 +721,7 @@ class _CupertinoSliverNavigationBarState extends State<CupertinoSliverNavigation
components:
components
,
userMiddle:
widget
.
middle
,
backgroundColor:
CupertinoDynamicColor
.
resolve
(
widget
.
backgroundColor
,
context
)
??
CupertinoTheme
.
of
(
context
).
barBackgroundColor
,
brightness:
widget
.
brightness
,
border:
widget
.
border
,
padding:
widget
.
padding
,
actionsForegroundColor:
actionsForegroundColor
,
...
...
@@ -715,6 +743,7 @@ class _LargeTitleNavigationBarSliverDelegate
@required
this
.
components
,
@required
this
.
userMiddle
,
@required
this
.
backgroundColor
,
@required
this
.
brightness
,
@required
this
.
border
,
@required
this
.
padding
,
@required
this
.
actionsForegroundColor
,
...
...
@@ -730,6 +759,7 @@ class _LargeTitleNavigationBarSliverDelegate
final
_NavigationBarStaticComponents
components
;
final
Widget
userMiddle
;
final
Color
backgroundColor
;
final
Brightness
brightness
;
final
Border
border
;
final
EdgeInsetsDirectional
padding
;
final
Color
actionsForegroundColor
;
...
...
@@ -760,6 +790,7 @@ class _LargeTitleNavigationBarSliverDelegate
final
Widget
navBar
=
_wrapWithBackground
(
border:
border
,
backgroundColor:
CupertinoDynamicColor
.
resolve
(
backgroundColor
,
context
),
brightness:
brightness
,
child:
DefaultTextStyle
(
style:
CupertinoTheme
.
of
(
context
).
textTheme
.
textStyle
,
child:
Stack
(
...
...
packages/flutter/test/cupertino/nav_bar_test.dart
View file @
b28dd0c2
...
...
@@ -136,6 +136,74 @@ void main() {
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
{
await
tester
.
pumpWidget
(
const
CupertinoApp
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment