From dde12499370d3e5854b6efe05cfaca2df799ae2a Mon Sep 17 00:00:00 2001 From: Ayush Bherwani Date: Tue, 16 Jun 2020 23:05:03 +0530 Subject: [PATCH] [MergeableMaterial] adds dividerColor property (#59481) --- .../lib/src/material/mergeable_material.dart | 8 ++++ .../material/mergeable_material_test.dart | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/packages/flutter/lib/src/material/mergeable_material.dart b/packages/flutter/lib/src/material/mergeable_material.dart index b7a7776247..773ee45ae0 100644 --- a/packages/flutter/lib/src/material/mergeable_material.dart +++ b/packages/flutter/lib/src/material/mergeable_material.dart @@ -107,6 +107,7 @@ class MergeableMaterial extends StatefulWidget { this.elevation = 2, this.hasDividers = false, this.children = const [], + this.dividerColor, }) : super(key: key); /// The children of the [MergeableMaterial]. @@ -128,6 +129,12 @@ class MergeableMaterial extends StatefulWidget { /// Whether connected pieces of [MaterialSlice] have dividers between them. final bool hasDividers; + /// Defines color used for dividers if [hasDividers] is true. + /// + /// If `dividerColor` is null, then [DividerThemeData.color] is used. If that + /// is null, then [ThemeData.dividerColor] is used. + final Color dividerColor; + @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); @@ -562,6 +569,7 @@ class _MergeableMaterialState extends State with TickerProvid final BorderSide divider = Divider.createBorderSide( context, width: 0.5, // TODO(ianh): This probably looks terrible when the dpr isn't a power of two. + color: widget.dividerColor, ); if (i == 0) { diff --git a/packages/flutter/test/material/mergeable_material_test.dart b/packages/flutter/test/material/mergeable_material_test.dart index 683c8dd1c8..ba4a20f610 100644 --- a/packages/flutter/test/material/mergeable_material_test.dart +++ b/packages/flutter/test/material/mergeable_material_test.dart @@ -1166,4 +1166,41 @@ void main() { expect(isDivider(boxes[offset + 3], false, true), isTrue); expect(isDivider(boxes[offset + 4], true, false), isTrue); }); + + testWidgets('MergeableMaterial respects dividerColor', (WidgetTester tester) async { + const Color dividerColor = Colors.red; + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: MergeableMaterial( + hasDividers: true, + dividerColor: dividerColor, + children: [ + MaterialSlice( + key: ValueKey('A'), + child: SizedBox( + width: 100.0, + height: 100.0, + ), + ), + MaterialSlice( + key: ValueKey('B'), + child: SizedBox( + width: 100.0, + height: 100.0, + ), + ), + ], + ), + ), + ), + ), + ); + + final DecoratedBox decoratedBox = tester.widget(find.byType(DecoratedBox).last); + final BoxDecoration decoration = decoratedBox.decoration as BoxDecoration; + // Since we are getting the last DecoratedBox, it will have a Border.top. + expect(decoration.border.top.color, dividerColor); + }); }