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
5140376e
Unverified
Commit
5140376e
authored
Apr 13, 2021
by
Michael Debertol
Committed by
GitHub
Apr 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Calculate the system overlay style based on the AppBar background color (#75091)
parent
ed5b8feb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
10 deletions
+61
-10
app_bar.dart
packages/flutter/lib/src/material/app_bar.dart
+15
-6
app_bar_test.dart
packages/flutter/test/material/app_bar_test.dart
+43
-1
app_bar_theme_test.dart
packages/flutter/test/material/app_bar_theme_test.dart
+3
-3
No files found.
packages/flutter/lib/src/material/app_bar.dart
View file @
5140376e
...
...
@@ -660,9 +660,11 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// {@template flutter.material.appbar.systemOverlayStyle}
/// Specifies the style to use for the system overlays that overlap the AppBar.
///
/// If this property is null, then [SystemUiOverlayStyle.light] is used if the
/// overall theme is dark, [SystemUiOverlayStyle.dark] otherwise. Theme brightness
/// is defined by [ColorScheme.brightness] for [ThemeData.colorScheme].
/// This property is only used if [backwardsCompatibility] is set to false.
///
/// If this property is null, then [AppBarTheme.systemOverlayStyle] of
/// [ThemeData.appBarTheme] is used. If that is also null, an appropriate
/// [SystemUiOverlayStyle] is calculated based on the [backgroundColor].
///
/// The AppBar's descendants are built within a
/// `AnnotatedRegion<SystemUiOverlayStyle>` widget, which causes
...
...
@@ -710,6 +712,10 @@ class _AppBarState extends State<AppBar> {
Scaffold
.
of
(
context
).
openEndDrawer
();
}
SystemUiOverlayStyle
_systemOverlayStyleForBrightness
(
Brightness
brightness
)
{
return
brightness
==
Brightness
.
dark
?
SystemUiOverlayStyle
.
light
:
SystemUiOverlayStyle
.
dark
;
}
@override
Widget
build
(
BuildContext
context
)
{
assert
(!
widget
.
primary
||
debugCheckHasMediaQuery
(
context
));
...
...
@@ -953,12 +959,15 @@ class _AppBarState extends State<AppBar> {
);
}
final
Brightness
overlayStyleBrightness
=
widget
.
brightness
??
appBarTheme
.
brightness
??
colorScheme
.
brightness
;
final
SystemUiOverlayStyle
overlayStyle
=
backwardsCompatibility
?
(
overlayStyleBrightness
==
Brightness
.
dark
?
SystemUiOverlayStyle
.
light
:
SystemUiOverlayStyle
.
dark
)
?
_systemOverlayStyleForBrightness
(
widget
.
brightness
??
appBarTheme
.
brightness
??
theme
.
primaryColorBrightness
,
)
:
widget
.
systemOverlayStyle
??
appBarTheme
.
systemOverlayStyle
??
(
colorScheme
.
brightness
==
Brightness
.
dark
?
SystemUiOverlayStyle
.
light
:
SystemUiOverlayStyle
.
dark
);
??
_systemOverlayStyleForBrightness
(
ThemeData
.
estimateBrightnessForColor
(
backgroundColor
)
);
return
Semantics
(
container:
true
,
...
...
packages/flutter/test/material/app_bar_test.dart
View file @
5140376e
...
...
@@ -1953,7 +1953,7 @@ void main() {
});
testWidgets
(
'AppBar draws a dark system bar for a light background'
,
(
WidgetTester
tester
)
async
{
final
ThemeData
lightTheme
=
ThemeData
(
primary
Color:
Colors
.
whit
e
);
final
ThemeData
lightTheme
=
ThemeData
(
primary
Swatch:
Colors
.
lightBlu
e
);
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
lightTheme
,
...
...
@@ -1974,6 +1974,48 @@ void main() {
));
});
testWidgets
(
'AppBar draws a light system bar for a light theme with a dark background'
,
(
WidgetTester
tester
)
async
{
final
ThemeData
lightTheme
=
ThemeData
(
primarySwatch:
Colors
.
deepOrange
);
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
lightTheme
,
home:
Scaffold
(
appBar:
AppBar
(
backwardsCompatibility:
false
,
title:
const
Text
(
'test'
)
),
),
));
expect
(
lightTheme
.
primaryColorBrightness
,
Brightness
.
dark
);
expect
(
lightTheme
.
colorScheme
.
brightness
,
Brightness
.
light
);
expect
(
SystemChrome
.
latestStyle
,
const
SystemUiOverlayStyle
(
statusBarBrightness:
Brightness
.
dark
,
statusBarIconBrightness:
Brightness
.
light
,
));
});
testWidgets
(
'AppBar draws a dark system bar for a dark theme with a light background'
,
(
WidgetTester
tester
)
async
{
final
ThemeData
darkTheme
=
ThemeData
(
brightness:
Brightness
.
dark
,
cardColor:
Colors
.
white
);
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
darkTheme
,
home:
Scaffold
(
appBar:
AppBar
(
backwardsCompatibility:
false
,
title:
const
Text
(
'test'
)
),
),
),
);
expect
(
darkTheme
.
primaryColorBrightness
,
Brightness
.
dark
);
expect
(
darkTheme
.
colorScheme
.
brightness
,
Brightness
.
dark
);
expect
(
SystemChrome
.
latestStyle
,
const
SystemUiOverlayStyle
(
statusBarBrightness:
Brightness
.
light
,
statusBarIconBrightness:
Brightness
.
dark
,
));
});
testWidgets
(
'Changing SliverAppBar snap from true to false'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/17598
const
double
appBarHeight
=
256.0
;
...
...
packages/flutter/test/material/app_bar_theme_test.dart
View file @
5140376e
...
...
@@ -30,7 +30,7 @@ void main() {
final
RichText
actionIconText
=
_getAppBarIconRichText
(
tester
);
final
DefaultTextStyle
text
=
_getAppBarText
(
tester
);
expect
(
SystemChrome
.
latestStyle
!.
statusBarBrightness
,
SystemUiOverlayStyle
.
dark
.
statusBarBrightness
);
expect
(
SystemChrome
.
latestStyle
!.
statusBarBrightness
,
SystemUiOverlayStyle
.
light
.
statusBarBrightness
);
expect
(
widget
.
color
,
Colors
.
blue
);
expect
(
widget
.
elevation
,
4.0
);
expect
(
widget
.
shadowColor
,
Colors
.
black
);
...
...
@@ -249,7 +249,7 @@ void main() {
// - background color: ColorScheme.primary
// - foreground color: ColorScheme.onPrimary
// - actions text: style bodyText2, foreground color
// - status bar brightness:
dark
(based on color scheme brightness)
// - status bar brightness:
light
(based on color scheme brightness)
{
await
tester
.
pumpWidget
(
buildFrame
(
ThemeData
.
from
(
colorScheme:
const
ColorScheme
.
light
())));
...
...
@@ -259,7 +259,7 @@ void main() {
final
RichText
actionIconText
=
_getAppBarIconRichText
(
tester
);
final
DefaultTextStyle
text
=
_getAppBarText
(
tester
);
expect
(
SystemChrome
.
latestStyle
!.
statusBarBrightness
,
SystemUiOverlayStyle
.
dark
.
statusBarBrightness
);
expect
(
SystemChrome
.
latestStyle
!.
statusBarBrightness
,
SystemUiOverlayStyle
.
light
.
statusBarBrightness
);
expect
(
widget
.
color
,
theme
.
colorScheme
.
primary
);
expect
(
widget
.
elevation
,
4.0
);
expect
(
widget
.
shadowColor
,
Colors
.
black
);
...
...
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