From aa8cc44e03817560069d4300d11b33bcb6ae2c2f Mon Sep 17 00:00:00 2001 From: Tirth Date: Fri, 14 Apr 2023 22:49:19 +0530 Subject: [PATCH] [CupertinoListSection] adds new property separatorColor (#124803) Adds new property `separatorColor` to `CupertinoListSection` widget. Fixes: #124744 ### `separatorColor` property is null ### `separatorColor` property is not-null | Color.fromARGB(255, 136, 13, 207) | Color.fromARGB(255, 13, 62, 207) | Color.fromARGB(255, 29, 207, 13) | | --- | --- | --- | | ![a](https://user-images.githubusercontent.com/13456345/231840832-6027cf86-e9c0-4206-b6f8-23556471c1bd.png) | ![b](https://user-images.githubusercontent.com/13456345/231840862-dcc30212-14f8-44af-a8cb-d04b22b7a078.png) | ![c](https://user-images.githubusercontent.com/13456345/231840870-d9fafe23-e9a4-423a-a25c-b71835991d07.png) | --- .../lib/src/cupertino/list_section.dart | 10 +++- .../test/cupertino/list_section_test.dart | 46 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) 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)); + } + } + }); }