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
fe046476
Unverified
Commit
fe046476
authored
May 25, 2022
by
Kate Lovett
Committed by
GitHub
May 25, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include forceElevated for scrolledUnder in new SliverAppBar variants (#104536)
parent
2e7cea6d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
169 additions
and
2 deletions
+169
-2
app_bar.dart
packages/flutter/lib/src/material/app_bar.dart
+2
-2
nested_scroll_view_test.dart
packages/flutter/test/widgets/nested_scroll_view_test.dart
+167
-0
No files found.
packages/flutter/lib/src/material/app_bar.dart
View file @
fe046476
...
@@ -1284,7 +1284,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
...
@@ -1284,7 +1284,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
final
double
extraToolbarHeight
=
math
.
max
(
minExtent
-
_bottomHeight
-
topPadding
-
(
toolbarHeight
??
kToolbarHeight
),
0.0
);
final
double
extraToolbarHeight
=
math
.
max
(
minExtent
-
_bottomHeight
-
topPadding
-
(
toolbarHeight
??
kToolbarHeight
),
0.0
);
final
double
visibleToolbarHeight
=
visibleMainHeight
-
_bottomHeight
-
extraToolbarHeight
;
final
double
visibleToolbarHeight
=
visibleMainHeight
-
_bottomHeight
-
extraToolbarHeight
;
final
bool
isScrolledUnder
=
overlapsContent
||
(
pinned
&&
shrinkOffset
>
maxExtent
-
minExtent
);
final
bool
isScrolledUnder
=
overlapsContent
||
forceElevated
||
(
pinned
&&
shrinkOffset
>
maxExtent
-
minExtent
);
final
bool
isPinnedWithOpacityFade
=
pinned
&&
floating
&&
bottom
!=
null
&&
extraToolbarHeight
==
0.0
;
final
bool
isPinnedWithOpacityFade
=
pinned
&&
floating
&&
bottom
!=
null
&&
extraToolbarHeight
==
0.0
;
final
double
toolbarOpacity
=
!
pinned
||
isPinnedWithOpacityFade
final
double
toolbarOpacity
=
!
pinned
||
isPinnedWithOpacityFade
?
clampDouble
(
visibleToolbarHeight
/
(
toolbarHeight
??
kToolbarHeight
),
0.0
,
1.0
)
?
clampDouble
(
visibleToolbarHeight
/
(
toolbarHeight
??
kToolbarHeight
),
0.0
,
1.0
)
...
@@ -1308,7 +1308,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
...
@@ -1308,7 +1308,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
)
)
:
flexibleSpace
,
:
flexibleSpace
,
bottom:
bottom
,
bottom:
bottom
,
elevation:
forceElevated
||
isScrolledUnder
?
elevation
:
0.0
,
elevation:
isScrolledUnder
?
elevation
:
0.0
,
scrolledUnderElevation:
scrolledUnderElevation
,
scrolledUnderElevation:
scrolledUnderElevation
,
shadowColor:
shadowColor
,
shadowColor:
shadowColor
,
surfaceTintColor:
surfaceTintColor
,
surfaceTintColor:
surfaceTintColor
,
...
...
packages/flutter/test/widgets/nested_scroll_view_test.dart
View file @
fe046476
...
@@ -2552,8 +2552,175 @@ void main() {
...
@@ -2552,8 +2552,175 @@ void main() {
expect
(
scrollStarted
,
2
);
expect
(
scrollStarted
,
2
);
expect
(
scrollEnded
,
2
);
expect
(
scrollEnded
,
2
);
});
});
testWidgets
(
'SliverAppBar.medium collapses in NestedScrollView'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
NestedScrollViewState
>
nestedScrollView
=
GlobalKey
();
const
double
collapsedAppBarHeight
=
64
;
const
double
expandedAppBarHeight
=
112
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
NestedScrollView
(
key:
nestedScrollView
,
headerSliverBuilder:
(
BuildContext
context
,
bool
innerBoxIsScrolled
)
{
return
<
Widget
>[
SliverOverlapAbsorber
(
handle:
NestedScrollView
.
sliverOverlapAbsorberHandleFor
(
context
),
sliver:
SliverAppBar
.
medium
(
title:
const
Text
(
'AppBar Title'
),
),
),
];
},
body:
Builder
(
builder:
(
BuildContext
context
)
{
return
CustomScrollView
(
slivers:
<
Widget
>[
SliverOverlapInjector
(
handle:
NestedScrollView
.
sliverOverlapAbsorberHandleFor
(
context
)),
SliverFixedExtentList
(
itemExtent:
50.0
,
delegate:
SliverChildBuilderDelegate
(
(
BuildContext
context
,
int
index
)
=>
ListTile
(
title:
Text
(
'Item
$index
'
)),
childCount:
30
,
),
),
],
);
},
),
),
),
));
// There are two widgets for the title.
final
Finder
expandedTitle
=
find
.
text
(
'AppBar Title'
).
last
;
final
Finder
expandedTitleClip
=
find
.
ancestor
(
of:
expandedTitle
,
matching:
find
.
byType
(
ClipRect
),
);
// Default, fully expanded app bar.
expect
(
nestedScrollView
.
currentState
?.
outerController
.
offset
,
0
);
expect
(
nestedScrollView
.
currentState
?.
innerController
.
offset
,
0
);
expect
(
find
.
byType
(
SliverAppBar
),
findsOneWidget
);
expect
(
appBarHeight
(
tester
),
expandedAppBarHeight
);
expect
(
tester
.
getSize
(
expandedTitleClip
).
height
,
expandedAppBarHeight
-
collapsedAppBarHeight
);
// Scroll the expanded app bar partially out of view.
final
Offset
point1
=
tester
.
getCenter
(
find
.
text
(
'Item 5'
));
await
tester
.
dragFrom
(
point1
,
const
Offset
(
0.0
,
-
45.0
));
await
tester
.
pump
();
expect
(
nestedScrollView
.
currentState
?.
outerController
.
offset
,
45.0
);
expect
(
nestedScrollView
.
currentState
?.
innerController
.
offset
,
0.0
);
expect
(
find
.
byType
(
SliverAppBar
),
findsOneWidget
);
expect
(
appBarHeight
(
tester
),
expandedAppBarHeight
-
45
);
expect
(
tester
.
getSize
(
expandedTitleClip
).
height
,
expandedAppBarHeight
-
collapsedAppBarHeight
-
45
);
// Scroll so that it is completely collapsed.
await
tester
.
dragFrom
(
point1
,
const
Offset
(
0.0
,
-
555.0
));
await
tester
.
pump
();
expect
(
nestedScrollView
.
currentState
?.
outerController
.
offset
,
48.0
);
expect
(
nestedScrollView
.
currentState
?.
innerController
.
offset
,
552.0
);
expect
(
find
.
byType
(
SliverAppBar
),
findsOneWidget
);
expect
(
appBarHeight
(
tester
),
collapsedAppBarHeight
);
expect
(
tester
.
getSize
(
expandedTitleClip
).
height
,
0
);
// Scroll back to fully expanded.
await
tester
.
dragFrom
(
point1
,
const
Offset
(
0.0
,
600.0
));
await
tester
.
pump
();
expect
(
nestedScrollView
.
currentState
?.
outerController
.
offset
,
0
);
expect
(
nestedScrollView
.
currentState
?.
innerController
.
offset
,
0
);
expect
(
find
.
byType
(
SliverAppBar
),
findsOneWidget
);
expect
(
appBarHeight
(
tester
),
expandedAppBarHeight
);
expect
(
tester
.
getSize
(
expandedTitleClip
).
height
,
expandedAppBarHeight
-
collapsedAppBarHeight
);
});
testWidgets
(
'SliverAppBar.large collapses in NestedScrollView'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
NestedScrollViewState
>
nestedScrollView
=
GlobalKey
();
const
double
collapsedAppBarHeight
=
64
;
const
double
expandedAppBarHeight
=
152
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
NestedScrollView
(
key:
nestedScrollView
,
headerSliverBuilder:
(
BuildContext
context
,
bool
innerBoxIsScrolled
)
{
return
<
Widget
>[
SliverOverlapAbsorber
(
handle:
NestedScrollView
.
sliverOverlapAbsorberHandleFor
(
context
),
sliver:
SliverAppBar
.
large
(
title:
const
Text
(
'AppBar Title'
),
forceElevated:
innerBoxIsScrolled
,
),
),
];
},
body:
Builder
(
builder:
(
BuildContext
context
)
{
return
CustomScrollView
(
slivers:
<
Widget
>[
SliverOverlapInjector
(
handle:
NestedScrollView
.
sliverOverlapAbsorberHandleFor
(
context
)),
SliverFixedExtentList
(
itemExtent:
50.0
,
delegate:
SliverChildBuilderDelegate
(
(
BuildContext
context
,
int
index
)
=>
ListTile
(
title:
Text
(
'Item
$index
'
)),
childCount:
30
,
),
),
],
);
},
),
),
),
));
// There are two widgets for the title.
final
Finder
expandedTitle
=
find
.
text
(
'AppBar Title'
).
last
;
final
Finder
expandedTitleClip
=
find
.
ancestor
(
of:
expandedTitle
,
matching:
find
.
byType
(
ClipRect
),
);
// Default, fully expanded app bar.
expect
(
nestedScrollView
.
currentState
?.
outerController
.
offset
,
0
);
expect
(
nestedScrollView
.
currentState
?.
innerController
.
offset
,
0
);
expect
(
find
.
byType
(
SliverAppBar
),
findsOneWidget
);
expect
(
appBarHeight
(
tester
),
expandedAppBarHeight
);
expect
(
tester
.
getSize
(
expandedTitleClip
).
height
,
expandedAppBarHeight
-
collapsedAppBarHeight
);
// Scroll the expanded app bar partially out of view.
final
Offset
point1
=
tester
.
getCenter
(
find
.
text
(
'Item 5'
));
await
tester
.
dragFrom
(
point1
,
const
Offset
(
0.0
,
-
45.0
));
await
tester
.
pump
();
expect
(
nestedScrollView
.
currentState
?.
outerController
.
offset
,
45.0
);
expect
(
nestedScrollView
.
currentState
?.
innerController
.
offset
,
0
);
expect
(
find
.
byType
(
SliverAppBar
),
findsOneWidget
);
expect
(
appBarHeight
(
tester
),
expandedAppBarHeight
-
45
);
expect
(
tester
.
getSize
(
expandedTitleClip
).
height
,
expandedAppBarHeight
-
collapsedAppBarHeight
-
45
);
// Scroll so that it is completely collapsed.
await
tester
.
dragFrom
(
point1
,
const
Offset
(
0.0
,
-
555.0
));
await
tester
.
pump
();
expect
(
nestedScrollView
.
currentState
?.
outerController
.
offset
,
88.0
);
expect
(
nestedScrollView
.
currentState
?.
innerController
.
offset
,
512.0
);
expect
(
find
.
byType
(
SliverAppBar
),
findsOneWidget
);
expect
(
appBarHeight
(
tester
),
collapsedAppBarHeight
);
expect
(
tester
.
getSize
(
expandedTitleClip
).
height
,
0
);
// Scroll back to fully expanded.
await
tester
.
dragFrom
(
point1
,
const
Offset
(
0.0
,
600.0
));
await
tester
.
pump
();
expect
(
nestedScrollView
.
currentState
?.
outerController
.
offset
,
0
);
expect
(
nestedScrollView
.
currentState
?.
innerController
.
offset
,
0
);
expect
(
find
.
byType
(
SliverAppBar
),
findsOneWidget
);
expect
(
appBarHeight
(
tester
),
expandedAppBarHeight
);
expect
(
tester
.
getSize
(
expandedTitleClip
).
height
,
expandedAppBarHeight
-
collapsedAppBarHeight
);
});
}
}
double
appBarHeight
(
WidgetTester
tester
)
=>
tester
.
getSize
(
find
.
byType
(
AppBar
,
skipOffstage:
false
)).
height
;
class
TestHeader
extends
SliverPersistentHeaderDelegate
{
class
TestHeader
extends
SliverPersistentHeaderDelegate
{
const
TestHeader
({
this
.
key
});
const
TestHeader
({
this
.
key
});
final
Key
?
key
;
final
Key
?
key
;
...
...
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