From d8bb880d08a73ca72b4e27497b81d568198af88b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Vel=C3=A1squez=20L=C3=B3pez?= Date: Wed, 1 May 2019 16:50:52 -0500 Subject: [PATCH] added `scrimColor` property in Scaffold widget (#31025) --- AUTHORS | 1 + packages/flutter/lib/src/material/drawer.dart | 9 +++++- .../flutter/lib/src/material/scaffold.dart | 8 ++++++ .../flutter/test/material/drawer_test.dart | 28 +++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index b96fcbd960..ccb644693e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -39,3 +39,4 @@ Marco Scannadinari Frederik Schweiger Martin Staadecker Igor Katsuba +Diego Velásquez \ No newline at end of file diff --git a/packages/flutter/lib/src/material/drawer.dart b/packages/flutter/lib/src/material/drawer.dart index 0de1987004..d64dc17a0f 100644 --- a/packages/flutter/lib/src/material/drawer.dart +++ b/packages/flutter/lib/src/material/drawer.dart @@ -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 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 with SingleTickerPro widget.drawerCallback(false); } - final ColorTween _color = ColorTween(begin: Colors.transparent, end: Colors.black54); + ColorTween _color; final GlobalKey _gestureDetectorKey = GlobalKey(); AlignmentDirectional get _drawerOuterAlignment { diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index 55e1f417d3..5316be375f 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -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 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 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 diff --git a/packages/flutter/test/material/drawer_test.dart b/packages/flutter/test/material/drawer_test.dart index 086e30ce72..06d14057b8 100644 --- a/packages/flutter/test/material/drawer_test.dart +++ b/packages/flutter/test/material/drawer_test.dart @@ -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(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); + }); }