diff --git a/packages/flutter/lib/src/cupertino/list_section.dart b/packages/flutter/lib/src/cupertino/list_section.dart index 30e6816f2f..b41430f304 100644 --- a/packages/flutter/lib/src/cupertino/list_section.dart +++ b/packages/flutter/lib/src/cupertino/list_section.dart @@ -211,6 +211,7 @@ class CupertinoListSection extends StatelessWidget { double? additionalDividerMargin, this.topMargin = _kMarginTop, bool hasLeading = true, + this.separatorColor, }) : assert((children != null && children.length > 0) || header != null), type = CupertinoListSectionType.base, additionalDividerMargin = additionalDividerMargin ?? @@ -274,6 +275,7 @@ class CupertinoListSection extends StatelessWidget { double? additionalDividerMargin, this.topMargin, bool hasLeading = true, + this.separatorColor, }) : assert((children != null && children.length > 0) || header != null), type = CupertinoListSectionType.insetGrouped, additionalDividerMargin = additionalDividerMargin ?? @@ -344,9 +346,15 @@ class CupertinoListSection extends StatelessWidget { /// matches iOS style by default. final double? topMargin; + /// Sets the color for the dividers between rows, and borders on top and + /// bottom of the rows. + /// + /// If null, defaults to [CupertinoColors.separator]. + final Color? separatorColor; + @override Widget build(BuildContext context) { - final Color dividerColor = CupertinoColors.separator.resolveFrom(context); + final Color dividerColor = separatorColor ?? CupertinoColors.separator.resolveFrom(context); final double dividerHeight = 1.0 / MediaQuery.devicePixelRatioOf(context); // Long divider is used for wrapping the top and bottom of rows. diff --git a/packages/flutter/test/cupertino/list_section_test.dart b/packages/flutter/test/cupertino/list_section_test.dart index 939ee82cf2..735c9614ca 100644 --- a/packages/flutter/test/cupertino/list_section_test.dart +++ b/packages/flutter/test/cupertino/list_section_test.dart @@ -176,4 +176,50 @@ void main() { expect(find.byType(ClipRRect), findsNothing); }); + + testWidgets('CupertinoListSection respects separatorColor', (WidgetTester tester) async { + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: CupertinoListSection( + separatorColor: const Color.fromARGB(255, 143, 193, 51), + children: const [ + CupertinoListTile(title: Text('CupertinoListTile')), + CupertinoListTile(title: Text('CupertinoListTile')), + ], + ), + ), + ), + ); + + final Column childrenColumn = tester.widget(find.byType(Column).at(1)); + for (final Widget e in childrenColumn.children) { + if (e is Container) { + expect(e.color, const Color.fromARGB(255, 143, 193, 51)); + } + } + }); + + testWidgets('CupertinoListSection.separatorColor defaults CupertinoColors.separator', (WidgetTester tester) async { + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: CupertinoListSection( + children: const [ + CupertinoListTile(title: Text('CupertinoListTile')), + CupertinoListTile(title: Text('CupertinoListTile')), + ], + ), + ), + ), + ); + + final BuildContext context = tester.element(find.byType(CupertinoListSection)); + final Column childrenColumn = tester.widget(find.byType(Column).at(1)); + for (final Widget e in childrenColumn.children) { + if (e is Container) { + expect(e.color, CupertinoColors.separator.resolveFrom(context)); + } + } + }); }