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
3af97d22
Unverified
Commit
3af97d22
authored
4 years ago
by
chunhtai
Committed by
GitHub
4 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the flexible space bar to still create a rendering object even if… (#62690)
parent
6ab558d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
278 additions
and
34 deletions
+278
-34
flexible_space_bar.dart
packages/flutter/lib/src/material/flexible_space_bar.dart
+34
-34
flexible_space_bar_test.dart
packages/flutter/test/material/flexible_space_bar_test.dart
+244
-0
No files found.
packages/flutter/lib/src/material/flexible_space_bar.dart
View file @
3af97d22
...
...
@@ -303,42 +303,42 @@ class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> {
const
double
fadeEnd
=
1.0
;
assert
(
fadeStart
<=
fadeEnd
);
final
double
opacity
=
1.0
-
Interval
(
fadeStart
,
fadeEnd
).
transform
(
t
);
if
(
opacity
>
0.0
)
{
double
height
=
settings
.
maxExtent
;
// StretchMode.zoomBackground
if
(
widget
.
stretchModes
.
contains
(
StretchMode
.
zoomBackground
)
&&
constraints
.
maxHeight
>
height
)
{
height
=
constraints
.
maxHeight
;
}
children
.
add
(
Positioned
(
top:
_getCollapsePadding
(
t
,
settings
),
left:
0.0
,
right:
0.0
,
height:
height
,
child:
Opacity
(
opacity:
opacity
,
child:
widget
.
background
,
),
));
double
height
=
settings
.
maxExtent
;
// StretchMode.blurBackground
if
(
widget
.
stretchModes
.
contains
(
StretchMode
.
blurBackground
)
&&
constraints
.
maxHeight
>
settings
.
maxExtent
)
{
final
double
blurAmount
=
(
constraints
.
maxHeight
-
settings
.
maxExtent
)
/
10
;
children
.
add
(
Positioned
.
fill
(
child:
BackdropFilter
(
child:
Container
(
color:
Colors
.
transparent
,
),
filter:
ui
.
ImageFilter
.
blur
(
sigmaX:
blurAmount
,
sigmaY:
blurAmount
,
)
// StretchMode.zoomBackground
if
(
widget
.
stretchModes
.
contains
(
StretchMode
.
zoomBackground
)
&&
constraints
.
maxHeight
>
height
)
{
height
=
constraints
.
maxHeight
;
}
children
.
add
(
Positioned
(
top:
_getCollapsePadding
(
t
,
settings
),
left:
0.0
,
right:
0.0
,
height:
height
,
child:
Opacity
(
// IOS is relying on this semantics node to correctly traverse
// through the app bar when it is collapsed.
alwaysIncludeSemantics:
true
,
opacity:
opacity
,
child:
widget
.
background
,
),
));
// StretchMode.blurBackground
if
(
widget
.
stretchModes
.
contains
(
StretchMode
.
blurBackground
)
&&
constraints
.
maxHeight
>
settings
.
maxExtent
)
{
final
double
blurAmount
=
(
constraints
.
maxHeight
-
settings
.
maxExtent
)
/
10
;
children
.
add
(
Positioned
.
fill
(
child:
BackdropFilter
(
child:
Container
(
color:
Colors
.
transparent
,
),
filter:
ui
.
ImageFilter
.
blur
(
sigmaX:
blurAmount
,
sigmaY:
blurAmount
,
)
)
);
}
)
));
}
}
...
...
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/flexible_space_bar_test.dart
View file @
3af97d22
...
...
@@ -7,6 +7,8 @@
import
'package:flutter/material.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'../widgets/semantics_tester.dart'
;
void
main
(
)
{
testWidgets
(
'FlexibleSpaceBar centers title on iOS'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
...
...
@@ -119,6 +121,248 @@ void main() {
expect
(
clipRect
.
size
.
height
,
minExtent
);
});
testWidgets
(
'Collpased FlexibleSpaceBar has correct semantics'
,
(
WidgetTester
tester
)
async
{
final
SemanticsTester
semantics
=
SemanticsTester
(
tester
);
const
double
expandedHeight
=
200
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
CustomScrollView
(
slivers:
<
Widget
>[
const
SliverAppBar
(
pinned:
true
,
expandedHeight:
expandedHeight
,
title:
Text
(
'Title'
),
flexibleSpace:
FlexibleSpaceBar
(
background:
Text
(
'Expanded title'
),
),
),
SliverList
(
delegate:
SliverChildListDelegate
(
<
Widget
>[
for
(
int
i
=
0
;
i
<
50
;
i
++)
Container
(
height:
200
,
child:
Center
(
child:
Text
(
'Item
$i
'
)),
),
],
),
),
],
),
),
),
);
TestSemantics
expectedSemantics
=
TestSemantics
.
root
(
children:
<
TestSemantics
>[
TestSemantics
.
rootChild
(
id:
1
,
rect:
TestSemantics
.
fullScreen
,
children:
<
TestSemantics
>[
TestSemantics
(
id:
2
,
rect:
TestSemantics
.
fullScreen
,
children:
<
TestSemantics
>[
TestSemantics
(
id:
3
,
rect:
TestSemantics
.
fullScreen
,
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
scopesRoute
],
children:
<
TestSemantics
>[
TestSemantics
(
id:
4
,
rect:
TestSemantics
.
fullScreen
,
children:
<
TestSemantics
>[
TestSemantics
(
id:
9
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
expandedHeight
),
children:
<
TestSemantics
>[
TestSemantics
(
id:
11
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
100.0
,
20.0
),
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
isHeader
,
SemanticsFlag
.
namesRoute
],
label:
'Title'
,
textDirection:
TextDirection
.
ltr
,
),
TestSemantics
(
id:
10
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
expandedHeight
),
label:
'Expanded title'
,
textDirection:
TextDirection
.
ltr
,
),
],
),
TestSemantics
(
id:
12
,
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
hasImplicitScrolling
],
rect:
TestSemantics
.
fullScreen
,
actions:
<
SemanticsAction
>[
SemanticsAction
.
scrollUp
],
children:
<
TestSemantics
>[
TestSemantics
(
id:
5
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
200.0
),
label:
'Item 0'
,
textDirection:
TextDirection
.
ltr
,
),
TestSemantics
(
id:
6
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
200.0
),
label:
'Item 1'
,
textDirection:
TextDirection
.
ltr
,
),
TestSemantics
(
id:
7
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
200.0
),
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
isHidden
],
label:
'Item 2'
,
textDirection:
TextDirection
.
ltr
,
),
TestSemantics
(
id:
8
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
50.0
),
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
isHidden
],
label:
'Item 3'
,
textDirection:
TextDirection
.
ltr
,
),
],
),
],
),
],
),
],
),
],
),
],
);
expect
(
semantics
,
hasSemantics
(
expectedSemantics
,
ignoreTransform:
true
));
// We drag up to fully collapse the space bar.
await
tester
.
drag
(
find
.
text
(
'Item 1'
),
const
Offset
(
0
,
-
600.0
));
await
tester
.
pumpAndSettle
();
expectedSemantics
=
TestSemantics
.
root
(
children:
<
TestSemantics
>[
TestSemantics
.
rootChild
(
id:
1
,
rect:
TestSemantics
.
fullScreen
,
children:
<
TestSemantics
>[
TestSemantics
(
id:
2
,
rect:
TestSemantics
.
fullScreen
,
children:
<
TestSemantics
>[
TestSemantics
(
id:
3
,
rect:
TestSemantics
.
fullScreen
,
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
scopesRoute
],
children:
<
TestSemantics
>[
TestSemantics
(
id:
4
,
rect:
TestSemantics
.
fullScreen
,
children:
<
TestSemantics
>[
TestSemantics
(
id:
9
,
// The app bar is collapsed.
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
56.0
),
children:
<
TestSemantics
>[
TestSemantics
(
id:
11
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
100.0
,
20.0
),
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
isHeader
,
SemanticsFlag
.
namesRoute
],
label:
'Title'
,
textDirection:
TextDirection
.
ltr
,
),
// The flexible space bar still persists in the
// semantic tree even if it is collapsed.
TestSemantics
(
id:
10
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
36.0
,
800.0
,
92.0
),
label:
'Expanded title'
,
textDirection:
TextDirection
.
ltr
,
),
],
),
TestSemantics
(
id:
12
,
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
hasImplicitScrolling
],
rect:
TestSemantics
.
fullScreen
,
actions:
<
SemanticsAction
>[
SemanticsAction
.
scrollUp
,
SemanticsAction
.
scrollDown
],
children:
<
TestSemantics
>[
TestSemantics
(
id:
5
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
150.0
,
800.0
,
200.0
),
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
isHidden
],
label:
'Item 0'
,
textDirection:
TextDirection
.
ltr
,
),
TestSemantics
(
id:
6
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
200.0
),
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
isHidden
],
label:
'Item 1'
,
textDirection:
TextDirection
.
ltr
,
),
TestSemantics
(
id:
7
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
56.0
,
800.0
,
200.0
),
label:
'Item 2'
,
textDirection:
TextDirection
.
ltr
,
),
TestSemantics
(
id:
8
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
200.0
),
label:
'Item 3'
,
textDirection:
TextDirection
.
ltr
,
),
TestSemantics
(
id:
13
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
200.0
),
label:
'Item 4'
,
textDirection:
TextDirection
.
ltr
,
),
TestSemantics
(
id:
14
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
200.0
),
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
isHidden
],
label:
'Item 5'
,
textDirection:
TextDirection
.
ltr
,
),
TestSemantics
(
id:
15
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
50.0
),
flags:
<
SemanticsFlag
>[
SemanticsFlag
.
isHidden
],
label:
'Item 6'
,
textDirection:
TextDirection
.
ltr
,
),
],
),
],
),
],
),
],
),
],
),
],
);
expect
(
semantics
,
hasSemantics
(
expectedSemantics
,
ignoreTransform:
true
));
semantics
.
dispose
();
});
// This is a regression test for https://github.com/flutter/flutter/issues/14227
testWidgets
(
'FlexibleSpaceBar sets width constraints for the title'
,
(
WidgetTester
tester
)
async
{
const
double
titleFontSize
=
20.0
;
...
...
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