added scrimColor property in Scaffold widget (#31025)

This commit is contained in:
Diego Velásquez López 2019-05-01 16:50:52 -05:00 committed by Hans Muller
parent 7690bb47dc
commit d8bb880d08
4 changed files with 45 additions and 1 deletions

View file

@ -39,3 +39,4 @@ Marco Scannadinari <m@scannadinari.co.uk>
Frederik Schweiger <mail@flschweiger.net>
Martin Staadecker <machstg@gmail.com>
Igor Katsuba <katsuba.igor@gmail.com>
Diego Velásquez <diego.velasquez.lopez@gmail.com>

View file

@ -181,6 +181,7 @@ class DrawerController extends StatefulWidget {
@required this.alignment,
this.drawerCallback,
this.dragStartBehavior = DragStartBehavior.start,
this.scrimColor = Colors.black54,
}) : assert(child != null),
assert(dragStartBehavior != null),
assert(alignment != null),
@ -220,6 +221,11 @@ class DrawerController extends StatefulWidget {
/// {@endtemplate}
final DragStartBehavior dragStartBehavior;
/// The color to use for the scrim that obscures primary content while a drawer is open.
///
/// By default, the color is [Colors.black54]
final Color scrimColor;
@override
DrawerControllerState createState() => DrawerControllerState();
}
@ -231,6 +237,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
@override
void initState() {
super.initState();
_color = ColorTween(begin: Colors.transparent, end: widget.scrimColor);
_controller = AnimationController(duration: _kBaseSettleDuration, vsync: this)
..addListener(_animationChanged)
..addStatusListener(_animationStatusChanged);
@ -379,7 +386,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
widget.drawerCallback(false);
}
final ColorTween _color = ColorTween(begin: Colors.transparent, end: Colors.black54);
ColorTween _color;
final GlobalKey _gestureDetectorKey = GlobalKey();
AlignmentDirectional get _drawerOuterAlignment {

View file

@ -904,6 +904,7 @@ class Scaffold extends StatefulWidget {
this.primary = true,
this.drawerDragStartBehavior = DragStartBehavior.start,
this.extendBody = false,
this.drawerScrimColor = Colors.black54,
}) : assert(primary != null),
assert(extendBody != null),
assert(drawerDragStartBehavior != null),
@ -994,6 +995,11 @@ class Scaffold extends StatefulWidget {
/// Typically a [Drawer].
final Widget endDrawer;
/// The color to use for the scrim that obscures primary content while a drawer is open.
///
/// By default, the color is [Colors.black54]
final Color drawerScrimColor;
/// The color of the [Material] widget that underlies the entire Scaffold.
///
/// The theme's [ThemeData.scaffoldBackgroundColor] by default.
@ -1906,6 +1912,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
child: widget.endDrawer,
drawerCallback: _endDrawerOpenedCallback,
dragStartBehavior: widget.drawerDragStartBehavior,
scrimColor: widget.drawerScrimColor,
),
_ScaffoldSlot.endDrawer,
// remove the side padding from the side we're not touching
@ -1928,6 +1935,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
child: widget.drawer,
drawerCallback: _drawerOpenedCallback,
dragStartBehavior: widget.drawerDragStartBehavior,
scrimColor: widget.drawerScrimColor,
),
_ScaffoldSlot.drawer,
// remove the side padding from the side we're not touching

View file

@ -106,4 +106,32 @@ void main() {
semantics.dispose();
});
testWidgets('Drawer scrimDrawerColor test', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
drawerScrimColor: const Color(0xFF323232),
drawer: Drawer(),
),
),
);
final ScaffoldState state = tester.firstState(find.byType(Scaffold));
state.openDrawer();
await tester.pump();
await tester.pump(const Duration(seconds: 1));
final Container container = tester.widget<Container>(find.descendant(
of: find.byType(Scaffold),
matching: find.byType(Container),
).first,
);
final BoxDecoration decoration = container.decoration;
expect(decoration.color, const Color(0xFF323232));
expect(decoration.shape, BoxShape.rectangle);
});
}