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
6eb601bc
Unverified
Commit
6eb601bc
authored
Apr 27, 2022
by
Kate Lovett
Committed by
GitHub
Apr 27, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix AppBar scrolledUnder initial state - the third (#102582)
parent
3edeb947
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
473 additions
and
290 deletions
+473
-290
app_bar.dart
packages/flutter/lib/src/material/app_bar.dart
+17
-4
scroll_notification_observer.dart
...flutter/lib/src/widgets/scroll_notification_observer.dart
+28
-6
app_bar_test.dart
packages/flutter/test/material/app_bar_test.dart
+426
-280
debug_test.dart
packages/flutter/test/material/debug_test.dart
+1
-0
scaffold_test.dart
packages/flutter/test/material/scaffold_test.dart
+1
-0
No files found.
packages/flutter/lib/src/material/app_bar.dart
View file @
6eb601bc
...
...
@@ -809,11 +809,24 @@ class _AppBarState extends State<AppBar> {
}
void
_handleScrollNotification
(
ScrollNotification
notification
)
{
if
(
notification
is
ScrollUpdateNotification
)
{
if
(
notification
is
ScrollUpdateNotification
&&
notification
.
depth
==
0
)
{
final
bool
oldScrolledUnder
=
_scrolledUnder
;
_scrolledUnder
=
notification
.
depth
==
0
&&
notification
.
metrics
.
extentBefore
>
0
&&
notification
.
metrics
.
axis
==
Axis
.
vertical
;
final
ScrollMetrics
metrics
=
notification
.
metrics
;
switch
(
metrics
.
axisDirection
)
{
case
AxisDirection
.
up
:
// Scroll view is reversed
_scrolledUnder
=
metrics
.
extentAfter
>
0
;
break
;
case
AxisDirection
.
down
:
_scrolledUnder
=
metrics
.
extentBefore
>
0
;
break
;
case
AxisDirection
.
right
:
case
AxisDirection
.
left
:
// Scrolled under is only supported in the vertical axis.
_scrolledUnder
=
false
;
break
;
}
if
(
_scrolledUnder
!=
oldScrolledUnder
)
{
setState
(()
{
// React to a change in MaterialState.scrolledUnder
...
...
packages/flutter/lib/src/widgets/scroll_notification_observer.dart
View file @
6eb601bc
...
...
@@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart';
import
'framework.dart'
;
import
'notification_listener.dart'
;
import
'scroll_notification.dart'
;
import
'scroll_position.dart'
;
/// A [ScrollNotification] listener for [ScrollNotificationObserver].
///
...
...
@@ -151,7 +152,19 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver>
@override
Widget
build
(
BuildContext
context
)
{
return
NotificationListener
<
ScrollNotification
>(
// A ScrollMetricsNotification allows listeners to be notified for an
// initial state, as well as if the content dimensions change without
// scrolling.
return
NotificationListener
<
ScrollMetricsNotification
>(
onNotification:
(
ScrollMetricsNotification
notification
)
{
_notifyListeners
(
_ConvertedScrollMetricsNotification
(
metrics:
notification
.
metrics
,
context:
notification
.
context
,
depth:
notification
.
depth
,
));
return
false
;
},
child:
NotificationListener
<
ScrollNotification
>(
onNotification:
(
ScrollNotification
notification
)
{
_notifyListeners
(
notification
);
return
false
;
...
...
@@ -160,6 +173,7 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver>
scrollNotificationObserverState:
this
,
child:
widget
.
child
,
),
),
);
}
...
...
@@ -170,3 +184,11 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver>
super
.
dispose
();
}
}
class
_ConvertedScrollMetricsNotification
extends
ScrollUpdateNotification
{
_ConvertedScrollMetricsNotification
({
required
super
.
metrics
,
required
super
.
context
,
required
super
.
depth
,
});
}
packages/flutter/test/material/app_bar_test.dart
View file @
6eb601bc
...
...
@@ -2621,47 +2621,63 @@ void main() {
expect
(
actionIconTheme
.
color
,
foregroundColor
);
});
testWidgets
(
'SliverAppBar.backgroundColor MaterialStateColor scrolledUnder'
,
(
WidgetTester
tester
)
async
{
group
(
'MaterialStateColor scrolledUnder'
,
()
{
const
double
collapsedHeight
=
kToolbarHeight
;
const
double
expandedHeight
=
200.0
;
const
Color
scrolledColor
=
Color
(
0xff00ff00
);
const
Color
defaultColor
=
Color
(
0xff0000ff
);
await
tester
.
pumpWidget
(
MaterialApp
(
Finder
findAppBarMaterial
()
{
return
find
.
descendant
(
of:
find
.
byType
(
AppBar
),
matching:
find
.
byType
(
Material
)).
first
;
}
Color
?
getAppBarBackgroundColor
(
WidgetTester
tester
)
{
return
tester
.
widget
<
Material
>(
findAppBarMaterial
()).
color
;
}
group
(
'SliverAppBar'
,
()
{
Widget
_buildSliverApp
({
required
double
contentHeight
,
bool
reverse
=
false
,
bool
includeFlexibleSpace
=
false
,
})
{
return
MaterialApp
(
home:
Scaffold
(
body:
CustomScrollView
(
reverse:
reverse
,
slivers:
<
Widget
>[
SliverAppBar
(
elevation:
0
,
backgroundColor:
MaterialStateColor
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
return
states
.
contains
(
MaterialState
.
scrolledUnder
)
?
scrolledColor
:
defaultColor
;
return
states
.
contains
(
MaterialState
.
scrolledUnder
)
?
scrolledColor
:
defaultColor
;
}),
expandedHeight:
expandedHeight
,
pinned:
true
,
flexibleSpace:
includeFlexibleSpace
?
const
FlexibleSpaceBar
(
title:
Text
(
'SliverAppBar'
))
:
null
,
),
SliverList
(
delegate:
SliverChildListDelegate
(
<
Widget
>[
Container
(
height:
1200.0
,
color:
Colors
.
teal
),
Container
(
height:
contentHeight
,
color:
Colors
.
teal
),
],
),
),
],
),
),
),
);
Finder
findAppBarMaterial
()
{
return
find
.
descendant
(
of:
find
.
byType
(
AppBar
),
matching:
find
.
byType
(
Material
));
}
Color
?
getAppBarBackgroundColor
()
{
return
tester
.
widget
<
Material
>(
findAppBarMaterial
()).
color
;
}
testWidgets
(
'backgroundColor'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_buildSliverApp
(
contentHeight:
1200.0
)
);
expect
(
getAppBarBackgroundColor
(
),
defaultColor
);
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
expandedHeight
);
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
...
...
@@ -2669,7 +2685,7 @@ void main() {
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
),
scrolledColor
);
expect
(
getAppBarBackgroundColor
(
tester
),
scrolledColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
collapsedHeight
);
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
300.0
));
...
...
@@ -2677,107 +2693,168 @@ void main() {
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
),
defaultColor
);
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
expandedHeight
);
});
testWidgets
(
'SliverAppBar.backgroundColor with FlexibleSpace MaterialStateColor scrolledUnder'
,
(
WidgetTester
tester
)
async
{
const
double
collapsedHeight
=
kToolbarHeight
;
const
double
expandedHeight
=
200.0
;
const
Color
scrolledColor
=
Color
(
0xff00ff00
);
const
Color
defaultColor
=
Color
(
0xff0000ff
);
testWidgets
(
'backgroundColor with FlexibleSpace'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
CustomScrollView
(
slivers:
<
Widget
>[
SliverAppBar
(
elevation:
0
,
backgroundColor:
MaterialStateColor
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
return
states
.
contains
(
MaterialState
.
scrolledUnder
)
?
scrolledColor
:
defaultColor
;
}),
expandedHeight:
expandedHeight
,
pinned:
true
,
flexibleSpace:
const
FlexibleSpaceBar
(
title:
Text
(
'SliverAppBar'
),
),
),
SliverList
(
delegate:
SliverChildListDelegate
(
<
Widget
>[
Container
(
height:
1200.0
,
color:
Colors
.
teal
),
],
),
),
],
),
),
),
_buildSliverApp
(
contentHeight:
1200.0
,
includeFlexibleSpace:
true
)
);
Finder
findAppBarMaterial
()
{
// There are 2 Material widgets below AppBar. The second is only added if
// flexibleSpace is non-null.
return
find
.
descendant
(
of:
find
.
byType
(
AppBar
),
matching:
find
.
byType
(
Material
)).
first
;
}
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
expandedHeight
);
Color
?
getAppBarBackgroundColor
()
{
return
tester
.
widget
<
Material
>(
findAppBarMaterial
()).
color
;
}
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
expandedHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
tester
),
scrolledColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
collapsedHeight
);
expect
(
getAppBarBackgroundColor
(),
defaultColor
);
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
300.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
expandedHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
expandedHeight
);
});
testWidgets
(
'backgroundColor - reverse'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_buildSliverApp
(
contentHeight:
1200.0
,
reverse:
true
)
);
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
expandedHeight
);
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
expandedHeight
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
expandedHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
),
scrolledColor
);
expect
(
getAppBarBackgroundColor
(
tester
),
scrolledColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
collapsedHeight
);
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
300.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
expandedHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
expandedHeight
);
});
testWidgets
(
'backgroundColor with FlexibleSpace - reverse'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_buildSliverApp
(
contentHeight:
1200.0
,
reverse:
true
,
includeFlexibleSpace:
true
,
)
);
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
expandedHeight
);
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
expandedHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(),
defaultColor
);
expect
(
getAppBarBackgroundColor
(
tester
),
scrolledColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
collapsedHeight
);
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
300.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
expandedHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
expandedHeight
);
});
testWidgets
(
'AppBar.backgroundColor MaterialStateColor scrolledUnder'
,
(
WidgetTester
tester
)
async
{
const
Color
scrolledColor
=
Color
(
0xff00ff00
);
const
Color
defaultColor
=
Color
(
0xff0000ff
);
testWidgets
(
'backgroundColor - not triggered in reverse for short content'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_buildSliverApp
(
contentHeight:
200
,
reverse:
true
)
);
// In reverse, the content here is not long enough to scroll under the app
// bar.
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
expandedHeight
);
final
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
expandedHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
expandedHeight
);
});
testWidgets
(
'backgroundColor with FlexibleSpace - not triggered in reverse for short content'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
_buildSliverApp
(
contentHeight:
200
,
reverse:
true
,
includeFlexibleSpace:
true
,
)
);
// In reverse, the content here is not long enough to scroll under the app
// bar.
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
expandedHeight
);
final
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
expandedHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
expandedHeight
);
});
});
group
(
'AppBar'
,
()
{
Widget
_buildAppBar
({
required
double
contentHeight
,
bool
reverse
=
false
,
bool
includeFlexibleSpace
=
false
})
{
return
MaterialApp
(
home:
Scaffold
(
appBar:
AppBar
(
elevation:
0
,
backgroundColor:
MaterialStateColor
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
return
states
.
contains
(
MaterialState
.
scrolledUnder
)
?
scrolledColor
:
defaultColor
;
return
states
.
contains
(
MaterialState
.
scrolledUnder
)
?
scrolledColor
:
defaultColor
;
}),
title:
const
Text
(
'AppBar'
),
flexibleSpace:
includeFlexibleSpace
?
const
FlexibleSpaceBar
(
title:
Text
(
'FlexibleSpace'
))
:
null
,
),
body:
ListView
(
reverse:
reverse
,
children:
<
Widget
>[
Container
(
height:
1200.0
,
color:
Colors
.
teal
),
Container
(
height:
contentHeight
,
color:
Colors
.
teal
),
],
),
),
),
);
Finder
findAppBarMaterial
()
{
return
find
.
descendant
(
of:
find
.
byType
(
AppBar
),
matching:
find
.
byType
(
Material
));
}
Color
?
getAppBarBackgroundColor
()
{
return
tester
.
widget
<
Material
>(
findAppBarMaterial
()).
color
;
}
testWidgets
(
'backgroundColor'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_buildAppBar
(
contentHeight:
1200.0
)
);
expect
(
getAppBarBackgroundColor
(
),
defaultColor
);
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
...
...
@@ -2785,7 +2862,7 @@ void main() {
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
),
scrolledColor
);
expect
(
getAppBarBackgroundColor
(
tester
),
scrolledColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
300.0
));
...
...
@@ -2793,67 +2870,96 @@ void main() {
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
),
defaultColor
);
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
});
testWidgets
(
'AppBar.backgroundColor with FlexibleSpace MaterialStateColor scrolledUnder'
,
(
WidgetTester
tester
)
async
{
const
Color
scrolledColor
=
Color
(
0xff00ff00
);
const
Color
defaultColor
=
Color
(
0xff0000ff
);
testWidgets
(
'backgroundColor with FlexibleSpace'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
appBar:
AppBar
(
elevation:
0
,
backgroundColor:
MaterialStateColor
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
return
states
.
contains
(
MaterialState
.
scrolledUnder
)
?
scrolledColor
:
defaultColor
;
}),
title:
const
Text
(
'AppBar'
),
flexibleSpace:
const
FlexibleSpaceBar
(
title:
Text
(
'FlexibleSpace'
),
),
),
body:
ListView
(
children:
<
Widget
>[
Container
(
height:
1200.0
,
color:
Colors
.
teal
),
],
),
),
),
_buildAppBar
(
contentHeight:
1200.0
,
includeFlexibleSpace:
true
)
);
Finder
findAppBarMaterial
()
{
// There are 2 Material widgets below AppBar. The second is only added if
// flexibleSpace is non-null.
return
find
.
descendant
(
of:
find
.
byType
(
AppBar
),
matching:
find
.
byType
(
Material
)).
first
;
}
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
Color
?
getAppBarBackgroundColor
()
{
return
tester
.
widget
<
Material
>(
findAppBarMaterial
()).
color
;
}
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
kToolbarHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
tester
),
scrolledColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
300.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
kToolbarHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
});
expect
(
getAppBarBackgroundColor
(),
defaultColor
);
testWidgets
(
'backgroundColor - reverse'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_buildAppBar
(
contentHeight:
1200.0
,
reverse:
true
)
);
await
tester
.
pump
();
// In this test case, the content always extends under the AppBar, so it
// should always be the scrolledColor.
expect
(
getAppBarBackgroundColor
(
tester
),
scrolledColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
kToolbarHeight
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
kToolbarHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
),
scrolledColor
);
expect
(
getAppBarBackgroundColor
(
tester
),
scrolledColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
300.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
kToolbarHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
tester
),
scrolledColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
});
testWidgets
(
'backgroundColor with FlexibleSpace - reverse'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_buildAppBar
(
contentHeight:
1200.0
,
reverse:
true
,
includeFlexibleSpace:
true
,
)
);
await
tester
.
pump
();
// In this test case, the content always extends under the AppBar, so it
// should always be the scrolledColor.
expect
(
getAppBarBackgroundColor
(
tester
),
scrolledColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
kToolbarHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(),
defaultColor
);
expect
(
getAppBarBackgroundColor
(
tester
),
scrolledColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
300.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
kToolbarHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
tester
),
scrolledColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
});
testWidgets
(
'AppBar.
_handleScrollNotification safely calls setState()'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'
_handleScrollNotification safely calls setState()'
,
(
WidgetTester
tester
)
async
{
// Regression test for failures found in Google internal issue b/185192049.
final
ScrollController
controller
=
ScrollController
(
initialScrollOffset:
400
);
await
tester
.
pumpWidget
(
...
...
@@ -2879,17 +2985,16 @@ void main() {
expect
(
tester
.
takeException
(),
isNull
);
});
testWidgets
(
'AppBar scrolledUnder does not trigger on horizontal scroll'
,
(
WidgetTester
tester
)
async
{
const
Color
scrolledColor
=
Color
(
0xff00ff00
);
const
Color
defaultColor
=
Color
(
0xff0000ff
);
testWidgets
(
'does not trigger on horizontal scroll'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
appBar:
AppBar
(
elevation:
0
,
backgroundColor:
MaterialStateColor
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
return
states
.
contains
(
MaterialState
.
scrolledUnder
)
?
scrolledColor
:
defaultColor
;
return
states
.
contains
(
MaterialState
.
scrolledUnder
)
?
scrolledColor
:
defaultColor
;
}),
title:
const
Text
(
'AppBar'
),
),
...
...
@@ -2903,29 +3008,70 @@ void main() {
),
);
Finder
findAppBarMaterial
()
{
return
find
.
descendant
(
of:
find
.
byType
(
AppBar
),
matching:
find
.
byType
(
Material
));
}
Color
?
getAppBarBackgroundColor
()
{
return
tester
.
widget
<
Material
>(
findAppBarMaterial
()).
color
;
}
expect
(
getAppBarBackgroundColor
(),
defaultColor
);
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
await
gesture
.
moveBy
(
const
Offset
(-
100.0
,
0.0
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
),
defaultColor
);
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
await
gesture
.
moveBy
(
const
Offset
(
100.0
,
0.0
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(),
defaultColor
);
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
});
testWidgets
(
'backgroundColor - not triggered in reverse for short content'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_buildAppBar
(
contentHeight:
200.0
,
reverse:
true
,
)
);
await
tester
.
pump
();
// In reverse, the content here is not long enough to scroll under the app
// bar.
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
final
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
kToolbarHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
});
testWidgets
(
'backgroundColor with FlexibleSpace - not triggered in reverse for short content'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_buildAppBar
(
contentHeight:
200.0
,
reverse:
true
,
includeFlexibleSpace:
true
,
)
);
await
tester
.
pump
();
// In reverse, the content here is not long enough to scroll under the app
// bar.
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
final
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
50.0
,
400.0
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
kToolbarHeight
));
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
getAppBarBackgroundColor
(
tester
),
defaultColor
);
expect
(
tester
.
getSize
(
findAppBarMaterial
()).
height
,
kToolbarHeight
);
});
});
});
testWidgets
(
'AppBar.preferredHeightFor'
,
(
WidgetTester
tester
)
async
{
...
...
packages/flutter/test/material/debug_test.dart
View file @
6eb601bc
...
...
@@ -349,6 +349,7 @@ void main() {
' Material
\n
'
' _ScrollNotificationObserverScope
\n
'
' NotificationListener<ScrollNotification>
\n
'
' NotificationListener<ScrollMetricsNotification>
\n
'
' ScrollNotificationObserver
\n
'
' _ScaffoldScope
\n
'
' Scaffold-[LabeledGlobalKey<ScaffoldState>#00000]
\n
'
...
...
packages/flutter/test/material/scaffold_test.dart
View file @
6eb601bc
...
...
@@ -2339,6 +2339,7 @@ void main() {
' Material
\n
'
' _ScrollNotificationObserverScope
\n
'
' NotificationListener<ScrollNotification>
\n
'
' NotificationListener<ScrollMetricsNotification>
\n
'
' ScrollNotificationObserver
\n
'
' _ScaffoldScope
\n
'
' Scaffold
\n
'
...
...
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