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
618ab7d2
Unverified
Commit
618ab7d2
authored
Aug 20, 2020
by
Kate Lovett
Committed by
GitHub
Aug 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix floating snackbar Y (#64268)
parent
0f4d2481
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletion
+56
-1
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+9
-1
snack_bar_test.dart
packages/flutter/test/material/snack_bar_test.dart
+47
-0
No files found.
packages/flutter/lib/src/material/scaffold.dart
View file @
618ab7d2
...
...
@@ -578,7 +578,15 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate {
if
(
floatingActionButtonRect
.
size
!=
Size
.
zero
&&
isSnackBarFloating
)
{
snackBarYOffsetBase
=
floatingActionButtonRect
.
top
;
}
else
{
snackBarYOffsetBase
=
contentBottom
;
// SnackBarBehavior.fixed applies a SafeArea automatically.
// SnackBarBehavior.floating does not since the positioning is affected
// if there is a FloatingActionButton (see condition above). If there is
// no FAB, make sure we account for safe space when the SnackBar is
// floating.
final
double
safeYOffsetBase
=
size
.
height
-
minViewPadding
.
bottom
;
snackBarYOffsetBase
=
isSnackBarFloating
?
math
.
min
(
contentBottom
,
safeYOffsetBase
)
:
contentBottom
;
}
final
double
xOffset
=
hasCustomWidth
?
(
size
.
width
-
snackBarWidth
)
/
2
:
0.0
;
...
...
packages/flutter/test/material/snack_bar_test.dart
View file @
618ab7d2
...
...
@@ -420,6 +420,53 @@ void main() {
expect
(
snackBarBottomRight
.
dx
,
800
-
padding
);
// Device width is 800.
});
testWidgets
(
'SnackbarBehavior.floating is positioned within safe area'
,
(
WidgetTester
tester
)
async
{
const
double
viewPadding
=
50.0
;
const
double
floatingSnackBarDefaultBottomMargin
=
10.0
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
MediaQuery
(
data:
const
MediaQueryData
(
// Simulate non-safe area.
viewPadding:
EdgeInsets
.
only
(
bottom:
viewPadding
),
),
child:
Scaffold
(
body:
Builder
(
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
onTap:
()
{
Scaffold
.
of
(
context
).
showSnackBar
(
const
SnackBar
(
content:
Text
(
'I am a snack bar.'
),
behavior:
SnackBarBehavior
.
floating
,
),
);
},
child:
const
Text
(
'X'
),
);
}
),
),
),
),
);
await
tester
.
tap
(
find
.
text
(
'X'
));
await
tester
.
pump
();
// Start animation
await
tester
.
pump
(
const
Duration
(
milliseconds:
750
));
final
Finder
materialFinder
=
find
.
descendant
(
of:
find
.
byType
(
SnackBar
),
matching:
find
.
byType
(
Material
),
);
final
Offset
snackBarBottomLeft
=
tester
.
getBottomLeft
(
materialFinder
);
expect
(
snackBarBottomLeft
.
dy
,
// Device height is 600.
600
-
viewPadding
-
floatingSnackBarDefaultBottomMargin
,
);
});
testWidgets
(
'Snackbar padding can be customized'
,
(
WidgetTester
tester
)
async
{
const
double
padding
=
20.0
;
await
tester
.
pumpWidget
(
...
...
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