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
4230e967
Unverified
Commit
4230e967
authored
May 02, 2019
by
Hans Muller
Committed by
GitHub
May 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify drawer scrimColor defaults, update tests (#31947)
parent
34325ba3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
25 deletions
+76
-25
drawer.dart
packages/flutter/lib/src/material/drawer.dart
+17
-6
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+1
-1
drawer_test.dart
packages/flutter/test/material/drawer_test.dart
+58
-18
No files found.
packages/flutter/lib/src/material/drawer.dart
View file @
4230e967
...
...
@@ -181,7 +181,7 @@ class DrawerController extends StatefulWidget {
@required
this
.
alignment
,
this
.
drawerCallback
,
this
.
dragStartBehavior
=
DragStartBehavior
.
start
,
this
.
scrimColor
=
Colors
.
black54
,
this
.
scrimColor
,
})
:
assert
(
child
!=
null
),
assert
(
dragStartBehavior
!=
null
),
assert
(
alignment
!=
null
),
...
...
@@ -223,7 +223,7 @@ class DrawerController extends StatefulWidget {
/// The color to use for the scrim that obscures primary content while a drawer is open.
///
/// By default, the color is [Colors.black54]
/// By default, the color
used
is [Colors.black54]
final
Color
scrimColor
;
@override
...
...
@@ -237,7 +237,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
@override
void
initState
()
{
super
.
initState
();
_
color
=
ColorTween
(
begin:
Colors
.
transparent
,
end:
widget
.
scrimColor
);
_
scrimColorTween
=
_buildScrimColorTween
(
);
_controller
=
AnimationController
(
duration:
_kBaseSettleDuration
,
vsync:
this
)
..
addListener
(
_animationChanged
)
..
addStatusListener
(
_animationStatusChanged
);
...
...
@@ -250,6 +250,13 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
super
.
dispose
();
}
@override
void
didUpdateWidget
(
DrawerController
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
if
(
widget
.
scrimColor
!=
oldWidget
.
scrimColor
)
_scrimColorTween
=
_buildScrimColorTween
();
}
void
_animationChanged
()
{
setState
(()
{
// The animation controller's state is our build state, and it changed already.
...
...
@@ -386,9 +393,13 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
widget
.
drawerCallback
(
false
);
}
ColorTween
_
color
;
ColorTween
_
scrimColorTween
;
final
GlobalKey
_gestureDetectorKey
=
GlobalKey
();
ColorTween
_buildScrimColorTween
()
{
return
ColorTween
(
begin:
Colors
.
transparent
,
end:
widget
.
scrimColor
??
Colors
.
black54
);
}
AlignmentDirectional
get
_drawerOuterAlignment
{
assert
(
widget
.
alignment
!=
null
);
switch
(
widget
.
alignment
)
{
...
...
@@ -452,8 +463,8 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
onTap:
close
,
child:
Semantics
(
label:
MaterialLocalizations
.
of
(
context
)?.
modalBarrierDismissLabel
,
child:
Container
(
color:
_
color
.
evaluate
(
_controller
),
child:
Container
(
// The drawer's "scrim"
color:
_
scrimColorTween
.
evaluate
(
_controller
),
),
),
),
...
...
packages/flutter/lib/src/material/scaffold.dart
View file @
4230e967
...
...
@@ -904,7 +904,7 @@ class Scaffold extends StatefulWidget {
this
.
primary
=
true
,
this
.
drawerDragStartBehavior
=
DragStartBehavior
.
start
,
this
.
extendBody
=
false
,
this
.
drawerScrimColor
=
Colors
.
black54
,
this
.
drawerScrimColor
,
})
:
assert
(
primary
!=
null
),
assert
(
extendBody
!=
null
),
assert
(
drawerDragStartBehavior
!=
null
),
...
...
packages/flutter/test/material/drawer_test.dart
View file @
4230e967
...
...
@@ -107,31 +107,71 @@ void main() {
semantics
.
dispose
();
});
testWidgets
(
'Drawer scrimDrawerColor test'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Scaffold drawerScrimColor'
,
(
WidgetTester
tester
)
async
{
// The scrim is a Container within a Semantics node labeled "Dismiss",
// within a DrawerController. Sorry.
Container
getScrim
()
{
return
tester
.
widget
<
Container
>(
find
.
descendant
(
of:
find
.
descendant
(
of:
find
.
byType
(
DrawerController
),
matching:
find
.
byWidgetPredicate
((
Widget
widget
)
{
if
(
widget
is
!
Semantics
)
return
false
;
final
Semantics
semantics
=
widget
;
return
semantics
.
properties
.
label
==
'Dismiss'
;
}),
),
matching:
find
.
byType
(
Container
),
),
);
}
await
tester
.
pumpWidget
(
const
MaterialApp
(
final
GlobalKey
<
ScaffoldState
>
scaffoldKey
=
GlobalKey
<
ScaffoldState
>();
Widget
buildFrame
({
Color
drawerScrimColor
})
{
return
MaterialApp
(
home:
Scaffold
(
drawerScrimColor:
Color
(
0xFF323232
),
drawer:
Drawer
(),
key:
scaffoldKey
,
drawerScrimColor:
drawerScrimColor
,
drawer:
Drawer
(
child:
Builder
(
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
onTap:
()
{
Navigator
.
pop
(
context
);
},
// close drawer
);
},
),
),
),
)
,
);
)
;
}
final
ScaffoldState
state
=
tester
.
firstState
(
find
.
byType
(
Scaffold
));
state
.
openDrawer
();
// Default drawerScrimColor
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pumpWidget
(
buildFrame
(
drawerScrimColor:
null
));
scaffoldKey
.
currentState
.
openDrawer
();
await
tester
.
pumpAndSettle
();
final
Container
container
=
tester
.
widget
<
Container
>(
find
.
descendant
(
of:
find
.
byType
(
Scaffold
),
matching:
find
.
byType
(
Container
),
).
first
,
);
BoxDecoration
decoration
=
getScrim
().
decoration
;
expect
(
decoration
.
color
,
Colors
.
black54
);
expect
(
decoration
.
shape
,
BoxShape
.
rectangle
);
final
BoxDecoration
decoration
=
container
.
decoration
;
await
tester
.
tap
(
find
.
byType
(
Drawer
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
Drawer
),
findsNothing
);
// Specific drawerScrimColor
await
tester
.
pumpWidget
(
buildFrame
(
drawerScrimColor:
const
Color
(
0xFF323232
)));
scaffoldKey
.
currentState
.
openDrawer
();
await
tester
.
pumpAndSettle
();
decoration
=
getScrim
().
decoration
;
expect
(
decoration
.
color
,
const
Color
(
0xFF323232
));
expect
(
decoration
.
shape
,
BoxShape
.
rectangle
);
expect
(
decoration
.
shape
,
BoxShape
.
rectangle
);
await
tester
.
tap
(
find
.
byType
(
Drawer
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
Drawer
),
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