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
d75c2781
Unverified
Commit
d75c2781
authored
Mar 05, 2021
by
Kate Lovett
Committed by
GitHub
Mar 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix missing root Scaffold check in ScaffoldMessenger (#77410)
parent
3dca866f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
1 deletion
+72
-1
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+1
-1
scaffold_test.dart
packages/flutter/test/material/scaffold_test.dart
+71
-0
No files found.
packages/flutter/lib/src/material/scaffold.dart
View file @
d75c2781
...
@@ -278,7 +278,7 @@ class ScaffoldMessengerState extends State<ScaffoldMessenger> with TickerProvide
...
@@ -278,7 +278,7 @@ class ScaffoldMessengerState extends State<ScaffoldMessenger> with TickerProvide
void
_register
(
ScaffoldState
scaffold
)
{
void
_register
(
ScaffoldState
scaffold
)
{
_scaffolds
.
add
(
scaffold
);
_scaffolds
.
add
(
scaffold
);
if
(
_snackBars
.
isNotEmpty
)
{
if
(
_snackBars
.
isNotEmpty
&&
_isRoot
(
scaffold
)
)
{
scaffold
.
_updateSnackBar
();
scaffold
.
_updateSnackBar
();
}
}
}
}
...
...
packages/flutter/test/material/scaffold_test.dart
View file @
d75c2781
...
@@ -2199,6 +2199,77 @@ void main() {
...
@@ -2199,6 +2199,77 @@ void main() {
' MaterialApp at the top of your application widget tree.
\n
'
' MaterialApp at the top of your application widget tree.
\n
'
));
));
});
});
testWidgets
(
'ScaffoldMessenger checks for nesting when a new Scaffold is registered'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/77251
const
String
snackBarContent
=
'SnackBar Content'
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Builder
(
builder:
(
BuildContext
context
)
=>
Scaffold
(
body:
Scaffold
(
body:
TextButton
(
onPressed:
()
{
Navigator
.
push
(
context
,
MaterialPageRoute
<
void
>(
builder:
(
BuildContext
context
)
{
return
Scaffold
(
body:
Column
(
children:
<
Widget
>[
TextButton
(
onPressed:
()
{
const
SnackBar
snackBar
=
SnackBar
(
content:
Text
(
snackBarContent
),
behavior:
SnackBarBehavior
.
floating
,
);
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
snackBar
);
},
child:
const
Text
(
'Show SnackBar'
),
),
TextButton
(
onPressed:
()
{
Navigator
.
pop
(
context
,
null
);
},
child:
const
Text
(
'Pop route'
),
)
],
),
);
},
),
);
},
child:
const
Text
(
'Push route'
),
),
),
),
)
));
expect
(
find
.
text
(
snackBarContent
),
findsNothing
);
await
tester
.
tap
(
find
.
text
(
'Push route'
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
snackBarContent
),
findsNothing
);
expect
(
find
.
text
(
'Pop route'
),
findsOneWidget
);
// Show SnackBar on second page
await
tester
.
tap
(
find
.
text
(
'Show SnackBar'
));
await
tester
.
pump
();
expect
(
find
.
text
(
snackBarContent
),
findsOneWidget
);
// Pop the second page, the SnackBar completes a hero animation to the next route.
// If we have not handled the nested Scaffolds properly, this will throw an
// exception as duplicate SnackBars on the first route would have a common hero tag.
await
tester
.
tap
(
find
.
text
(
'Pop route'
));
await
tester
.
pump
();
// There are SnackBars two during the execution of the hero animation.
expect
(
find
.
text
(
snackBarContent
),
findsNWidgets
(
2
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
snackBarContent
),
findsOneWidget
);
// Allow the SnackBar to animate out
await
tester
.
pump
(
const
Duration
(
seconds:
4
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
snackBarContent
),
findsNothing
);
});
}
}
class
_GeometryListener
extends
StatefulWidget
{
class
_GeometryListener
extends
StatefulWidget
{
...
...
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