Add IconThemeData adjustment to ListTile trailing element (#11858)
* Add IconThemeData adjustment to ListTile trailing element (makes consistent with leading element) * Add test for ListTile theme changes * Pull out and share IconThemeData variable between leading and trailing * remove extra comma * fix style nit
This commit is contained in:
parent
b5ea59d5f6
commit
cb2204d1c4
@ -387,9 +387,13 @@ class ListTile extends StatelessWidget {
|
||||
// Overall, the list tile is a Row() with these children.
|
||||
final List<Widget> children = <Widget>[];
|
||||
|
||||
IconThemeData iconThemeData;
|
||||
if (leading != null || trailing != null)
|
||||
iconThemeData = new IconThemeData(color: _iconColor(theme, tileTheme));
|
||||
|
||||
if (leading != null) {
|
||||
children.add(IconTheme.merge(
|
||||
data: new IconThemeData(color: _iconColor(theme, tileTheme)),
|
||||
data: iconThemeData,
|
||||
child: new Container(
|
||||
margin: const EdgeInsetsDirectional.only(end: 16.0),
|
||||
width: 40.0,
|
||||
@ -424,10 +428,14 @@ class ListTile extends StatelessWidget {
|
||||
));
|
||||
|
||||
if (trailing != null) {
|
||||
children.add(new Container(
|
||||
margin: const EdgeInsetsDirectional.only(start: 16.0),
|
||||
alignment: FractionalOffsetDirectional.centerEnd,
|
||||
child: trailing,
|
||||
children.add(IconTheme.merge(
|
||||
data: iconThemeData,
|
||||
child: new Container(
|
||||
margin: const EdgeInsetsDirectional.only(start: 16.0),
|
||||
width: 40.0,
|
||||
alignment: FractionalOffsetDirectional.centerEnd,
|
||||
child: trailing,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -178,6 +178,8 @@ void main() {
|
||||
testWidgets('ListTileTheme', (WidgetTester tester) async {
|
||||
final Key titleKey = new UniqueKey();
|
||||
final Key subtitleKey = new UniqueKey();
|
||||
final Key leadingKey = new UniqueKey();
|
||||
final Key trailingKey = new UniqueKey();
|
||||
ThemeData theme;
|
||||
|
||||
Widget buildFrame({
|
||||
@ -202,7 +204,8 @@ void main() {
|
||||
return new ListTile(
|
||||
enabled: enabled,
|
||||
selected: selected,
|
||||
leading: const TestIcon(),
|
||||
leading: new TestIcon(key: leadingKey),
|
||||
trailing: new TestIcon(key: trailingKey),
|
||||
title: new TestText('title', key: titleKey),
|
||||
subtitle: new TestText('subtitle', key: subtitleKey),
|
||||
);
|
||||
@ -217,35 +220,39 @@ void main() {
|
||||
const Color green = const Color(0xFF00FF00);
|
||||
const Color red = const Color(0xFFFF0000);
|
||||
|
||||
Color iconColor() => tester.state<TestIconState>(find.byType(TestIcon)).iconTheme.color;
|
||||
Color iconColor(Key key) => tester.state<TestIconState>(find.byKey(key)).iconTheme.color;
|
||||
Color textColor(Key key) => tester.state<TestTextState>(find.byKey(key)).textStyle.color;
|
||||
|
||||
// A selected ListTile's leading and text get the primary color by default
|
||||
// A selected ListTile's leading, trailing, and text get the primary color by default
|
||||
await(tester.pumpWidget(buildFrame(selected: true)));
|
||||
await(tester.pump(const Duration(milliseconds: 300))); // DefaultTextStyle changes animate
|
||||
expect(iconColor(), theme.primaryColor);
|
||||
expect(iconColor(leadingKey), theme.primaryColor);
|
||||
expect(iconColor(trailingKey), theme.primaryColor);
|
||||
expect(textColor(titleKey), theme.primaryColor);
|
||||
expect(textColor(subtitleKey), theme.primaryColor);
|
||||
|
||||
// A selected ListTile's leading and text get the ListTileTheme's selectedColor
|
||||
// A selected ListTile's leading, trailing, and text get the ListTileTheme's selectedColor
|
||||
await(tester.pumpWidget(buildFrame(selected: true, selectedColor: green)));
|
||||
await(tester.pump(const Duration(milliseconds: 300))); // DefaultTextStyle changes animate
|
||||
expect(iconColor(), green);
|
||||
expect(iconColor(leadingKey), green);
|
||||
expect(iconColor(trailingKey), green);
|
||||
expect(textColor(titleKey), green);
|
||||
expect(textColor(subtitleKey), green);
|
||||
|
||||
// An unselected ListTile's leading icon gets the ListTileTheme's iconColor
|
||||
// An unselected ListTile's leading and trailing get the ListTileTheme's iconColor
|
||||
// An unselected ListTile's title texts get the ListTileTheme's textColor
|
||||
await(tester.pumpWidget(buildFrame(iconColor: red, textColor: green)));
|
||||
await(tester.pump(const Duration(milliseconds: 300))); // DefaultTextStyle changes animate
|
||||
expect(iconColor(), red);
|
||||
expect(iconColor(leadingKey), red);
|
||||
expect(iconColor(trailingKey), red);
|
||||
expect(textColor(titleKey), green);
|
||||
expect(textColor(subtitleKey), green);
|
||||
|
||||
// If the item is disabled it's rendered with the theme's disabled color.
|
||||
await(tester.pumpWidget(buildFrame(enabled: false)));
|
||||
await(tester.pump(const Duration(milliseconds: 300))); // DefaultTextStyle changes animate
|
||||
expect(iconColor(), theme.disabledColor);
|
||||
expect(iconColor(leadingKey), theme.disabledColor);
|
||||
expect(iconColor(trailingKey), theme.disabledColor);
|
||||
expect(textColor(titleKey), theme.disabledColor);
|
||||
expect(textColor(subtitleKey), theme.disabledColor);
|
||||
|
||||
@ -253,7 +260,8 @@ void main() {
|
||||
// Even if it's selected.
|
||||
await(tester.pumpWidget(buildFrame(enabled: false, selected: true)));
|
||||
await(tester.pump(const Duration(milliseconds: 300))); // DefaultTextStyle changes animate
|
||||
expect(iconColor(), theme.disabledColor);
|
||||
expect(iconColor(leadingKey), theme.disabledColor);
|
||||
expect(iconColor(trailingKey), theme.disabledColor);
|
||||
expect(textColor(titleKey), theme.disabledColor);
|
||||
expect(textColor(subtitleKey), theme.disabledColor);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user