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
fba96809
Commit
fba96809
authored
Dec 16, 2019
by
Yuwen Yan
Committed by
Hans Muller
Dec 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add enableDrag configuration for showModalBottomSheet (#46685)
parent
c06bf650
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
122 additions
and
1 deletion
+122
-1
bottom_sheet.dart
packages/flutter/lib/src/material/bottom_sheet.dart
+15
-1
bottom_sheet_test.dart
packages/flutter/test/material/bottom_sheet_test.dart
+107
-0
No files found.
packages/flutter/lib/src/material/bottom_sheet.dart
View file @
fba96809
...
...
@@ -265,7 +265,9 @@ class _ModalBottomSheet<T> extends StatefulWidget {
this
.
shape
,
this
.
clipBehavior
,
this
.
isScrollControlled
=
false
,
this
.
enableDrag
=
true
,
})
:
assert
(
isScrollControlled
!=
null
),
assert
(
enableDrag
!=
null
),
super
(
key:
key
);
final
_ModalBottomSheetRoute
<
T
>
route
;
...
...
@@ -274,6 +276,7 @@ class _ModalBottomSheet<T> extends StatefulWidget {
final
double
elevation
;
final
ShapeBorder
shape
;
final
Clip
clipBehavior
;
final
bool
enableDrag
;
@override
_ModalBottomSheetState
<
T
>
createState
()
=>
_ModalBottomSheetState
<
T
>();
...
...
@@ -326,6 +329,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
elevation:
widget
.
elevation
,
shape:
widget
.
shape
,
clipBehavior:
widget
.
clipBehavior
,
enableDrag:
widget
.
enableDrag
,
),
),
),
...
...
@@ -346,10 +350,12 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
this
.
clipBehavior
,
this
.
modalBarrierColor
,
this
.
isDismissible
=
true
,
this
.
enableDrag
=
true
,
@required
this
.
isScrollControlled
,
RouteSettings
settings
,
})
:
assert
(
isScrollControlled
!=
null
),
assert
(
isDismissible
!=
null
),
assert
(
enableDrag
!=
null
),
super
(
settings:
settings
);
final
WidgetBuilder
builder
;
...
...
@@ -361,6 +367,7 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
final
Clip
clipBehavior
;
final
Color
modalBarrierColor
;
final
bool
isDismissible
;
final
bool
enableDrag
;
@override
Duration
get
transitionDuration
=>
_bottomSheetDuration
;
...
...
@@ -399,6 +406,7 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
shape:
shape
,
clipBehavior:
clipBehavior
,
isScrollControlled:
isScrollControlled
,
enableDrag:
enableDrag
,
),
);
if
(
theme
!=
null
)
...
...
@@ -437,6 +445,9 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
/// The [isDismissible] parameter specifies whether the bottom sheet will be
/// dismissed when user taps on the scrim.
///
/// The [enableDrag] parameter specifies whether the bottom sheet can be
/// dragged up and down and dismissed by swiping downards.
///
/// The optional [backgroundColor], [elevation], [shape], and [clipBehavior]
/// parameters can be passed in to customize the appearance and behavior of
/// modal bottom sheets.
...
...
@@ -507,12 +518,14 @@ Future<T> showModalBottomSheet<T>({
bool
isScrollControlled
=
false
,
bool
useRootNavigator
=
false
,
bool
isDismissible
=
true
,
bool
enableDrag
=
true
,
})
{
assert
(
context
!=
null
);
assert
(
builder
!=
null
);
assert
(
isScrollControlled
!=
null
);
assert
(
useRootNavigator
!=
null
);
assert
(
isDismissible
!=
null
);
assert
(
enableDrag
!=
null
);
assert
(
debugCheckHasMediaQuery
(
context
));
assert
(
debugCheckHasMaterialLocalizations
(
context
));
...
...
@@ -526,7 +539,8 @@ Future<T> showModalBottomSheet<T>({
shape:
shape
,
clipBehavior:
clipBehavior
,
isDismissible:
isDismissible
,
modalBarrierColor:
barrierColor
modalBarrierColor:
barrierColor
,
enableDrag:
enableDrag
,
));
}
...
...
packages/flutter/test/material/bottom_sheet_test.dart
View file @
fba96809
...
...
@@ -152,6 +152,113 @@ void main() {
expect
(
find
.
text
(
'BottomSheet'
),
findsOneWidget
);
});
testWidgets
(
'Swiping down a modal BottomSheet should dismiss it by default'
,
(
WidgetTester
tester
)
async
{
BuildContext
savedContext
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Builder
(
builder:
(
BuildContext
context
)
{
savedContext
=
context
;
return
Container
();
},
),
));
await
tester
.
pump
();
expect
(
find
.
text
(
'BottomSheet'
),
findsNothing
);
bool
showBottomSheetThenCalled
=
false
;
showModalBottomSheet
<
void
>(
context:
savedContext
,
isDismissible:
false
,
builder:
(
BuildContext
context
)
=>
const
Text
(
'BottomSheet'
),
).
then
<
void
>((
void
value
)
{
showBottomSheetThenCalled
=
true
;
});
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'BottomSheet'
),
findsOneWidget
);
expect
(
showBottomSheetThenCalled
,
isFalse
);
// Swipe the bottom sheet to dismiss it.
await
tester
.
drag
(
find
.
text
(
'BottomSheet'
),
const
Offset
(
0.0
,
150.0
));
await
tester
.
pumpAndSettle
();
// Bottom sheet dismiss animation.
expect
(
showBottomSheetThenCalled
,
isTrue
);
expect
(
find
.
text
(
'BottomSheet'
),
findsNothing
);
});
testWidgets
(
'Swiping down a modal BottomSheet should not dismiss it when enableDrag is false'
,
(
WidgetTester
tester
)
async
{
BuildContext
savedContext
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Builder
(
builder:
(
BuildContext
context
)
{
savedContext
=
context
;
return
Container
();
},
),
));
await
tester
.
pump
();
expect
(
find
.
text
(
'BottomSheet'
),
findsNothing
);
bool
showBottomSheetThenCalled
=
false
;
showModalBottomSheet
<
void
>(
context:
savedContext
,
isDismissible:
false
,
enableDrag:
false
,
builder:
(
BuildContext
context
)
=>
const
Text
(
'BottomSheet'
),
).
then
<
void
>((
void
value
)
{
showBottomSheetThenCalled
=
true
;
});
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'BottomSheet'
),
findsOneWidget
);
expect
(
showBottomSheetThenCalled
,
isFalse
);
// Swipe the bottom sheet, attempting to dismiss it.
await
tester
.
drag
(
find
.
text
(
'BottomSheet'
),
const
Offset
(
0.0
,
150.0
));
await
tester
.
pumpAndSettle
();
// Bottom sheet should not dismiss.
expect
(
showBottomSheetThenCalled
,
isFalse
);
expect
(
find
.
text
(
'BottomSheet'
),
findsOneWidget
);
});
testWidgets
(
'Swiping down a modal BottomSheet should dismiss it when enableDrag is true'
,
(
WidgetTester
tester
)
async
{
BuildContext
savedContext
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Builder
(
builder:
(
BuildContext
context
)
{
savedContext
=
context
;
return
Container
();
},
),
));
await
tester
.
pump
();
expect
(
find
.
text
(
'BottomSheet'
),
findsNothing
);
bool
showBottomSheetThenCalled
=
false
;
showModalBottomSheet
<
void
>(
context:
savedContext
,
isDismissible:
false
,
enableDrag:
true
,
builder:
(
BuildContext
context
)
=>
const
Text
(
'BottomSheet'
),
).
then
<
void
>((
void
value
)
{
showBottomSheetThenCalled
=
true
;
});
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'BottomSheet'
),
findsOneWidget
);
expect
(
showBottomSheetThenCalled
,
isFalse
);
// Swipe the bottom sheet to dismiss it.
await
tester
.
drag
(
find
.
text
(
'BottomSheet'
),
const
Offset
(
0.0
,
150.0
));
await
tester
.
pumpAndSettle
();
// Bottom sheet dismiss animation.
expect
(
showBottomSheetThenCalled
,
isTrue
);
expect
(
find
.
text
(
'BottomSheet'
),
findsNothing
);
});
testWidgets
(
'Verify that a downwards fling dismisses a persistent BottomSheet'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
ScaffoldState
>
scaffoldKey
=
GlobalKey
<
ScaffoldState
>();
bool
showBottomSheetThenCalled
=
false
;
...
...
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