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
14bc5e8c
Unverified
Commit
14bc5e8c
authored
Jan 22, 2022
by
Pedro Massango
Committed by
GitHub
Jan 22, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add closeDrawer and closeEndDrawer in ScaffoldState (#96960)
parent
da7d7777
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
4 deletions
+92
-4
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+26
-4
drawer_test.dart
packages/flutter/test/material/drawer_test.dart
+66
-0
No files found.
packages/flutter/lib/src/material/scaffold.dart
View file @
14bc5e8c
...
...
@@ -1590,7 +1590,8 @@ class Scaffold extends StatefulWidget {
///
/// To open the drawer, use the [ScaffoldState.openDrawer] function.
///
/// To close the drawer, use [Navigator.pop].
/// To close the drawer, use either [ScaffoldState.closeDrawer] or
/// [Navigator.pop].
///
/// {@tool dartpad}
/// To disable the drawer edge swipe, set the
...
...
@@ -1613,7 +1614,8 @@ class Scaffold extends StatefulWidget {
///
/// To open the drawer, use the [ScaffoldState.openEndDrawer] function.
///
/// To close the drawer, use [Navigator.pop].
/// To close the drawer, use either [ScaffoldState.closeEndDrawer] or
/// [Navigator.pop].
///
/// {@tool dartpad}
/// To disable the drawer edge swipe, set the
...
...
@@ -1986,7 +1988,8 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
/// appropriate [IconButton], and handles the edge-swipe gesture, to show the
/// drawer.
///
/// To close the drawer once it is open, use [Navigator.pop].
/// To close the drawer, use either [ScaffoldState.closeEndDrawer] or
/// [Navigator.pop].
///
/// See [Scaffold.of] for information about how to obtain the [ScaffoldState].
void
openDrawer
()
{
...
...
@@ -2004,7 +2007,8 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
/// appropriate [IconButton], and handles the edge-swipe gesture, to show the
/// drawer.
///
/// To close the end side drawer once it is open, use [Navigator.pop].
/// To close the drawer, use either [ScaffoldState.closeEndDrawer] or
/// [Navigator.pop].
///
/// See [Scaffold.of] for information about how to obtain the [ScaffoldState].
void
openEndDrawer
()
{
...
...
@@ -2305,6 +2309,24 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
}
}
/// Closes [Scaffold.drawer] if it is currently opened.
///
/// See [Scaffold.of] for information about how to obtain the [ScaffoldState].
void
closeDrawer
()
{
if
(
hasDrawer
&&
isDrawerOpen
)
{
_drawerKey
.
currentState
!.
close
();
}
}
/// Closes [Scaffold.endDrawer] if it is currently opened.
///
/// See [Scaffold.of] for information about how to obtain the [ScaffoldState].
void
closeEndDrawer
()
{
if
(
hasEndDrawer
&&
isEndDrawerOpen
)
{
_endDrawerKey
.
currentState
!.
close
();
}
}
void
_updatePersistentBottomSheet
()
{
_currentBottomSheetKey
.
currentState
!.
setState
(()
{});
}
...
...
packages/flutter/test/material/drawer_test.dart
View file @
14bc5e8c
...
...
@@ -379,4 +379,70 @@ void main() {
expect
(
find
.
text
(
'drawer'
),
findsNothing
);
expect
(
find
.
text
(
'endDrawer'
),
findsOneWidget
);
});
testWidgets
(
'ScaffoldState close drawer'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
ScaffoldState
>
scaffoldKey
=
GlobalKey
<
ScaffoldState
>();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
key:
scaffoldKey
,
drawer:
const
Text
(
'Drawer'
),
body:
Container
(),
),
),
);
expect
(
find
.
text
(
'Drawer'
),
findsNothing
);
scaffoldKey
.
currentState
!.
openDrawer
();
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Drawer'
),
findsOneWidget
);
scaffoldKey
.
currentState
!.
closeDrawer
();
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Drawer'
),
findsNothing
);
});
testWidgets
(
'ScaffoldState close drawer do not crash if drawer is already closed'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
ScaffoldState
>
scaffoldKey
=
GlobalKey
<
ScaffoldState
>();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
key:
scaffoldKey
,
drawer:
const
Text
(
'Drawer'
),
body:
Container
(),
),
),
);
expect
(
find
.
text
(
'Drawer'
),
findsNothing
);
scaffoldKey
.
currentState
!.
closeDrawer
();
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Drawer'
),
findsNothing
);
});
testWidgets
(
'ScaffoldState close end drawer'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
ScaffoldState
>
scaffoldKey
=
GlobalKey
<
ScaffoldState
>();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
key:
scaffoldKey
,
endDrawer:
const
Text
(
'endDrawer'
),
body:
Container
(),
),
),
);
expect
(
find
.
text
(
'endDrawer'
),
findsNothing
);
scaffoldKey
.
currentState
!.
openEndDrawer
();
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'endDrawer'
),
findsOneWidget
);
scaffoldKey
.
currentState
!.
closeEndDrawer
();
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'endDrawer'
),
findsNothing
);
});
}
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