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
2415eca4
Unverified
Commit
2415eca4
authored
Mar 23, 2021
by
Anurag Roy
Committed by
GitHub
Mar 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FloatingActionButtonLocation] Avoid docked FAB to be clipped by the software keyboard (#77769)
parent
5a6bac30
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
4 deletions
+43
-4
floating_action_button_location.dart
...ter/lib/src/material/floating_action_button_location.dart
+17
-1
floating_action_button_location_test.dart
...r/test/material/floating_action_button_location_test.dart
+26
-3
No files found.
packages/flutter/lib/src/material/floating_action_button_location.dart
View file @
2415eca4
...
...
@@ -584,7 +584,23 @@ mixin FabDockedOffsetY on StandardFabLocation {
final
double
bottomSheetHeight
=
scaffoldGeometry
.
bottomSheetSize
.
height
;
final
double
fabHeight
=
scaffoldGeometry
.
floatingActionButtonSize
.
height
;
final
double
snackBarHeight
=
scaffoldGeometry
.
snackBarSize
.
height
;
final
double
safeMargin
=
bottomViewPadding
>
contentMargin
?
bottomViewPadding
:
0.0
;
final
double
bottomMinInset
=
scaffoldGeometry
.
minInsets
.
bottom
;
double
safeMargin
;
if
(
contentMargin
>
bottomMinInset
+
fabHeight
/
2.0
)
{
// If contentMargin is higher than bottomMinInset enough to display the
// FAB without clipping, don't provide a margin
safeMargin
=
0.0
;
}
else
if
(
bottomMinInset
==
0.0
)
{
// If bottomMinInset is zero(the software keyboard is not on the screen)
// provide bottomViewPadding as margin
safeMargin
=
bottomViewPadding
;
}
else
{
// Provide a margin that would shift the FAB enough so that it stays away
// from the keyboard
safeMargin
=
fabHeight
/
2.0
+
kFloatingActionButtonMargin
;
}
double
fabY
=
contentBottom
-
fabHeight
/
2.0
-
safeMargin
;
// The FAB should sit with a margin between it and the snack bar.
...
...
packages/flutter/test/material/floating_action_button_location_test.dart
View file @
2415eca4
...
...
@@ -1037,7 +1037,9 @@ void main() {
);
});
// Test docked locations, for each (6), keyboard presented or not:
// Test docked locations, for each (6), keyboard presented or not.
// If keyboard is presented and resizeToAvoidBottomInset: true, test whether
// the FAB is away from the keyboard(and thus not clipped):
// - Default
// - Default with resizeToAvoidBottomInset: false
// - docked with BottomNavigationBar
...
...
@@ -1057,6 +1059,7 @@ void main() {
const
double
keyboardHeight
=
200.0
;
const
double
viewPadding
=
50.0
;
const
double
bottomNavHeight
=
106.0
;
const
double
scaffoldHeight
=
600.0
;
final
Key
floatingActionButton
=
UniqueKey
();
final
double
fabHeight
=
mini
?
48.0
:
56.0
;
// Default
...
...
@@ -1084,9 +1087,14 @@ void main() {
tester
.
getRect
(
find
.
byKey
(
floatingActionButton
)),
rectMoreOrLessEquals
(
defaultRect
.
translate
(
0.0
,
viewPadding
-
keyboardHeight
+
fabHeight
/
2.0
,
viewPadding
-
keyboardHeight
-
kFloatingActionButtonMargin
,
)),
);
// The FAB should be away from the keyboard
expect
(
tester
.
getRect
(
find
.
byKey
(
floatingActionButton
)).
bottom
,
lessThan
(
scaffoldHeight
-
keyboardHeight
),
);
// With resizeToAvoidBottomInset: false
// With keyboard presented, should maintain default position
...
...
@@ -1136,9 +1144,14 @@ void main() {
tester
.
getRect
(
find
.
byKey
(
floatingActionButton
)),
rectMoreOrLessEquals
(
bottomNavigationBarRect
.
translate
(
0.0
,
-
keyboardHeight
+
bottomNav
Height
,
bottomNavHeight
+
fabHeight
/
2.0
-
keyboardHeight
-
kFloatingActionButtonMargin
-
fab
Height
,
)),
);
// The FAB should be away from the keyboard
expect
(
tester
.
getRect
(
find
.
byKey
(
floatingActionButton
)).
bottom
,
lessThan
(
scaffoldHeight
-
keyboardHeight
),
);
// BottomNavigationBar with resizeToAvoidBottomInset: false
// With keyboard presented, should maintain default position
...
...
@@ -1195,6 +1208,11 @@ void main() {
-
keyboardHeight
+
bottomNavHeight
,
)),
);
// The FAB should be away from the keyboard
expect
(
tester
.
getRect
(
find
.
byKey
(
floatingActionButton
)).
bottom
,
lessThan
(
scaffoldHeight
-
keyboardHeight
),
);
// BottomNavigationBar + BottomSheet with resizeToAvoidBottomInset: false
// With keyboard presented, should maintain default position
...
...
@@ -1264,6 +1282,11 @@ void main() {
tester
.
getRect
(
find
.
byKey
(
floatingActionButton
)),
rectMoreOrLessEquals
(
snackBarRect
.
translate
(
0.0
,
-
keyboardHeight
)),
);
// The FAB should be away from the keyboard
expect
(
tester
.
getRect
(
find
.
byKey
(
floatingActionButton
)).
bottom
,
lessThan
(
scaffoldHeight
-
keyboardHeight
),
);
}
testWidgets
(
'startDocked'
,
(
WidgetTester
tester
)
async
{
...
...
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