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
dc432d78
Unverified
Commit
dc432d78
authored
Dec 01, 2020
by
Bikram Pandit
Committed by
GitHub
Dec 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add detection of drawer open and close in Scaffold widget as a callback method. (#67249)
parent
a7f5fd53
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+10
-0
scaffold_test.dart
packages/flutter/test/material/scaffold_test.dart
+38
-0
No files found.
packages/flutter/lib/src/material/scaffold.dart
View file @
dc432d78
...
...
@@ -1443,7 +1443,9 @@ class Scaffold extends StatefulWidget {
this
.
floatingActionButtonAnimator
,
this
.
persistentFooterButtons
,
this
.
drawer
,
this
.
onDrawerChanged
,
this
.
endDrawer
,
this
.
onEndDrawerChanged
,
this
.
bottomNavigationBar
,
this
.
bottomSheet
,
this
.
backgroundColor
,
...
...
@@ -1607,6 +1609,9 @@ class Scaffold extends StatefulWidget {
/// {@end-tool}
final
Widget
?
drawer
;
/// Optional callback that is called when the [Scaffold.drawer] is opened or closed.
final
DrawerCallback
?
onDrawerChanged
;
/// A panel displayed to the side of the [body], often hidden on mobile
/// devices. Swipes in from right-to-left ([TextDirection.ltr]) or
/// left-to-right ([TextDirection.rtl])
...
...
@@ -1667,6 +1672,9 @@ class Scaffold extends StatefulWidget {
/// {@end-tool}
final
Widget
?
endDrawer
;
/// Optional callback that is called when the [Scaffold.endDrawer] is opened or closed.
final
DrawerCallback
?
onEndDrawerChanged
;
/// The color to use for the scrim that obscures primary content while a drawer is open.
///
/// By default, the color is [Colors.black54]
...
...
@@ -2091,12 +2099,14 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
setState
(()
{
_drawerOpened
=
isOpened
;
});
widget
.
onDrawerChanged
?.
call
(
isOpened
);
}
void
_endDrawerOpenedCallback
(
bool
isOpened
)
{
setState
(()
{
_endDrawerOpened
=
isOpened
;
});
widget
.
onEndDrawerChanged
?.
call
(
isOpened
);
}
/// Opens the [Drawer] (if any).
...
...
packages/flutter/test/material/scaffold_test.dart
View file @
dc432d78
...
...
@@ -11,6 +11,44 @@ import 'package:flutter_test/flutter_test.dart';
import
'../widgets/semantics_tester.dart'
;
void
main
(
)
{
testWidgets
(
'Scaffold drawer callback test'
,
(
WidgetTester
tester
)
async
{
bool
isDrawerOpen
=
false
;
bool
isEndDrawerOpen
=
false
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
drawer:
Container
(
color:
Colors
.
blue
,
),
onDrawerChanged:
(
bool
isOpen
)
{
isDrawerOpen
=
isOpen
;
},
endDrawer:
Container
(
color:
Colors
.
green
,
),
onEndDrawerChanged:
(
bool
isOpen
)
{
isEndDrawerOpen
=
isOpen
;
},
body:
Container
()),
));
final
ScaffoldState
scaffoldState
=
tester
.
state
(
find
.
byType
(
Scaffold
));
scaffoldState
.
openDrawer
();
await
tester
.
pumpAndSettle
();
expect
(
true
,
isDrawerOpen
);
scaffoldState
.
openEndDrawer
();
await
tester
.
pumpAndSettle
();
expect
(
false
,
isDrawerOpen
);
scaffoldState
.
openEndDrawer
();
await
tester
.
pumpAndSettle
();
expect
(
true
,
isEndDrawerOpen
);
scaffoldState
.
openDrawer
();
await
tester
.
pumpAndSettle
();
expect
(
false
,
isEndDrawerOpen
);
});
testWidgets
(
'Scaffold control test'
,
(
WidgetTester
tester
)
async
{
final
Key
bodyKey
=
UniqueKey
();
Widget
boilerplate
(
Widget
child
)
{
...
...
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