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
74e564da
Unverified
Commit
74e564da
authored
5 years ago
by
Per Classon
Committed by
GitHub
5 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add parameter to Scaffold so its possible to disable open Drawer drag gesture (#50925)
parent
9295b348
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
186 additions
and
20 deletions
+186
-20
drawer.dart
packages/flutter/lib/src/material/drawer.dart
+22
-12
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+28
-8
scaffold_test.dart
packages/flutter/test/material/scaffold_test.dart
+136
-0
No files found.
packages/flutter/lib/src/material/drawer.dart
View file @
74e564da
...
...
@@ -232,6 +232,7 @@ class DrawerController extends StatefulWidget {
this
.
dragStartBehavior
=
DragStartBehavior
.
start
,
this
.
scrimColor
,
this
.
edgeDragWidth
,
this
.
enableOpenDragGesture
=
true
,
})
:
assert
(
child
!=
null
),
assert
(
dragStartBehavior
!=
null
),
assert
(
alignment
!=
null
),
...
...
@@ -278,6 +279,11 @@ class DrawerController extends StatefulWidget {
/// By default, the color used is [Colors.black54]
final
Color
scrimColor
;
/// Determines if the [Drawer] can be opened with a drag gesture.
///
/// By default, the drag gesture is enabled.
final
bool
enableOpenDragGesture
;
/// The width of the area within which a horizontal swipe will open the
/// drawer.
///
...
...
@@ -505,6 +511,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
}
if
(
_controller
.
status
==
AnimationStatus
.
dismissed
)
{
if
(
widget
.
enableOpenDragGesture
)
{
return
Align
(
alignment:
_drawerOuterAlignment
,
child:
GestureDetector
(
...
...
@@ -517,6 +524,9 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
child:
Container
(
width:
dragAreaWidth
),
),
);
}
else
{
return
const
SizedBox
.
shrink
();
}
}
else
{
bool
platformHasBackButton
;
switch
(
Theme
.
of
(
context
).
platform
)
{
...
...
This diff is collapsed.
Click to expand it.
packages/flutter/lib/src/material/scaffold.dart
View file @
74e564da
...
...
@@ -1011,6 +1011,8 @@ class Scaffold extends StatefulWidget {
this
.
extendBodyBehindAppBar
=
false
,
this
.
drawerScrimColor
,
this
.
drawerEdgeDragWidth
,
this
.
drawerEnableOpenDragGesture
=
true
,
this
.
endDrawerEnableOpenDragGesture
=
true
,
})
:
assert
(
primary
!=
null
),
assert
(
extendBody
!=
null
),
assert
(
extendBodyBehindAppBar
!=
null
),
...
...
@@ -1113,9 +1115,10 @@ class Scaffold extends StatefulWidget {
/// To close the drawer, use [Navigator.pop].
///
/// {@tool dartpad --template=stateful_widget_material}
/// To disable the drawer edge swipe, set the [Scaffold.drawerEdgeWidth] to 0.
/// Then, use [ScaffoldState.openDrawer] to open the drawer and
/// [Navigator.pop] to close it.
/// To disable the drawer edge swipe, set the
/// [Scaffold.drawerEnableOpenDragGesture] to false. Then, use
/// [ScaffoldState.openDrawer] to open the drawer and [Navigator.pop] to close
/// it.
///
/// ```dart
/// final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
...
...
@@ -1153,7 +1156,8 @@ class Scaffold extends StatefulWidget {
/// ),
/// ),
/// ),
/// drawerEdgeDragWidth: 0.0, // Disable opening the drawer with a swipe gesture.
/// // Disable opening the drawer with a swipe gesture.
/// drawerEnableOpenDragGesture: false,
/// );
/// }
/// ```
...
...
@@ -1171,9 +1175,10 @@ class Scaffold extends StatefulWidget {
/// To close the drawer, use [Navigator.pop].
///
/// {@tool dartpad --template=stateful_widget_material}
/// To disable the drawer edge swipe, set the [Scaffold.drawerEdgeWidth]
/// to 0. Then, use [ScaffoldState.openEndDrawer] to open the drawer and
/// [Navigator.pop] to close it.
/// To disable the drawer edge swipe, set the
/// [Scaffold.endDrawerEnableOpenDragGesture] to false. Then, use
/// [ScaffoldState.openEndDrawer] to open the drawer and [Navigator.pop] to
/// close it.
///
/// ```dart
/// final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
...
...
@@ -1211,7 +1216,8 @@ class Scaffold extends StatefulWidget {
/// ),
/// ),
/// ),
/// drawerEdgeDragWidth: 0.0, // Disable opening the drawer with a swipe gesture.
/// // Disable opening the end drawer with a swipe gesture.
/// endDrawerEnableOpenDragGesture: false,
/// );
/// }
/// ```
...
...
@@ -1313,6 +1319,18 @@ class Scaffold extends StatefulWidget {
/// 20.0 will be added to `MediaQuery.of(context).padding.left`.
final
double
drawerEdgeDragWidth
;
/// Determines if the [Scaffold.drawer] can be opened with a drag
/// gesture.
///
/// By default, the drag gesture is enabled.
final
bool
drawerEnableOpenDragGesture
;
/// Determines if the [Scaffold.endDrawer] can be opened with a
/// drag gesture.
///
/// By default, the drag gesture is enabled.
final
bool
endDrawerEnableOpenDragGesture
;
/// This flag is deprecated and fixes and issue with incorrect clipping
/// and positioning of the [SnackBar] set to [SnackBarBehavior.floating].
@Deprecated
(
...
...
@@ -2230,6 +2248,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
dragStartBehavior:
widget
.
drawerDragStartBehavior
,
scrimColor:
widget
.
drawerScrimColor
,
edgeDragWidth:
widget
.
drawerEdgeDragWidth
,
enableOpenDragGesture:
widget
.
endDrawerEnableOpenDragGesture
,
),
_ScaffoldSlot
.
endDrawer
,
// remove the side padding from the side we're not touching
...
...
@@ -2254,6 +2273,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
dragStartBehavior:
widget
.
drawerDragStartBehavior
,
scrimColor:
widget
.
drawerScrimColor
,
edgeDragWidth:
widget
.
drawerEdgeDragWidth
,
enableOpenDragGesture:
widget
.
drawerEnableOpenDragGesture
,
),
_ScaffoldSlot
.
drawer
,
// remove the side padding from the side we're not touching
...
...
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/scaffold_test.dart
View file @
74e564da
...
...
@@ -1596,6 +1596,142 @@ void main() {
expect
(
scaffoldState
.
isDrawerOpen
,
true
);
});
testWidgets
(
'Drawer does not open with a drag gesture when it is disabled'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
drawer:
const
Drawer
(
child:
Text
(
'Drawer'
),
),
drawerEnableOpenDragGesture:
true
,
body:
const
Text
(
'Scaffold Body'
),
appBar:
AppBar
(
centerTitle:
true
,
title:
const
Text
(
'Title'
),
),
),
),
);
ScaffoldState
scaffoldState
=
tester
.
state
(
find
.
byType
(
Scaffold
));
expect
(
scaffoldState
.
isDrawerOpen
,
false
);
// Test that we can open the drawer with a drag gesture when
// `Scaffold.drawerEnableDragGesture` is true.
await
tester
.
dragFrom
(
const
Offset
(
0
,
100
),
const
Offset
(
300
,
0
));
await
tester
.
pumpAndSettle
();
expect
(
scaffoldState
.
isDrawerOpen
,
true
);
await
tester
.
dragFrom
(
const
Offset
(
300
,
100
),
const
Offset
(-
300
,
0
));
await
tester
.
pumpAndSettle
();
expect
(
scaffoldState
.
isDrawerOpen
,
false
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
drawer:
const
Drawer
(
child:
Text
(
'Drawer'
),
),
drawerEnableOpenDragGesture:
false
,
body:
const
Text
(
'Scaffold body'
),
appBar:
AppBar
(
centerTitle:
true
,
title:
const
Text
(
'Title'
),
),
),
),
);
scaffoldState
=
tester
.
state
(
find
.
byType
(
Scaffold
));
expect
(
scaffoldState
.
isDrawerOpen
,
false
);
// Test that we cannot open the drawer with a drag gesture when
// `Scaffold.drawerEnableDragGesture` is false.
await
tester
.
dragFrom
(
const
Offset
(
0
,
100
),
const
Offset
(
300
,
0
));
await
tester
.
pumpAndSettle
();
expect
(
scaffoldState
.
isDrawerOpen
,
false
);
// Test that we can close drawer with a drag gesture when
// `Scaffold.drawerEnableDragGesture` is false.
final
Finder
drawerOpenButton
=
find
.
byType
(
IconButton
).
first
;
await
tester
.
tap
(
drawerOpenButton
);
await
tester
.
pumpAndSettle
();
expect
(
scaffoldState
.
isDrawerOpen
,
true
);
await
tester
.
dragFrom
(
const
Offset
(
300
,
100
),
const
Offset
(-
300
,
0
));
await
tester
.
pumpAndSettle
();
expect
(
scaffoldState
.
isDrawerOpen
,
false
);
});
testWidgets
(
'End drawer does not open with a drag gesture when it is disabled'
,
(
WidgetTester
tester
)
async
{
double
screenWidth
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Builder
(
builder:
(
BuildContext
context
)
{
screenWidth
=
MediaQuery
.
of
(
context
).
size
.
width
;
return
Scaffold
(
endDrawer:
const
Drawer
(
child:
Text
(
'Drawer'
),
),
endDrawerEnableOpenDragGesture:
true
,
body:
const
Text
(
'Scaffold Body'
),
appBar:
AppBar
(
centerTitle:
true
,
title:
const
Text
(
'Title'
),
),
);
}
),
),
);
ScaffoldState
scaffoldState
=
tester
.
state
(
find
.
byType
(
Scaffold
));
expect
(
scaffoldState
.
isEndDrawerOpen
,
false
);
// Test that we can open the end drawer with a drag gesture when
// `Scaffold.endDrawerEnableDragGesture` is true.
await
tester
.
dragFrom
(
Offset
(
screenWidth
-
1
,
100
),
const
Offset
(-
300
,
0
));
await
tester
.
pumpAndSettle
();
expect
(
scaffoldState
.
isEndDrawerOpen
,
true
);
await
tester
.
dragFrom
(
Offset
(
screenWidth
-
300
,
100
),
const
Offset
(
300
,
0
));
await
tester
.
pumpAndSettle
();
expect
(
scaffoldState
.
isEndDrawerOpen
,
false
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
endDrawer:
const
Drawer
(
child:
Text
(
'Drawer'
),
),
endDrawerEnableOpenDragGesture:
false
,
body:
const
Text
(
'Scaffold body'
),
appBar:
AppBar
(
centerTitle:
true
,
title:
const
Text
(
'Title'
),
),
),
),
);
scaffoldState
=
tester
.
state
(
find
.
byType
(
Scaffold
));
expect
(
scaffoldState
.
isEndDrawerOpen
,
false
);
// Test that we cannot open the end drawer with a drag gesture when
// `Scaffold.endDrawerEnableDragGesture` is false.
await
tester
.
dragFrom
(
Offset
(
screenWidth
-
1
,
100
),
const
Offset
(-
300
,
0
));
await
tester
.
pumpAndSettle
();
expect
(
scaffoldState
.
isEndDrawerOpen
,
false
);
// Test that we can close the end drawer a with drag gesture when
// `Scaffold.endDrawerEnableDragGesture` is false.
final
Finder
endDrawerOpenButton
=
find
.
byType
(
IconButton
).
first
;
await
tester
.
tap
(
endDrawerOpenButton
);
await
tester
.
pumpAndSettle
();
expect
(
scaffoldState
.
isEndDrawerOpen
,
true
);
await
tester
.
dragFrom
(
Offset
(
screenWidth
-
300
,
100
),
const
Offset
(
300
,
0
));
await
tester
.
pumpAndSettle
();
expect
(
scaffoldState
.
isEndDrawerOpen
,
false
);
});
testWidgets
(
'Nested scaffold body insets'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/20295
final
Key
bodyKey
=
UniqueKey
();
...
...
This diff is collapsed.
Click to expand it.
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