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
34a6e48a
Commit
34a6e48a
authored
7 years ago
by
xster
Committed by
GitHub
7 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
16 dp title margin when there’s no leading button (#8344)
parent
7201c8c9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
38 deletions
+60
-38
app_bar.dart
packages/flutter/lib/src/material/app_bar.dart
+8
-5
app_bar_test.dart
packages/flutter/test/material/app_bar_test.dart
+52
-33
No files found.
packages/flutter/lib/src/material/app_bar.dart
View file @
34a6e48a
...
@@ -47,7 +47,8 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
...
@@ -47,7 +47,8 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
final
bool
centerTitle
;
final
bool
centerTitle
;
static
const
double
kLeadingWidth
=
56.0
;
// So it's square with kToolbarHeight.
static
const
double
kLeadingWidth
=
56.0
;
// So it's square with kToolbarHeight.
static
const
double
kTitleLeft
=
72.0
;
// As per https://material.io/guidelines/layout/metrics-keylines.html#metrics-keylines-keylines-spacing.
static
const
double
kTitleLeftWithLeading
=
72.0
;
// As per https://material.io/guidelines/layout/metrics-keylines.html#metrics-keylines-keylines-spacing.
static
const
double
kTitleLeftWithoutLeading
=
16.0
;
@override
@override
void
performLayout
(
Size
size
)
{
void
performLayout
(
Size
size
)
{
...
@@ -69,11 +70,13 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
...
@@ -69,11 +70,13 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
}
}
if
(
hasChild
(
_ToolbarSlot
.
title
))
{
if
(
hasChild
(
_ToolbarSlot
.
title
))
{
final
double
maxWidth
=
math
.
max
(
size
.
width
-
kTitleLeft
-
actionsWidth
,
0.0
);
final
double
titleLeftMargin
=
hasChild
(
_ToolbarSlot
.
leading
)
?
kTitleLeftWithLeading
:
kTitleLeftWithoutLeading
;
final
double
maxWidth
=
math
.
max
(
size
.
width
-
titleLeftMargin
-
actionsWidth
,
0.0
);
final
BoxConstraints
constraints
=
new
BoxConstraints
.
loose
(
size
).
copyWith
(
maxWidth:
maxWidth
);
final
BoxConstraints
constraints
=
new
BoxConstraints
.
loose
(
size
).
copyWith
(
maxWidth:
maxWidth
);
final
Size
titleSize
=
layoutChild
(
_ToolbarSlot
.
title
,
constraints
);
final
Size
titleSize
=
layoutChild
(
_ToolbarSlot
.
title
,
constraints
);
final
double
titleY
=
(
size
.
height
-
titleSize
.
height
)
/
2.0
;
final
double
titleY
=
(
size
.
height
-
titleSize
.
height
)
/
2.0
;
double
titleX
=
kTitleLeft
;
double
titleX
=
titleLeftMargin
;
// If the centered title will not fit between the leading and actions
// If the centered title will not fit between the leading and actions
// widgets, then align its left or right edge with the adjacent boundary.
// widgets, then align its left or right edge with the adjacent boundary.
...
@@ -81,8 +84,8 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
...
@@ -81,8 +84,8 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
titleX
=
(
size
.
width
-
titleSize
.
width
)
/
2.0
;
titleX
=
(
size
.
width
-
titleSize
.
width
)
/
2.0
;
if
(
titleX
+
titleSize
.
width
>
size
.
width
-
actionsWidth
)
if
(
titleX
+
titleSize
.
width
>
size
.
width
-
actionsWidth
)
titleX
=
size
.
width
-
actionsWidth
-
titleSize
.
width
;
titleX
=
size
.
width
-
actionsWidth
-
titleSize
.
width
;
else
if
(
titleX
<
kTitleLeft
)
else
if
(
titleX
<
titleLeftMargin
)
titleX
=
kTitleLeft
;
titleX
=
titleLeftMargin
;
}
}
positionChild
(
_ToolbarSlot
.
title
,
new
Offset
(
titleX
,
titleY
));
positionChild
(
_ToolbarSlot
.
title
,
new
Offset
(
titleX
,
titleY
));
...
...
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/app_bar_test.dart
View file @
34a6e48a
...
@@ -13,10 +13,10 @@ void main() {
...
@@ -13,10 +13,10 @@ void main() {
theme:
new
ThemeData
(
platform:
TargetPlatform
.
android
),
theme:
new
ThemeData
(
platform:
TargetPlatform
.
android
),
home:
new
Scaffold
(
home:
new
Scaffold
(
appBar:
new
AppBar
(
appBar:
new
AppBar
(
title:
new
Text
(
'X'
)
title:
new
Text
(
'X'
)
,
)
)
,
)
)
,
)
)
,
);
);
Finder
title
=
find
.
text
(
'X'
);
Finder
title
=
find
.
text
(
'X'
);
...
@@ -32,10 +32,10 @@ void main() {
...
@@ -32,10 +32,10 @@ void main() {
theme:
new
ThemeData
(
platform:
TargetPlatform
.
iOS
),
theme:
new
ThemeData
(
platform:
TargetPlatform
.
iOS
),
home:
new
Scaffold
(
home:
new
Scaffold
(
appBar:
new
AppBar
(
appBar:
new
AppBar
(
title:
new
Text
(
'X'
)
title:
new
Text
(
'X'
)
,
)
)
,
)
)
,
)
)
,
);
);
center
=
tester
.
getCenter
(
title
);
center
=
tester
.
getCenter
(
title
);
...
@@ -51,7 +51,7 @@ void main() {
...
@@ -51,7 +51,7 @@ void main() {
home:
new
Scaffold
(
home:
new
Scaffold
(
appBar:
new
AppBar
(
appBar:
new
AppBar
(
centerTitle:
true
,
centerTitle:
true
,
title:
new
Text
(
'X'
)
title:
new
Text
(
'X'
)
,
)
)
)
)
)
)
...
@@ -65,16 +65,35 @@ void main() {
...
@@ -65,16 +65,35 @@ void main() {
expect
(
center
.
x
,
lessThan
(
400
+
size
.
width
/
2.0
));
expect
(
center
.
x
,
lessThan
(
400
+
size
.
width
/
2.0
));
});
});
testWidgets
(
'AppBar centerTitle:false title left edge is
72
.0 '
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'AppBar centerTitle:false title left edge is
16
.0 '
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
await
tester
.
pumpWidget
(
new
MaterialApp
(
new
MaterialApp
(
home:
new
Scaffold
(
home:
new
Scaffold
(
appBar:
new
AppBar
(
appBar:
new
AppBar
(
centerTitle:
false
,
centerTitle:
false
,
title:
new
Text
(
'X'
)
title:
new
Text
(
'X'
),
)
),
)
),
)
),
);
expect
(
tester
.
getTopLeft
(
find
.
text
(
'X'
)).
x
,
16.0
);
});
testWidgets
(
'AppBar centerTitle:false leading button title left edge is 72.0 '
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
MaterialApp
(
home:
new
Scaffold
(
appBar:
new
AppBar
(
centerTitle:
false
,
title:
new
Text
(
'X'
),
),
// A drawer causes a leading hamburger.
drawer:
new
Drawer
(),
),
),
);
);
expect
(
tester
.
getTopLeft
(
find
.
text
(
'X'
)).
x
,
72.0
);
expect
(
tester
.
getTopLeft
(
find
.
text
(
'X'
)).
x
,
72.0
);
...
@@ -85,7 +104,7 @@ void main() {
...
@@ -85,7 +104,7 @@ void main() {
// between the leading and actions widgets.
// between the leading and actions widgets.
Key
titleKey
=
new
UniqueKey
();
Key
titleKey
=
new
UniqueKey
();
Widget
leading
;
Widget
leading
=
new
Container
()
;
List
<
Widget
>
actions
;
List
<
Widget
>
actions
;
Widget
buildApp
()
{
Widget
buildApp
()
{
...
@@ -96,11 +115,11 @@ void main() {
...
@@ -96,11 +115,11 @@ void main() {
centerTitle:
false
,
centerTitle:
false
,
title:
new
Container
(
title:
new
Container
(
key:
titleKey
,
key:
titleKey
,
constraints:
new
BoxConstraints
.
loose
(
const
Size
(
1000.0
,
1000.0
))
constraints:
new
BoxConstraints
.
loose
(
const
Size
(
1000.0
,
1000.0
)),
),
actions:
actions
,
),
),
),
actions:
actions
)
)
);
);
}
}
...
@@ -146,11 +165,11 @@ void main() {
...
@@ -146,11 +165,11 @@ void main() {
centerTitle:
true
,
centerTitle:
true
,
title:
new
Container
(
title:
new
Container
(
key:
titleKey
,
key:
titleKey
,
constraints:
new
BoxConstraints
.
loose
(
new
Size
(
titleWidth
,
1000.0
))
constraints:
new
BoxConstraints
.
loose
(
new
Size
(
titleWidth
,
1000.0
)),
),
actions:
actions
,
),
),
),
actions:
actions
)
)
);
);
}
}
...
@@ -188,11 +207,11 @@ void main() {
...
@@ -188,11 +207,11 @@ void main() {
width:
0.0
,
width:
0.0
,
child:
new
Scaffold
(
child:
new
Scaffold
(
appBar:
new
AppBar
(
appBar:
new
AppBar
(
title:
new
Text
(
'X'
)
title:
new
Text
(
'X'
)
,
)
)
,
)
)
,
)
)
,
)
)
,
);
);
Finder
title
=
find
.
text
(
'X'
);
Finder
title
=
find
.
text
(
'X'
);
...
@@ -219,7 +238,7 @@ void main() {
...
@@ -219,7 +238,7 @@ void main() {
],
],
),
),
),
),
)
)
,
);
);
// The vertical center of the widget with key, in global coordinates.
// The vertical center of the widget with key, in global coordinates.
...
@@ -240,8 +259,8 @@ void main() {
...
@@ -240,8 +259,8 @@ void main() {
title:
new
Text
(
'X'
),
title:
new
Text
(
'X'
),
),
),
drawer:
new
Column
(),
// Doesn't really matter. Triggers a hamburger regardless.
drawer:
new
Column
(),
// Doesn't really matter. Triggers a hamburger regardless.
)
)
,
)
)
,
);
);
Finder
hamburger
=
find
.
byTooltip
(
'Open navigation menu'
);
Finder
hamburger
=
find
.
byTooltip
(
'Open navigation menu'
);
...
@@ -271,8 +290,8 @@ void main() {
...
@@ -271,8 +290,8 @@ void main() {
),
),
],
],
),
),
)
)
,
)
)
,
);
);
Finder
addButton
=
find
.
byTooltip
(
'Add'
);
Finder
addButton
=
find
.
byTooltip
(
'Add'
);
...
...
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