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
14a9b4a7
Unverified
Commit
14a9b4a7
authored
Apr 27, 2022
by
Darren Austin
Committed by
GitHub
Apr 27, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate AppBar to Material 3 (#101884)
parent
0c3c38dc
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
554 additions
and
149 deletions
+554
-149
gen_defaults.dart
dev/tools/gen_defaults/bin/gen_defaults.dart
+2
-0
app_bar_template.dart
dev/tools/gen_defaults/lib/app_bar_template.dart
+58
-0
app_bar.dart
packages/flutter/lib/src/material/app_bar.dart
+187
-30
app_bar_theme.dart
packages/flutter/lib/src/material/app_bar_theme.dart
+22
-0
material.dart
packages/flutter/lib/src/material/material.dart
+20
-13
theme_data.dart
packages/flutter/lib/src/material/theme_data.dart
+1
-0
app_bar_test.dart
packages/flutter/test/material/app_bar_test.dart
+92
-38
app_bar_theme_test.dart
packages/flutter/test/material/app_bar_theme_test.dart
+172
-68
No files found.
dev/tools/gen_defaults/bin/gen_defaults.dart
View file @
14a9b4a7
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
import
'dart:convert'
;
import
'dart:convert'
;
import
'dart:io'
;
import
'dart:io'
;
import
'package:gen_defaults/app_bar_template.dart'
;
import
'package:gen_defaults/button_template.dart'
;
import
'package:gen_defaults/button_template.dart'
;
import
'package:gen_defaults/card_template.dart'
;
import
'package:gen_defaults/card_template.dart'
;
import
'package:gen_defaults/dialog_template.dart'
;
import
'package:gen_defaults/dialog_template.dart'
;
...
@@ -78,6 +79,7 @@ Future<void> main(List<String> args) async {
...
@@ -78,6 +79,7 @@ Future<void> main(List<String> args) async {
tokens
[
'colorsLight'
]
=
_readTokenFile
(
'color_light.json'
);
tokens
[
'colorsLight'
]
=
_readTokenFile
(
'color_light.json'
);
tokens
[
'colorsDark'
]
=
_readTokenFile
(
'color_dark.json'
);
tokens
[
'colorsDark'
]
=
_readTokenFile
(
'color_dark.json'
);
AppBarTemplate
(
'
$materialLib
/app_bar.dart'
,
tokens
).
updateFile
();
ButtonTemplate
(
'md.comp.elevated-button'
,
'
$materialLib
/elevated_button.dart'
,
tokens
).
updateFile
();
ButtonTemplate
(
'md.comp.elevated-button'
,
'
$materialLib
/elevated_button.dart'
,
tokens
).
updateFile
();
ButtonTemplate
(
'md.comp.outlined-button'
,
'
$materialLib
/outlined_button.dart'
,
tokens
).
updateFile
();
ButtonTemplate
(
'md.comp.outlined-button'
,
'
$materialLib
/outlined_button.dart'
,
tokens
).
updateFile
();
ButtonTemplate
(
'md.comp.text-button'
,
'
$materialLib
/text_button.dart'
,
tokens
).
updateFile
();
ButtonTemplate
(
'md.comp.text-button'
,
'
$materialLib
/text_button.dart'
,
tokens
).
updateFile
();
...
...
dev/tools/gen_defaults/lib/app_bar_template.dart
0 → 100644
View file @
14a9b4a7
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'template.dart'
;
class
AppBarTemplate
extends
TokenTemplate
{
const
AppBarTemplate
(
super
.
fileName
,
super
.
tokens
)
:
super
(
colorSchemePrefix:
'_colors.'
,
textThemePrefix:
'_textTheme.'
,
);
@override
String
generate
()
=>
'''
// Generated version
${tokens["version"]}
class _TokenDefaultsM3 extends AppBarTheme {
_TokenDefaultsM3(this.context)
: super(
elevation:
${elevation('md.comp.top-app-bar.small.container')}
,
scrolledUnderElevation:
${elevation('md.comp.top-app-bar.small.on-scroll.container')}
,
titleSpacing: NavigationToolbar.kMiddleSpacing,
toolbarHeight:
${tokens['md.comp.top-app-bar.small.container.height']}
,
);
final BuildContext context;
late final ThemeData _theme = Theme.of(context);
late final ColorScheme _colors = _theme.colorScheme;
late final TextTheme _textTheme = _theme.textTheme;
@override
Color? get backgroundColor =>
${componentColor('md.comp.top-app-bar.small.container')}
;
@override
Color? get foregroundColor =>
${color('md.comp.top-app-bar.small.headline.color')}
;
@override
Color? get surfaceTintColor =>
${componentColor('md.comp.top-app-bar.small.container.surface-tint-layer')}
;
@override
IconThemeData? get iconTheme => IconThemeData(
color:
${componentColor('md.comp.top-app-bar.small.leading-icon')}
,
size:
${tokens['md.comp.top-app-bar.small.leading-icon.size']}
,
);
@override
IconThemeData? get actionsIconTheme => IconThemeData(
color:
${componentColor('md.comp.top-app-bar.small.trailing-icon')}
,
size:
${tokens['md.comp.top-app-bar.small.trailing-icon.size']}
,
);
@override
TextStyle? get toolbarTextStyle => _textTheme.bodyText2;
@override
TextStyle? get titleTextStyle =>
${textStyle('md.comp.top-app-bar.small.headline')}
;
}'''
;
}
packages/flutter/lib/src/material/app_bar.dart
View file @
14a9b4a7
This diff is collapsed.
Click to expand it.
packages/flutter/lib/src/material/app_bar_theme.dart
View file @
14a9b4a7
...
@@ -37,7 +37,9 @@ class AppBarTheme with Diagnosticable {
...
@@ -37,7 +37,9 @@ class AppBarTheme with Diagnosticable {
Color
?
backgroundColor
,
Color
?
backgroundColor
,
this
.
foregroundColor
,
this
.
foregroundColor
,
this
.
elevation
,
this
.
elevation
,
this
.
scrolledUnderElevation
,
this
.
shadowColor
,
this
.
shadowColor
,
this
.
surfaceTintColor
,
this
.
shape
,
this
.
shape
,
this
.
iconTheme
,
this
.
iconTheme
,
this
.
actionsIconTheme
,
this
.
actionsIconTheme
,
...
@@ -121,10 +123,18 @@ class AppBarTheme with Diagnosticable {
...
@@ -121,10 +123,18 @@ class AppBarTheme with Diagnosticable {
/// descendant [AppBar] widgets.
/// descendant [AppBar] widgets.
final
double
?
elevation
;
final
double
?
elevation
;
/// Overrides the default value of [AppBar.scrolledUnderElevation] in all
/// descendant [AppBar] widgets.
final
double
?
scrolledUnderElevation
;
/// Overrides the default value for [AppBar.shadowColor] in all
/// Overrides the default value for [AppBar.shadowColor] in all
/// descendant widgets.
/// descendant widgets.
final
Color
?
shadowColor
;
final
Color
?
shadowColor
;
/// Overrides the default value for [AppBar.surfaceTintColor] in all
/// descendant widgets.
final
Color
?
surfaceTintColor
;
/// Overrides the default value for [AppBar.shape] in all
/// Overrides the default value for [AppBar.shape] in all
/// descendant widgets.
/// descendant widgets.
final
ShapeBorder
?
shape
;
final
ShapeBorder
?
shape
;
...
@@ -237,7 +247,9 @@ class AppBarTheme with Diagnosticable {
...
@@ -237,7 +247,9 @@ class AppBarTheme with Diagnosticable {
Color
?
backgroundColor
,
Color
?
backgroundColor
,
Color
?
foregroundColor
,
Color
?
foregroundColor
,
double
?
elevation
,
double
?
elevation
,
double
?
scrolledUnderElevation
,
Color
?
shadowColor
,
Color
?
shadowColor
,
Color
?
surfaceTintColor
,
ShapeBorder
?
shape
,
ShapeBorder
?
shape
,
IconThemeData
?
iconTheme
,
IconThemeData
?
iconTheme
,
@Deprecated
(
@Deprecated
(
...
@@ -266,7 +278,9 @@ class AppBarTheme with Diagnosticable {
...
@@ -266,7 +278,9 @@ class AppBarTheme with Diagnosticable {
backgroundColor:
backgroundColor
??
color
??
this
.
backgroundColor
,
backgroundColor:
backgroundColor
??
color
??
this
.
backgroundColor
,
foregroundColor:
foregroundColor
??
this
.
foregroundColor
,
foregroundColor:
foregroundColor
??
this
.
foregroundColor
,
elevation:
elevation
??
this
.
elevation
,
elevation:
elevation
??
this
.
elevation
,
scrolledUnderElevation:
scrolledUnderElevation
??
this
.
scrolledUnderElevation
,
shadowColor:
shadowColor
??
this
.
shadowColor
,
shadowColor:
shadowColor
??
this
.
shadowColor
,
surfaceTintColor:
surfaceTintColor
??
this
.
surfaceTintColor
,
shape:
shape
??
this
.
shape
,
shape:
shape
??
this
.
shape
,
iconTheme:
iconTheme
??
this
.
iconTheme
,
iconTheme:
iconTheme
??
this
.
iconTheme
,
actionsIconTheme:
actionsIconTheme
??
this
.
actionsIconTheme
,
actionsIconTheme:
actionsIconTheme
??
this
.
actionsIconTheme
,
...
@@ -298,7 +312,9 @@ class AppBarTheme with Diagnosticable {
...
@@ -298,7 +312,9 @@ class AppBarTheme with Diagnosticable {
backgroundColor:
Color
.
lerp
(
a
?.
backgroundColor
,
b
?.
backgroundColor
,
t
),
backgroundColor:
Color
.
lerp
(
a
?.
backgroundColor
,
b
?.
backgroundColor
,
t
),
foregroundColor:
Color
.
lerp
(
a
?.
foregroundColor
,
b
?.
foregroundColor
,
t
),
foregroundColor:
Color
.
lerp
(
a
?.
foregroundColor
,
b
?.
foregroundColor
,
t
),
elevation:
lerpDouble
(
a
?.
elevation
,
b
?.
elevation
,
t
),
elevation:
lerpDouble
(
a
?.
elevation
,
b
?.
elevation
,
t
),
scrolledUnderElevation:
lerpDouble
(
a
?.
scrolledUnderElevation
,
b
?.
scrolledUnderElevation
,
t
),
shadowColor:
Color
.
lerp
(
a
?.
shadowColor
,
b
?.
shadowColor
,
t
),
shadowColor:
Color
.
lerp
(
a
?.
shadowColor
,
b
?.
shadowColor
,
t
),
surfaceTintColor:
Color
.
lerp
(
a
?.
surfaceTintColor
,
b
?.
surfaceTintColor
,
t
),
shape:
ShapeBorder
.
lerp
(
a
?.
shape
,
b
?.
shape
,
t
),
shape:
ShapeBorder
.
lerp
(
a
?.
shape
,
b
?.
shape
,
t
),
iconTheme:
IconThemeData
.
lerp
(
a
?.
iconTheme
,
b
?.
iconTheme
,
t
),
iconTheme:
IconThemeData
.
lerp
(
a
?.
iconTheme
,
b
?.
iconTheme
,
t
),
actionsIconTheme:
IconThemeData
.
lerp
(
a
?.
actionsIconTheme
,
b
?.
actionsIconTheme
,
t
),
actionsIconTheme:
IconThemeData
.
lerp
(
a
?.
actionsIconTheme
,
b
?.
actionsIconTheme
,
t
),
...
@@ -319,7 +335,9 @@ class AppBarTheme with Diagnosticable {
...
@@ -319,7 +335,9 @@ class AppBarTheme with Diagnosticable {
backgroundColor
,
backgroundColor
,
foregroundColor
,
foregroundColor
,
elevation
,
elevation
,
scrolledUnderElevation
,
shadowColor
,
shadowColor
,
surfaceTintColor
,
shape
,
shape
,
iconTheme
,
iconTheme
,
actionsIconTheme
,
actionsIconTheme
,
...
@@ -344,7 +362,9 @@ class AppBarTheme with Diagnosticable {
...
@@ -344,7 +362,9 @@ class AppBarTheme with Diagnosticable {
&&
other
.
backgroundColor
==
backgroundColor
&&
other
.
backgroundColor
==
backgroundColor
&&
other
.
foregroundColor
==
foregroundColor
&&
other
.
foregroundColor
==
foregroundColor
&&
other
.
elevation
==
elevation
&&
other
.
elevation
==
elevation
&&
other
.
scrolledUnderElevation
==
scrolledUnderElevation
&&
other
.
shadowColor
==
shadowColor
&&
other
.
shadowColor
==
shadowColor
&&
other
.
surfaceTintColor
==
surfaceTintColor
&&
other
.
shape
==
shape
&&
other
.
shape
==
shape
&&
other
.
iconTheme
==
iconTheme
&&
other
.
iconTheme
==
iconTheme
&&
other
.
actionsIconTheme
==
actionsIconTheme
&&
other
.
actionsIconTheme
==
actionsIconTheme
...
@@ -365,7 +385,9 @@ class AppBarTheme with Diagnosticable {
...
@@ -365,7 +385,9 @@ class AppBarTheme with Diagnosticable {
properties
.
add
(
ColorProperty
(
'backgroundColor'
,
backgroundColor
,
defaultValue:
null
));
properties
.
add
(
ColorProperty
(
'backgroundColor'
,
backgroundColor
,
defaultValue:
null
));
properties
.
add
(
ColorProperty
(
'foregroundColor'
,
foregroundColor
,
defaultValue:
null
));
properties
.
add
(
ColorProperty
(
'foregroundColor'
,
foregroundColor
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
double
>(
'elevation'
,
elevation
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
double
>(
'elevation'
,
elevation
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
double
>(
'scrolledUnderElevation'
,
scrolledUnderElevation
,
defaultValue:
null
));
properties
.
add
(
ColorProperty
(
'shadowColor'
,
shadowColor
,
defaultValue:
null
));
properties
.
add
(
ColorProperty
(
'shadowColor'
,
shadowColor
,
defaultValue:
null
));
properties
.
add
(
ColorProperty
(
'surfaceTintColor'
,
surfaceTintColor
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
ShapeBorder
>(
'shape'
,
shape
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
ShapeBorder
>(
'shape'
,
shape
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
IconThemeData
>(
'iconTheme'
,
iconTheme
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
IconThemeData
>(
'iconTheme'
,
iconTheme
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
IconThemeData
>(
'actionsIconTheme'
,
actionsIconTheme
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
IconThemeData
>(
'actionsIconTheme'
,
actionsIconTheme
,
defaultValue:
null
));
...
...
packages/flutter/lib/src/material/material.dart
View file @
14a9b4a7
...
@@ -400,6 +400,9 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
...
@@ -400,6 +400,9 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
final
ThemeData
theme
=
Theme
.
of
(
context
);
final
ThemeData
theme
=
Theme
.
of
(
context
);
final
Color
?
backgroundColor
=
_getBackgroundColor
(
context
);
final
Color
?
backgroundColor
=
_getBackgroundColor
(
context
);
final
Color
?
modelShadowColor
=
widget
.
shadowColor
??
(
theme
.
useMaterial3
?
null
:
theme
.
shadowColor
);
// If no shadow color is specified, use 0 for elevation in the model so a drop shadow won't be painted.
final
double
modelElevation
=
modelShadowColor
!=
null
?
widget
.
elevation
:
0
;
assert
(
assert
(
backgroundColor
!=
null
||
widget
.
type
==
MaterialType
.
transparency
,
backgroundColor
!=
null
||
widget
.
type
==
MaterialType
.
transparency
,
'If Material type is not MaterialType.transparency, a color must '
'If Material type is not MaterialType.transparency, a color must '
...
@@ -449,9 +452,9 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
...
@@ -449,9 +452,9 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
duration:
widget
.
animationDuration
,
duration:
widget
.
animationDuration
,
shape:
BoxShape
.
rectangle
,
shape:
BoxShape
.
rectangle
,
clipBehavior:
widget
.
clipBehavior
,
clipBehavior:
widget
.
clipBehavior
,
elevation:
widget
.
e
levation
,
elevation:
modelE
levation
,
color:
color
,
color:
color
,
shadowColor:
widget
.
shadowColor
??
(
theme
.
useMaterial3
?
const
Color
(
0x00000000
)
:
theme
.
shadowColor
),
shadowColor:
modelShadowColor
??
const
Color
(
0x00000000
),
animateColor:
false
,
animateColor:
false
,
child:
contents
,
child:
contents
,
);
);
...
@@ -476,7 +479,7 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
...
@@ -476,7 +479,7 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
clipBehavior:
widget
.
clipBehavior
,
clipBehavior:
widget
.
clipBehavior
,
elevation:
widget
.
elevation
,
elevation:
widget
.
elevation
,
color:
backgroundColor
!,
color:
backgroundColor
!,
shadowColor:
widget
.
shadowColor
??
(
theme
.
useMaterial3
?
const
Color
(
0x00000000
)
:
theme
.
shadowColor
)
,
shadowColor:
modelShadowColor
,
surfaceTintColor:
widget
.
surfaceTintColor
,
surfaceTintColor:
widget
.
surfaceTintColor
,
child:
contents
,
child:
contents
,
);
);
...
@@ -742,8 +745,7 @@ class _MaterialInterior extends ImplicitlyAnimatedWidget {
...
@@ -742,8 +745,7 @@ class _MaterialInterior extends ImplicitlyAnimatedWidget {
assert
(
shape
!=
null
),
assert
(
shape
!=
null
),
assert
(
clipBehavior
!=
null
),
assert
(
clipBehavior
!=
null
),
assert
(
elevation
!=
null
&&
elevation
>=
0.0
),
assert
(
elevation
!=
null
&&
elevation
>=
0.0
),
assert
(
color
!=
null
),
assert
(
color
!=
null
);
assert
(
shadowColor
!=
null
);
/// The widget below this widget in the tree.
/// The widget below this widget in the tree.
///
///
...
@@ -777,7 +779,7 @@ class _MaterialInterior extends ImplicitlyAnimatedWidget {
...
@@ -777,7 +779,7 @@ class _MaterialInterior extends ImplicitlyAnimatedWidget {
final
Color
color
;
final
Color
color
;
/// The target shadow color.
/// The target shadow color.
final
Color
shadowColor
;
final
Color
?
shadowColor
;
/// The target surface tint color.
/// The target surface tint color.
final
Color
?
surfaceTintColor
;
final
Color
?
surfaceTintColor
;
...
@@ -808,11 +810,13 @@ class _MaterialInteriorState extends AnimatedWidgetBaseState<_MaterialInterior>
...
@@ -808,11 +810,13 @@ class _MaterialInteriorState extends AnimatedWidgetBaseState<_MaterialInterior>
widget
.
elevation
,
widget
.
elevation
,
(
dynamic
value
)
=>
Tween
<
double
>(
begin:
value
as
double
),
(
dynamic
value
)
=>
Tween
<
double
>(
begin:
value
as
double
),
)
as
Tween
<
double
>?;
)
as
Tween
<
double
>?;
_shadowColor
=
visitor
(
_shadowColor
=
widget
.
shadowColor
!=
null
?
visitor
(
_shadowColor
,
_shadowColor
,
widget
.
shadowColor
,
widget
.
shadowColor
,
(
dynamic
value
)
=>
ColorTween
(
begin:
value
as
Color
),
(
dynamic
value
)
=>
ColorTween
(
begin:
value
as
Color
),
)
as
ColorTween
?;
)
as
ColorTween
?
:
null
;
_surfaceTintColor
=
widget
.
surfaceTintColor
!=
null
_surfaceTintColor
=
widget
.
surfaceTintColor
!=
null
?
visitor
(
?
visitor
(
_surfaceTintColor
,
_surfaceTintColor
,
...
@@ -834,15 +838,18 @@ class _MaterialInteriorState extends AnimatedWidgetBaseState<_MaterialInterior>
...
@@ -834,15 +838,18 @@ class _MaterialInteriorState extends AnimatedWidgetBaseState<_MaterialInterior>
final
Color
color
=
Theme
.
of
(
context
).
useMaterial3
final
Color
color
=
Theme
.
of
(
context
).
useMaterial3
?
ElevationOverlay
.
applySurfaceTint
(
widget
.
color
,
_surfaceTintColor
?.
evaluate
(
animation
),
elevation
)
?
ElevationOverlay
.
applySurfaceTint
(
widget
.
color
,
_surfaceTintColor
?.
evaluate
(
animation
),
elevation
)
:
ElevationOverlay
.
applyOverlay
(
context
,
widget
.
color
,
elevation
);
:
ElevationOverlay
.
applyOverlay
(
context
,
widget
.
color
,
elevation
);
// If no shadow color is specified, use 0 for elevation in the model so a drop shadow won't be painted.
final
double
modelElevation
=
widget
.
shadowColor
!=
null
?
elevation
:
0
;
final
Color
shadowColor
=
_shadowColor
?.
evaluate
(
animation
)
??
const
Color
(
0x00000000
);
return
PhysicalShape
(
return
PhysicalShape
(
clipper:
ShapeBorderClipper
(
clipper:
ShapeBorderClipper
(
shape:
shape
,
shape:
shape
,
textDirection:
Directionality
.
maybeOf
(
context
),
textDirection:
Directionality
.
maybeOf
(
context
),
),
),
clipBehavior:
widget
.
clipBehavior
,
clipBehavior:
widget
.
clipBehavior
,
elevation:
e
levation
,
elevation:
modelE
levation
,
color:
color
,
color:
color
,
shadowColor:
_shadowColor
!.
evaluate
(
animation
)!
,
shadowColor:
shadowColor
,
child:
_ShapeBorderPaint
(
child:
_ShapeBorderPaint
(
shape:
shape
,
shape:
shape
,
borderOnForeground:
widget
.
borderOnForeground
,
borderOnForeground:
widget
.
borderOnForeground
,
...
...
packages/flutter/lib/src/material/theme_data.dart
View file @
14a9b4a7
...
@@ -1203,6 +1203,7 @@ class ThemeData with Diagnosticable {
...
@@ -1203,6 +1203,7 @@ class ThemeData with Diagnosticable {
/// Components that have been migrated to Material 3 are:
/// Components that have been migrated to Material 3 are:
///
///
/// * [AlertDialog]
/// * [AlertDialog]
/// * [AppBar]
/// * [Card]
/// * [Card]
/// * [Dialog]
/// * [Dialog]
/// * [ElevatedButton]
/// * [ElevatedButton]
...
...
packages/flutter/test/material/app_bar_test.dart
View file @
14a9b4a7
...
@@ -954,6 +954,8 @@ void main() {
...
@@ -954,6 +954,8 @@ void main() {
});
});
testWidgets
(
'AppBar uses the specified elevation or defaults to 4.0'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'AppBar uses the specified elevation or defaults to 4.0'
,
(
WidgetTester
tester
)
async
{
final
bool
useMaterial3
=
ThemeData
().
useMaterial3
;
Widget
buildAppBar
([
double
?
elevation
])
{
Widget
buildAppBar
([
double
?
elevation
])
{
return
MaterialApp
(
return
MaterialApp
(
home:
Scaffold
(
home:
Scaffold
(
...
@@ -967,15 +969,48 @@ void main() {
...
@@ -967,15 +969,48 @@ void main() {
matching:
find
.
byType
(
Material
),
matching:
find
.
byType
(
Material
),
));
));
// Default elevation should be
_AppBarState._defaultElevation = 4.0
// Default elevation should be
used for the material.
await
tester
.
pumpWidget
(
buildAppBar
());
await
tester
.
pumpWidget
(
buildAppBar
());
expect
(
getMaterial
().
elevation
,
4.0
);
expect
(
getMaterial
().
elevation
,
useMaterial3
?
0
:
4
);
// AppBar should use the specified elevation.
// AppBar should use the specified elevation.
await
tester
.
pumpWidget
(
buildAppBar
(
8.0
));
await
tester
.
pumpWidget
(
buildAppBar
(
8.0
));
expect
(
getMaterial
().
elevation
,
8.0
);
expect
(
getMaterial
().
elevation
,
8.0
);
});
});
testWidgets
(
'scrolledUnderElevation'
,
(
WidgetTester
tester
)
async
{
Widget
buildAppBar
({
double
?
elevation
,
double
?
scrolledUnderElevation
})
{
return
MaterialApp
(
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'Title'
),
elevation:
elevation
,
scrolledUnderElevation:
scrolledUnderElevation
,
),
body:
ListView
.
builder
(
itemCount:
100
,
itemBuilder:
(
BuildContext
context
,
int
index
)
=>
ListTile
(
title:
Text
(
'Item
$index
'
)),
),
),
);
}
Material
getMaterial
()
=>
tester
.
widget
<
Material
>(
find
.
descendant
(
of:
find
.
byType
(
AppBar
),
matching:
find
.
byType
(
Material
),
));
await
tester
.
pumpWidget
(
buildAppBar
(
elevation:
2
,
scrolledUnderElevation:
10
));
// Starts with the base elevation.
expect
(
getMaterial
().
elevation
,
2
);
await
tester
.
fling
(
find
.
text
(
'Item 2'
),
const
Offset
(
0.0
,
-
600.0
),
2000.0
);
await
tester
.
pumpAndSettle
();
// After scrolling it should be the scrolledUnderElevation.
expect
(
getMaterial
().
elevation
,
10
);
});
group
(
'SliverAppBar elevation'
,
()
{
group
(
'SliverAppBar elevation'
,
()
{
Widget
buildSliverAppBar
(
bool
forceElevated
,
{
double
?
elevation
,
double
?
themeElevation
})
{
Widget
buildSliverAppBar
(
bool
forceElevated
,
{
double
?
elevation
,
double
?
themeElevation
})
{
return
MaterialApp
(
return
MaterialApp
(
...
@@ -996,15 +1031,16 @@ void main() {
...
@@ -996,15 +1031,16 @@ void main() {
// Regression test for https://github.com/flutter/flutter/issues/59158.
// Regression test for https://github.com/flutter/flutter/issues/59158.
AppBar
getAppBar
()
=>
tester
.
widget
<
AppBar
>(
find
.
byType
(
AppBar
));
AppBar
getAppBar
()
=>
tester
.
widget
<
AppBar
>(
find
.
byType
(
AppBar
));
Material
getMaterial
()
=>
tester
.
widget
<
Material
>(
find
.
byType
(
Material
));
Material
getMaterial
()
=>
tester
.
widget
<
Material
>(
find
.
byType
(
Material
));
final
bool
useMaterial3
=
ThemeData
().
useMaterial3
;
// When forceElevated is off, SliverAppBar should not be elevated.
// When forceElevated is off, SliverAppBar should not be elevated.
await
tester
.
pumpWidget
(
buildSliverAppBar
(
false
));
await
tester
.
pumpWidget
(
buildSliverAppBar
(
false
));
expect
(
getMaterial
().
elevation
,
0.0
);
expect
(
getMaterial
().
elevation
,
0.0
);
// Default elevation should be
_AppBarState._defaultElevation = 4.0, and
// Default elevation should be
used by the material, but
// the AppBar's elevation should not be specified by SliverAppBar.
// the AppBar's elevation should not be specified by SliverAppBar.
await
tester
.
pumpWidget
(
buildSliverAppBar
(
true
));
await
tester
.
pumpWidget
(
buildSliverAppBar
(
true
));
expect
(
getMaterial
().
elevation
,
4.0
);
expect
(
getMaterial
().
elevation
,
useMaterial3
?
0.0
:
4.0
);
expect
(
getAppBar
().
elevation
,
null
);
expect
(
getAppBar
().
elevation
,
null
);
// SliverAppBar should use the specified elevation.
// SliverAppBar should use the specified elevation.
...
@@ -1312,6 +1348,8 @@ void main() {
...
@@ -1312,6 +1348,8 @@ void main() {
final
Key
key
=
UniqueKey
();
final
Key
key
=
UniqueKey
();
await
tester
.
pumpWidget
(
await
tester
.
pumpWidget
(
MaterialApp
(
MaterialApp
(
// Test was designed against InkSplash so need to make sure that is used.
theme:
ThemeData
(
splashFactory:
InkSplash
.
splashFactory
),
home:
Center
(
home:
Center
(
child:
AppBar
(
child:
AppBar
(
title:
const
Text
(
'Abc'
),
title:
const
Text
(
'Abc'
),
...
@@ -2005,44 +2043,55 @@ void main() {
...
@@ -2005,44 +2043,55 @@ void main() {
));
));
});
});
testWidgets
(
'
AppBar draws a light system bar for a light theme with a dark background
'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'
Default system bar brightness based on AppBar background color brightness.
'
,
(
WidgetTester
tester
)
async
{
final
ThemeData
lightTheme
=
ThemeData
(
primarySwatch:
Colors
.
deepOrange
);
Widget
buildAppBar
(
ThemeData
theme
)
{
await
tester
.
pumpWidget
(
MaterialApp
(
return
MaterialApp
(
theme:
lightT
heme
,
theme:
t
heme
,
home:
Scaffold
(
home:
Scaffold
(
appBar:
AppBar
(
appBar:
AppBar
(
title:
const
Text
(
'Title'
)),
title:
const
Text
(
'test'
),
),
),
);
}
// Using a light theme.
{
await
tester
.
pumpWidget
(
buildAppBar
(
ThemeData
.
from
(
colorScheme:
const
ColorScheme
.
light
())));
final
Material
appBarMaterial
=
tester
.
widget
<
Material
>(
find
.
descendant
(
of:
find
.
byType
(
AppBar
),
matching:
find
.
byType
(
Material
),
),
),
));
);
final
Brightness
appBarBrightness
=
ThemeData
.
estimateBrightnessForColor
(
appBarMaterial
.
color
!);
final
Brightness
onAppBarBrightness
=
appBarBrightness
==
Brightness
.
light
?
Brightness
.
dark
:
Brightness
.
light
;
expect
(
lightTheme
.
primaryColorBrightness
,
Brightness
.
dark
);
expect
(
SystemChrome
.
latestStyle
,
SystemUiOverlayStyle
(
expect
(
lightTheme
.
colorScheme
.
brightness
,
Brightness
.
light
);
statusBarBrightness:
appBarBrightness
,
expect
(
SystemChrome
.
latestStyle
,
const
SystemUiOverlayStyle
(
statusBarIconBrightness:
onAppBarBrightness
,
statusBarBrightness:
Brightness
.
dark
,
statusBarIconBrightness:
Brightness
.
light
,
));
));
});
}
testWidgets
(
'AppBar draws a dark system bar for a dark theme with a light background'
,
(
WidgetTester
tester
)
async
{
// Using a dark theme.
final
ThemeData
darkTheme
=
ThemeData
(
brightness:
Brightness
.
dark
,
cardColor:
Colors
.
white
);
{
await
tester
.
pumpWidget
(
await
tester
.
pumpWidget
(
buildAppBar
(
ThemeData
.
from
(
colorScheme:
const
ColorScheme
.
dark
())));
MaterialApp
(
final
Material
appBarMaterial
=
tester
.
widget
<
Material
>(
theme:
darkTheme
,
find
.
descendant
(
home:
Scaffold
(
of:
find
.
byType
(
AppBar
),
appBar:
AppBar
(
matching:
find
.
byType
(
Material
),
title:
const
Text
(
'test'
),
),
),
),
),
);
);
final
Brightness
appBarBrightness
=
ThemeData
.
estimateBrightnessForColor
(
appBarMaterial
.
color
!);
final
Brightness
onAppBarBrightness
=
appBarBrightness
==
Brightness
.
light
?
Brightness
.
dark
:
Brightness
.
light
;
expect
(
darkTheme
.
primaryColorBrightness
,
Brightness
.
dark
);
expect
(
SystemChrome
.
latestStyle
,
SystemUiOverlayStyle
(
expect
(
darkTheme
.
colorScheme
.
brightness
,
Brightness
.
dark
);
statusBarBrightness:
appBarBrightness
,
expect
(
SystemChrome
.
latestStyle
,
const
SystemUiOverlayStyle
(
statusBarIconBrightness:
onAppBarBrightness
,
statusBarBrightness:
Brightness
.
light
,
statusBarIconBrightness:
Brightness
.
dark
,
));
));
}
});
});
testWidgets
(
'Changing SliverAppBar snap from true to false'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Changing SliverAppBar snap from true to false'
,
(
WidgetTester
tester
)
async
{
...
@@ -2207,6 +2256,8 @@ void main() {
...
@@ -2207,6 +2256,8 @@ void main() {
Widget
buildFrame
()
{
Widget
buildFrame
()
{
return
MaterialApp
(
return
MaterialApp
(
// Test designed against 2014 font sizes.
theme:
ThemeData
(
textTheme:
Typography
.
englishLike2014
),
home:
Builder
(
home:
Builder
(
builder:
(
BuildContext
context
)
{
builder:
(
BuildContext
context
)
{
return
MediaQuery
(
return
MediaQuery
(
...
@@ -2245,6 +2296,8 @@ void main() {
...
@@ -2245,6 +2296,8 @@ void main() {
Widget
buildFrame
()
{
Widget
buildFrame
()
{
return
MaterialApp
(
return
MaterialApp
(
// Test designed against 2014 font sizes.
theme:
ThemeData
(
textTheme:
Typography
.
englishLike2014
),
home:
Builder
(
home:
Builder
(
builder:
(
BuildContext
context
)
{
builder:
(
BuildContext
context
)
{
return
Directionality
(
return
Directionality
(
...
@@ -2536,6 +2589,7 @@ void main() {
...
@@ -2536,6 +2589,7 @@ void main() {
await
tester
.
pumpWidget
(
await
tester
.
pumpWidget
(
MaterialApp
(
MaterialApp
(
theme:
ThemeData
.
light
().
copyWith
(
theme:
ThemeData
.
light
().
copyWith
(
useMaterial3:
false
,
appBarTheme:
const
AppBarTheme
(
appBarTheme:
const
AppBarTheme
(
backwardsCompatibility:
false
,
backwardsCompatibility:
false
,
),
),
...
...
packages/flutter/test/material/app_bar_theme_test.dart
View file @
14a9b4a7
This diff is collapsed.
Click to expand it.
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