forked from firka/flutter
[CupertinoListSection] adds new property separatorColor (#124803)
Adds new property `separatorColor` to `CupertinoListSection` widget. Fixes: #124744 ### `separatorColor` property is null <img src="https://user-images.githubusercontent.com/13456345/231840875-22605c23-ee9f-464f-a005-c9fce1b641a7.png" width=350> ### `separatorColor` property is not-null | Color.fromARGB(255, 136, 13, 207) | Color.fromARGB(255, 13, 62, 207) | Color.fromARGB(255, 29, 207, 13) | | --- | --- | --- | |  |  |  |
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 <Widget>[
|
||||
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 <Widget>[
|
||||
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));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user