Commit d8bb880d authored by Diego Velásquez López's avatar Diego Velásquez López Committed by Hans Muller

added `scrimColor` property in Scaffold widget (#31025)

parent 7690bb47
...@@ -39,3 +39,4 @@ Marco Scannadinari <m@scannadinari.co.uk> ...@@ -39,3 +39,4 @@ Marco Scannadinari <m@scannadinari.co.uk>
Frederik Schweiger <mail@flschweiger.net> Frederik Schweiger <mail@flschweiger.net>
Martin Staadecker <machstg@gmail.com> Martin Staadecker <machstg@gmail.com>
Igor Katsuba <katsuba.igor@gmail.com> Igor Katsuba <katsuba.igor@gmail.com>
Diego Velásquez <diego.velasquez.lopez@gmail.com>
\ No newline at end of file
...@@ -181,6 +181,7 @@ class DrawerController extends StatefulWidget { ...@@ -181,6 +181,7 @@ class DrawerController extends StatefulWidget {
@required this.alignment, @required this.alignment,
this.drawerCallback, this.drawerCallback,
this.dragStartBehavior = DragStartBehavior.start, this.dragStartBehavior = DragStartBehavior.start,
this.scrimColor = Colors.black54,
}) : assert(child != null), }) : assert(child != null),
assert(dragStartBehavior != null), assert(dragStartBehavior != null),
assert(alignment != null), assert(alignment != null),
...@@ -220,6 +221,11 @@ class DrawerController extends StatefulWidget { ...@@ -220,6 +221,11 @@ class DrawerController extends StatefulWidget {
/// {@endtemplate} /// {@endtemplate}
final DragStartBehavior dragStartBehavior; 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 @override
DrawerControllerState createState() => DrawerControllerState(); DrawerControllerState createState() => DrawerControllerState();
} }
...@@ -231,6 +237,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro ...@@ -231,6 +237,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_color = ColorTween(begin: Colors.transparent, end: widget.scrimColor);
_controller = AnimationController(duration: _kBaseSettleDuration, vsync: this) _controller = AnimationController(duration: _kBaseSettleDuration, vsync: this)
..addListener(_animationChanged) ..addListener(_animationChanged)
..addStatusListener(_animationStatusChanged); ..addStatusListener(_animationStatusChanged);
...@@ -379,7 +386,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro ...@@ -379,7 +386,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
widget.drawerCallback(false); widget.drawerCallback(false);
} }
final ColorTween _color = ColorTween(begin: Colors.transparent, end: Colors.black54); ColorTween _color;
final GlobalKey _gestureDetectorKey = GlobalKey(); final GlobalKey _gestureDetectorKey = GlobalKey();
AlignmentDirectional get _drawerOuterAlignment { AlignmentDirectional get _drawerOuterAlignment {
......
...@@ -904,6 +904,7 @@ class Scaffold extends StatefulWidget { ...@@ -904,6 +904,7 @@ class Scaffold extends StatefulWidget {
this.primary = true, this.primary = true,
this.drawerDragStartBehavior = DragStartBehavior.start, this.drawerDragStartBehavior = DragStartBehavior.start,
this.extendBody = false, this.extendBody = false,
this.drawerScrimColor = Colors.black54,
}) : assert(primary != null), }) : assert(primary != null),
assert(extendBody != null), assert(extendBody != null),
assert(drawerDragStartBehavior != null), assert(drawerDragStartBehavior != null),
...@@ -994,6 +995,11 @@ class Scaffold extends StatefulWidget { ...@@ -994,6 +995,11 @@ class Scaffold extends StatefulWidget {
/// Typically a [Drawer]. /// Typically a [Drawer].
final Widget endDrawer; 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 color of the [Material] widget that underlies the entire Scaffold.
/// ///
/// The theme's [ThemeData.scaffoldBackgroundColor] by default. /// The theme's [ThemeData.scaffoldBackgroundColor] by default.
...@@ -1906,6 +1912,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -1906,6 +1912,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
child: widget.endDrawer, child: widget.endDrawer,
drawerCallback: _endDrawerOpenedCallback, drawerCallback: _endDrawerOpenedCallback,
dragStartBehavior: widget.drawerDragStartBehavior, dragStartBehavior: widget.drawerDragStartBehavior,
scrimColor: widget.drawerScrimColor,
), ),
_ScaffoldSlot.endDrawer, _ScaffoldSlot.endDrawer,
// remove the side padding from the side we're not touching // remove the side padding from the side we're not touching
...@@ -1928,6 +1935,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -1928,6 +1935,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
child: widget.drawer, child: widget.drawer,
drawerCallback: _drawerOpenedCallback, drawerCallback: _drawerOpenedCallback,
dragStartBehavior: widget.drawerDragStartBehavior, dragStartBehavior: widget.drawerDragStartBehavior,
scrimColor: widget.drawerScrimColor,
), ),
_ScaffoldSlot.drawer, _ScaffoldSlot.drawer,
// remove the side padding from the side we're not touching // remove the side padding from the side we're not touching
......
...@@ -106,4 +106,32 @@ void main() { ...@@ -106,4 +106,32 @@ void main() {
semantics.dispose(); 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);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment