Unverified Commit 94ff5202 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Refactored ListTileTheme: ListTileThemeData, ThemeData.listThemeData (#91449)

parent 4d25af34
......@@ -125,7 +125,7 @@ class AboutListTile extends StatelessWidget {
/// Whether this list tile is part of a vertically dense list.
///
/// If this property is null, then its value is based on [ListTileTheme.dense].
/// If this property is null, then its value is based on [ListTileThemeData.dense].
///
/// Dense list tiles default to a smaller height.
final bool? dense;
......
......@@ -214,7 +214,7 @@ class CheckboxListTile extends StatelessWidget {
/// Whether this list tile is part of a vertically dense list.
///
/// If this property is null then its value is based on [ListTileTheme.dense].
/// If this property is null then its value is based on [ListTileThemeData.dense].
final bool? dense;
/// Whether to render icons and text in the [activeColor].
......@@ -252,7 +252,7 @@ class CheckboxListTile extends StatelessWidget {
/// If tristate is false (the default), [value] must not be null.
final bool tristate;
/// {@macro flutter.material.ListTileTheme.shape}
/// {@macro flutter.material.ListTile.shape}
final ShapeBorder? shape;
/// If non-null, defines the background color when [CheckboxListTile.selected] is true.
......
......@@ -21,7 +21,7 @@ const Duration _kExpand = Duration(milliseconds: 200);
/// [ExpansionTile] to save and restore its expanded state when it is scrolled
/// in and out of view.
///
/// This class overrides the [ListTileTheme.iconColor] and [ListTileTheme.textColor]
/// This class overrides the [ListTileThemeData.iconColor] and [ListTileThemeData.textColor]
/// theme properties for its [ListTile]. These colors animate between values when
/// the tile is expanded and collapsed: between [iconColor], [collapsedIconColor] and
/// between [textColor] and [collapsedTextColor].
......@@ -176,23 +176,23 @@ class ExpansionTile extends StatefulWidget {
/// The icon color of tile's expansion arrow icon when the sublist is expanded.
///
/// Used to override to the [ListTileTheme.iconColor].
/// Used to override to the [ListTileThemeData.iconColor].
final Color? iconColor;
/// The icon color of tile's expansion arrow icon when the sublist is collapsed.
///
/// Used to override to the [ListTileTheme.iconColor].
/// Used to override to the [ListTileThemeData.iconColor].
final Color? collapsedIconColor;
/// The color of the tile's titles when the sublist is expanded.
///
/// Used to override to the [ListTileTheme.textColor].
/// Used to override to the [ListTileThemeData.textColor].
final Color? textColor;
/// The color of the tile's titles when the sublist is collapsed.
///
/// Used to override to the [ListTileTheme.textColor].
/// Used to override to the [ListTileThemeData.textColor].
final Color? collapsedTextColor;
/// Typically used to force the expansion arrow icon to the tile's leading or trailing edge.
......
......@@ -236,7 +236,7 @@ class RadioListTile<T> extends StatelessWidget {
/// Whether this list tile is part of a vertically dense list.
///
/// If this property is null then its value is based on [ListTileTheme.dense].
/// If this property is null then its value is based on [ListTileThemeData.dense].
final bool? dense;
/// Whether to render icons and text in the [activeColor].
......
......@@ -291,7 +291,7 @@ class SwitchListTile extends StatelessWidget {
/// Whether this list tile is part of a vertically dense list.
///
/// If this property is null then its value is based on [ListTileTheme.dense].
/// If this property is null then its value is based on [ListTileThemeData.dense].
final bool? dense;
/// The tile's internal padding.
......@@ -323,7 +323,7 @@ class SwitchListTile extends StatelessWidget {
/// By default, the value of `controlAffinity` is [ListTileControlAffinity.platform].
final ListTileControlAffinity controlAffinity;
/// {@macro flutter.material.ListTileTheme.shape}
/// {@macro flutter.material.ListTile.shape}
final ShapeBorder? shape;
/// If non-null, defines the background color when [SwitchListTile.selected] is true.
......
......@@ -28,6 +28,7 @@ import 'floating_action_button_theme.dart';
import 'ink_splash.dart';
import 'ink_well.dart' show InteractiveInkFeatureFactory;
import 'input_decorator.dart';
import 'list_tile.dart';
import 'navigation_bar_theme.dart';
import 'navigation_rail_theme.dart';
import 'outlined_button_theme.dart';
......@@ -340,6 +341,7 @@ class ThemeData with Diagnosticable {
SwitchThemeData? switchTheme,
ProgressIndicatorThemeData? progressIndicatorTheme,
DrawerThemeData? drawerTheme,
ListTileThemeData? listTileTheme,
@Deprecated(
'This "fix" is now enabled by default. '
'This feature was deprecated after v2.5.0-1.0.pre.',
......@@ -485,6 +487,7 @@ class ThemeData with Diagnosticable {
switchTheme ??= const SwitchThemeData();
progressIndicatorTheme ??= const ProgressIndicatorThemeData();
drawerTheme ??= const DrawerThemeData();
listTileTheme ??= const ListTileThemeData();
fixTextFieldOutlineLabel ??= true;
useTextSelectionTheme ??= true;
......@@ -568,6 +571,7 @@ class ThemeData with Diagnosticable {
switchTheme: switchTheme,
progressIndicatorTheme: progressIndicatorTheme,
drawerTheme: drawerTheme,
listTileTheme: listTileTheme,
fixTextFieldOutlineLabel: fixTextFieldOutlineLabel,
useTextSelectionTheme: useTextSelectionTheme,
androidOverscrollIndicator: androidOverscrollIndicator,
......@@ -703,6 +707,7 @@ class ThemeData with Diagnosticable {
required this.switchTheme,
required this.progressIndicatorTheme,
required this.drawerTheme,
required this.listTileTheme,
@Deprecated(
'This "fix" is now enabled by default. '
'This feature was deprecated after v2.5.0-1.0.pre.',
......@@ -789,6 +794,7 @@ class ThemeData with Diagnosticable {
assert(switchTheme != null),
assert(progressIndicatorTheme != null),
assert(drawerTheme != null),
assert(listTileTheme != null),
assert(fixTextFieldOutlineLabel != null),
assert(useTextSelectionTheme != null);
......@@ -1356,6 +1362,9 @@ class ThemeData with Diagnosticable {
/// A theme for customizing the appearance and layout of [Drawer] widgets.
final DrawerThemeData drawerTheme;
/// A theme for customizing the appearance of [ListTile] widgets.
final ListTileThemeData listTileTheme;
/// An obsolete flag to allow apps to opt-out of a
/// [small fix](https://github.com/flutter/flutter/issues/54028) for the Y
/// coordinate of the floating label in a [TextField] [OutlineInputBorder].
......@@ -1517,6 +1526,7 @@ class ThemeData with Diagnosticable {
SwitchThemeData? switchTheme,
ProgressIndicatorThemeData? progressIndicatorTheme,
DrawerThemeData? drawerTheme,
ListTileThemeData? listTileTheme,
@Deprecated(
'This "fix" is now enabled by default. '
'This feature was deprecated after v2.5.0-1.0.pre.',
......@@ -1609,6 +1619,7 @@ class ThemeData with Diagnosticable {
switchTheme: switchTheme ?? this.switchTheme,
progressIndicatorTheme: progressIndicatorTheme ?? this.progressIndicatorTheme,
drawerTheme: drawerTheme ?? this.drawerTheme,
listTileTheme: listTileTheme ?? this.listTileTheme,
fixTextFieldOutlineLabel: fixTextFieldOutlineLabel ?? this.fixTextFieldOutlineLabel,
useTextSelectionTheme: useTextSelectionTheme ?? this.useTextSelectionTheme,
androidOverscrollIndicator: androidOverscrollIndicator ?? this.androidOverscrollIndicator,
......@@ -1771,6 +1782,7 @@ class ThemeData with Diagnosticable {
switchTheme: SwitchThemeData.lerp(a.switchTheme, b.switchTheme, t),
progressIndicatorTheme: ProgressIndicatorThemeData.lerp(a.progressIndicatorTheme, b.progressIndicatorTheme, t)!,
drawerTheme: DrawerThemeData.lerp(a.drawerTheme, b.drawerTheme, t)!,
listTileTheme: ListTileThemeData.lerp(a.listTileTheme, b.listTileTheme, t)!,
fixTextFieldOutlineLabel: t < 0.5 ? a.fixTextFieldOutlineLabel : b.fixTextFieldOutlineLabel,
useTextSelectionTheme: t < 0.5 ? a.useTextSelectionTheme : b.useTextSelectionTheme,
androidOverscrollIndicator: t < 0.5 ? a.androidOverscrollIndicator : b.androidOverscrollIndicator,
......@@ -1861,6 +1873,7 @@ class ThemeData with Diagnosticable {
&& other.switchTheme == switchTheme
&& other.progressIndicatorTheme == progressIndicatorTheme
&& other.drawerTheme == drawerTheme
&& other.listTileTheme == listTileTheme
&& other.fixTextFieldOutlineLabel == fixTextFieldOutlineLabel
&& other.useTextSelectionTheme == useTextSelectionTheme
&& other.androidOverscrollIndicator == androidOverscrollIndicator;
......@@ -1950,6 +1963,7 @@ class ThemeData with Diagnosticable {
switchTheme,
progressIndicatorTheme,
drawerTheme,
listTileTheme,
fixTextFieldOutlineLabel,
useTextSelectionTheme,
androidOverscrollIndicator,
......@@ -2037,6 +2051,7 @@ class ThemeData with Diagnosticable {
properties.add(DiagnosticsProperty<SwitchThemeData>('switchTheme', switchTheme, defaultValue: defaultData.switchTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<ProgressIndicatorThemeData>('progressIndicatorTheme', progressIndicatorTheme, defaultValue: defaultData.progressIndicatorTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<DrawerThemeData>('drawerTheme', drawerTheme, defaultValue: defaultData.drawerTheme, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<ListTileThemeData>('listTileTheme', listTileTheme, defaultValue: defaultData.listTileTheme, level: DiagnosticLevel.debug));
properties.add(EnumProperty<AndroidOverscrollIndicator>('androidOverscrollIndicator', androidOverscrollIndicator, defaultValue: null, level: DiagnosticLevel.debug));
}
}
......
......@@ -51,6 +51,80 @@ class TestTextState extends State<TestText> {
}
void main() {
test('ListTileThemeData copyWith, ==, hashCode basics', () {
expect(const ListTileThemeData(), const ListTileThemeData().copyWith());
expect(const ListTileThemeData().hashCode, const ListTileThemeData().copyWith().hashCode);
});
test('ListTileThemeData defaults', () {
const ListTileThemeData themeData = ListTileThemeData();
expect(themeData.dense, null);
expect(themeData.shape, null);
expect(themeData.style, null);
expect(themeData.selectedColor, null);
expect(themeData.iconColor, null);
expect(themeData.textColor, null);
expect(themeData.contentPadding, null);
expect(themeData.tileColor, null);
expect(themeData.selectedTileColor, null);
expect(themeData.horizontalTitleGap, null);
expect(themeData.minVerticalPadding, null);
expect(themeData.minLeadingWidth, null);
expect(themeData.enableFeedback, null);
});
testWidgets('Default ListTileThemeData debugFillProperties', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const ListTileThemeData().debugFillProperties(builder);
final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
.map((DiagnosticsNode node) => node.toString())
.toList();
expect(description, <String>[]);
});
testWidgets('ListTileThemeData implements debugFillProperties', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const ListTileThemeData(
dense: true,
shape: StadiumBorder(),
style: ListTileStyle.drawer,
selectedColor: Color(0x00000001),
iconColor: Color(0x00000002),
textColor: Color(0x00000003),
contentPadding: EdgeInsets.all(100),
tileColor: Color(0x00000004),
selectedTileColor: Color(0x00000005),
horizontalTitleGap: 200,
minVerticalPadding: 300,
minLeadingWidth: 400,
enableFeedback: true,
).debugFillProperties(builder);
final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
.map((DiagnosticsNode node) => node.toString())
.toList();
expect(description, <String>[
'dense: true',
'shape: StadiumBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none))',
'style: drawer',
'selectedColor: Color(0x00000001)',
'iconColor: Color(0x00000002)',
'textColor: Color(0x00000003)',
'contentPadding: EdgeInsets.all(100.0)',
'tileColor: Color(0x00000004)',
'selectedTileColor: Color(0x00000005)',
'horizontalTitleGap: 200.0',
'minVerticalPadding: 300.0',
'minLeadingWidth: 400.0',
'enableFeedback: true'
]);
});
testWidgets('ListTile geometry (LTR)', (WidgetTester tester) async {
// See https://material.io/go/design-lists
......@@ -291,11 +365,13 @@ void main() {
home: Material(
child: Center(
child: ListTileTheme(
data: ListTileThemeData(
dense: dense,
shape: shape,
selectedColor: selectedColor,
iconColor: iconColor,
textColor: textColor,
),
child: Builder(
builder: (BuildContext context) {
theme = Theme.of(context);
......@@ -1720,15 +1796,17 @@ void main() {
});
testWidgets("ListTile respects ListTileTheme's tileColor & selectedTileColor", (WidgetTester tester) async {
late ListTileTheme theme;
late ListTileThemeData theme;
bool isSelected = false;
await tester.pumpWidget(
MaterialApp(
home: Material(
child: ListTileTheme(
data: ListTileThemeData(
tileColor: Colors.green.shade500,
selectedTileColor: Colors.red.shade500,
),
child: Center(
child: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
......@@ -1766,8 +1844,10 @@ void main() {
MaterialApp(
home: Material(
child: ListTileTheme(
data: const ListTileThemeData(
selectedTileColor: Colors.green,
tileColor: Colors.red,
),
child: Center(
child: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
......@@ -1898,7 +1978,7 @@ void main() {
MaterialApp(
home: Material(
child: ListTileTheme(
enableFeedback: enableFeedbackTheme,
data: const ListTileThemeData(enableFeedback: enableFeedbackTheme),
child: ListTile(
title: const Text('Title'),
onTap: () {},
......@@ -1922,7 +2002,7 @@ void main() {
MaterialApp(
home: Material(
child: ListTileTheme(
enableFeedback: enableFeedbackTheme,
data: const ListTileThemeData(enableFeedback: enableFeedbackTheme),
child: ListTile(
enableFeedback: enableFeedback,
title: const Text('Title'),
......@@ -1948,7 +2028,7 @@ void main() {
textDirection: textDirection,
child: Material(
child: ListTileTheme(
horizontalTitleGap: themeHorizontalTitleGap,
data: ListTileThemeData(horizontalTitleGap: themeHorizontalTitleGap),
child: Container(
alignment: Alignment.topLeft,
child: ListTile(
......@@ -2081,7 +2161,7 @@ void main() {
textDirection: textDirection,
child: Material(
child: ListTileTheme(
minVerticalPadding: themeMinVerticalPadding,
data: ListTileThemeData(minVerticalPadding: themeMinVerticalPadding),
child: Container(
alignment: Alignment.topLeft,
child: ListTile(
......@@ -2127,7 +2207,7 @@ void main() {
textDirection: textDirection,
child: Material(
child: ListTileTheme(
minLeadingWidth: themeMinLeadingWidth,
data: ListTileThemeData(minLeadingWidth: themeMinLeadingWidth),
child: Container(
alignment: Alignment.topLeft,
child: ListTile(
......@@ -2241,8 +2321,10 @@ void main() {
home: Material(
child: Center(
child: ListTileTheme(
data: const ListTileThemeData(
selectedColor: selectedColor,
textColor: defaultColor,
),
child: Builder(
builder: (BuildContext context) {
theme = Theme.of(context);
......
......@@ -346,6 +346,7 @@ void main() {
switchTheme: const SwitchThemeData(),
progressIndicatorTheme: const ProgressIndicatorThemeData(),
drawerTheme: const DrawerThemeData(),
listTileTheme: const ListTileThemeData(),
fixTextFieldOutlineLabel: false,
useTextSelectionTheme: false,
androidOverscrollIndicator: null,
......@@ -443,6 +444,7 @@ void main() {
switchTheme: const SwitchThemeData(),
progressIndicatorTheme: const ProgressIndicatorThemeData(),
drawerTheme: const DrawerThemeData(),
listTileTheme: const ListTileThemeData(),
fixTextFieldOutlineLabel: true,
useTextSelectionTheme: true,
androidOverscrollIndicator: AndroidOverscrollIndicator.stretch,
......@@ -521,6 +523,7 @@ void main() {
switchTheme: otherTheme.switchTheme,
progressIndicatorTheme: otherTheme.progressIndicatorTheme,
drawerTheme: otherTheme.drawerTheme,
listTileTheme: otherTheme.listTileTheme,
fixTextFieldOutlineLabel: otherTheme.fixTextFieldOutlineLabel,
);
......@@ -596,6 +599,7 @@ void main() {
expect(themeDataCopy.switchTheme, equals(otherTheme.switchTheme));
expect(themeDataCopy.progressIndicatorTheme, equals(otherTheme.progressIndicatorTheme));
expect(themeDataCopy.drawerTheme, equals(otherTheme.drawerTheme));
expect(themeDataCopy.listTileTheme, equals(otherTheme.listTileTheme));
expect(themeDataCopy.fixTextFieldOutlineLabel, equals(otherTheme.fixTextFieldOutlineLabel));
});
......
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