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
852a30b0
Unverified
Commit
852a30b0
authored
May 21, 2020
by
Ayush Bherwani
Committed by
GitHub
May 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AppBarTheme] adds centerTitle property (#57736)
parent
02b10801
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
4 deletions
+56
-4
app_bar.dart
packages/flutter/lib/src/material/app_bar.dart
+6
-3
app_bar_theme.dart
packages/flutter/lib/src/material/app_bar_theme.dart
+13
-1
app_bar_theme_test.dart
packages/flutter/test/material/app_bar_theme_test.dart
+37
-0
No files found.
packages/flutter/lib/src/material/app_bar.dart
View file @
852a30b0
...
@@ -174,8 +174,8 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
...
@@ -174,8 +174,8 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// [elevation] is specified, it must be non-negative.
/// [elevation] is specified, it must be non-negative.
///
///
/// If [backgroundColor], [elevation], [brightness], [iconTheme],
/// If [backgroundColor], [elevation], [brightness], [iconTheme],
/// [actionsIconTheme],
or [textTheme] are null, then their [AppBarTheme]
/// [actionsIconTheme],
[textTheme] or [centerTitle] are null, then their
/// values will be used. If the corresponding [AppBarTheme] property is null,
///
[AppBarTheme]
values will be used. If the corresponding [AppBarTheme] property is null,
/// then the default specified in the property's documentation will be used.
/// then the default specified in the property's documentation will be used.
///
///
/// Typically used in the [Scaffold.appBar] property.
/// Typically used in the [Scaffold.appBar] property.
...
@@ -388,7 +388,8 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
...
@@ -388,7 +388,8 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// Whether the title should be centered.
/// Whether the title should be centered.
///
///
/// Defaults to being adapted to the current [TargetPlatform].
/// If this property is null, then [ThemeData.appBarTheme.centerTitle] is used,
/// if that is also null, then value is adapted to the current [TargetPlatform].
final
bool
centerTitle
;
final
bool
centerTitle
;
/// Whether the title should be wrapped with header [Semantics].
/// Whether the title should be wrapped with header [Semantics].
...
@@ -431,6 +432,8 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
...
@@ -431,6 +432,8 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
bool
_getEffectiveCenterTitle
(
ThemeData
theme
)
{
bool
_getEffectiveCenterTitle
(
ThemeData
theme
)
{
if
(
centerTitle
!=
null
)
if
(
centerTitle
!=
null
)
return
centerTitle
;
return
centerTitle
;
if
(
theme
.
appBarTheme
.
centerTitle
!=
null
)
return
theme
.
appBarTheme
.
centerTitle
;
assert
(
theme
.
platform
!=
null
);
assert
(
theme
.
platform
!=
null
);
switch
(
theme
.
platform
)
{
switch
(
theme
.
platform
)
{
case
TargetPlatform
.
android
:
case
TargetPlatform
.
android
:
...
...
packages/flutter/lib/src/material/app_bar_theme.dart
View file @
852a30b0
...
@@ -37,6 +37,7 @@ class AppBarTheme with Diagnosticable {
...
@@ -37,6 +37,7 @@ class AppBarTheme with Diagnosticable {
this
.
iconTheme
,
this
.
iconTheme
,
this
.
actionsIconTheme
,
this
.
actionsIconTheme
,
this
.
textTheme
,
this
.
textTheme
,
this
.
centerTitle
,
});
});
/// Default value for [AppBar.brightness].
/// Default value for [AppBar.brightness].
...
@@ -69,6 +70,11 @@ class AppBarTheme with Diagnosticable {
...
@@ -69,6 +70,11 @@ class AppBarTheme with Diagnosticable {
/// If null, [AppBar] uses [ThemeData.primaryTextTheme].
/// If null, [AppBar] uses [ThemeData.primaryTextTheme].
final
TextTheme
textTheme
;
final
TextTheme
textTheme
;
/// Default value for [AppBar.centerTitle].
///
/// If null, the value is adapted to current [TargetPlatform].
final
bool
centerTitle
;
/// Creates a copy of this object with the given fields replaced with the
/// Creates a copy of this object with the given fields replaced with the
/// new values.
/// new values.
AppBarTheme
copyWith
({
AppBarTheme
copyWith
({
...
@@ -78,6 +84,7 @@ class AppBarTheme with Diagnosticable {
...
@@ -78,6 +84,7 @@ class AppBarTheme with Diagnosticable {
double
elevation
,
double
elevation
,
IconThemeData
iconTheme
,
IconThemeData
iconTheme
,
TextTheme
textTheme
,
TextTheme
textTheme
,
bool
centerTitle
,
})
{
})
{
return
AppBarTheme
(
return
AppBarTheme
(
brightness:
brightness
??
this
.
brightness
,
brightness:
brightness
??
this
.
brightness
,
...
@@ -86,6 +93,7 @@ class AppBarTheme with Diagnosticable {
...
@@ -86,6 +93,7 @@ class AppBarTheme with Diagnosticable {
iconTheme:
iconTheme
??
this
.
iconTheme
,
iconTheme:
iconTheme
??
this
.
iconTheme
,
actionsIconTheme:
actionsIconTheme
??
this
.
actionsIconTheme
,
actionsIconTheme:
actionsIconTheme
??
this
.
actionsIconTheme
,
textTheme:
textTheme
??
this
.
textTheme
,
textTheme:
textTheme
??
this
.
textTheme
,
centerTitle:
centerTitle
??
this
.
centerTitle
,
);
);
}
}
...
@@ -108,6 +116,7 @@ class AppBarTheme with Diagnosticable {
...
@@ -108,6 +116,7 @@ class AppBarTheme with Diagnosticable {
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
),
textTheme:
TextTheme
.
lerp
(
a
?.
textTheme
,
b
?.
textTheme
,
t
),
textTheme:
TextTheme
.
lerp
(
a
?.
textTheme
,
b
?.
textTheme
,
t
),
centerTitle:
t
<
0.5
?
a
?.
centerTitle
:
b
?.
centerTitle
,
);
);
}
}
...
@@ -120,6 +129,7 @@ class AppBarTheme with Diagnosticable {
...
@@ -120,6 +129,7 @@ class AppBarTheme with Diagnosticable {
iconTheme
,
iconTheme
,
actionsIconTheme
,
actionsIconTheme
,
textTheme
,
textTheme
,
centerTitle
,
);
);
}
}
...
@@ -135,7 +145,8 @@ class AppBarTheme with Diagnosticable {
...
@@ -135,7 +145,8 @@ class AppBarTheme with Diagnosticable {
&&
other
.
elevation
==
elevation
&&
other
.
elevation
==
elevation
&&
other
.
iconTheme
==
iconTheme
&&
other
.
iconTheme
==
iconTheme
&&
other
.
actionsIconTheme
==
actionsIconTheme
&&
other
.
actionsIconTheme
==
actionsIconTheme
&&
other
.
textTheme
==
textTheme
;
&&
other
.
textTheme
==
textTheme
&&
other
.
centerTitle
==
centerTitle
;
}
}
@override
@override
...
@@ -147,5 +158,6 @@ class AppBarTheme with Diagnosticable {
...
@@ -147,5 +158,6 @@ class AppBarTheme with Diagnosticable {
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
));
properties
.
add
(
DiagnosticsProperty
<
TextTheme
>(
'textTheme'
,
textTheme
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
TextTheme
>(
'textTheme'
,
textTheme
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
bool
>(
'centerTitle'
,
centerTitle
,
defaultValue:
null
));
}
}
}
}
packages/flutter/test/material/app_bar_theme_test.dart
View file @
852a30b0
...
@@ -182,6 +182,43 @@ void main() {
...
@@ -182,6 +182,43 @@ void main() {
// Default value for ThemeData.typography is Typography.material2014()
// Default value for ThemeData.typography is Typography.material2014()
expect
(
text
.
style
,
Typography
.
material2014
().
englishLike
.
bodyText2
.
merge
(
Typography
.
material2014
().
white
.
bodyText2
).
merge
(
themeData
.
primaryTextTheme
.
bodyText2
));
expect
(
text
.
style
,
Typography
.
material2014
().
englishLike
.
bodyText2
.
merge
(
Typography
.
material2014
().
white
.
bodyText2
).
merge
(
themeData
.
primaryTextTheme
.
bodyText2
));
});
});
testWidgets
(
'AppBar uses AppBarTheme.centerTitle when centerTitle is null'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
appBarTheme:
const
AppBarTheme
(
centerTitle:
true
)),
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'Title'
))),
));
final
NavigationToolbar
navToolBar
=
tester
.
widget
(
find
.
byType
(
NavigationToolbar
));
expect
(
navToolBar
.
centerMiddle
,
true
);
});
testWidgets
(
'AppBar.centerTitle takes priority over AppBarTheme.centerTitle'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
appBarTheme:
const
AppBarTheme
(
centerTitle:
true
)),
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'Title'
),
centerTitle:
false
,
)),
));
final
NavigationToolbar
navToolBar
=
tester
.
widget
(
find
.
byType
(
NavigationToolbar
));
// The AppBar.centerTitle should be used instead of AppBarTheme.centerTitle.
expect
(
navToolBar
.
centerMiddle
,
false
);
});
testWidgets
(
'AppBar.centerTitle adapts to TargetPlatform when AppBarTheme.centerTitle is null'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
platform:
TargetPlatform
.
iOS
),
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'Title'
))),
));
final
NavigationToolbar
navToolBar
=
tester
.
widget
(
find
.
byType
(
NavigationToolbar
));
// When ThemeData.platform is TargetPlatform.iOS, and AppBarTheme is null,
// the value of NavigationToolBar.centerMiddle should be true.
expect
(
navToolBar
.
centerMiddle
,
true
);
});
}
}
AppBarTheme
_appBarTheme
(
)
{
AppBarTheme
_appBarTheme
(
)
{
...
...
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