Skip to content

Conversation

HansMuller
Copy link
Contributor

@HansMuller HansMuller commented Oct 7, 2021

Refactored ListTileTheme to make it conform to Flutter's conventions for component themes.

  • Added a ListTileThemeData class which defines overrides for the defaults for visual ListTile properties.
  • Added a ListTileTheme constructor parameter and getter: ListTileThemeData data. This is now the preferred way to configure a ListTileTheme.
  • Added a listTileThemeData listTileTheme property to ThemeData. This is now the preferred way to configure ListTiles in a MaterialApp.
  • Added selectedColor, textColor, iconColor and (ListTileStyle) style parameters to ListTile, so that all of the properties that can be overridden via the theme can also be set on the widget itself.

For example to configure the icon and text colors for all of the ListTiles in an app:

import 'package:flutter/material.dart';

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            ListTile(
              selected: true,
              title: Text('selected'),
              leading: Icon(Icons.android),
              trailing: Text('trailing')
            ),
            SizedBox(height: 32),
            ListTile(
              selected: false,
              title: Text('unselected'),
              leading: Icon(Icons.android),
              trailing: Icon(Icons.android),
            ),
          ],
        ),
      ),
    );
  }
}

void main() {
  runApp(
    MaterialApp(
      theme: ThemeData.light().copyWith(
        listTileTheme: ListTileThemeData(
          selectedColor: Colors.orange,
          iconColor: Colors.green,
          textColor: Colors.blue,
        ),
      ),
      home: Scaffold(body: Home())
    ),
  );
}

This is a non-breaking change. In an upcoming PR all of the ListTileTheme properties, except for data will be deprecated and a Dart Fix script will be provided to automatically migrate code.

Fixes #31247

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Oct 7, 2021
@google-cla google-cla bot added the cla: yes label Oct 7, 2021
Copy link
Contributor

@darrenaustin darrenaustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nicely done. Just a few suggestions below.

_minLeadingWidth = minLeadingWidth,
super(key: key, child: child);

final ListTileThemeData? _data;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make _data non-nullable and create a ListTileThemeData in the constructor from the parameters if they were given? That would simplify a lot of the getters below.

Is this because the constructor is const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's not possible to construct a const ListThemeData parameter value that absorbs all of the constructor parameters - error • Invalid constant value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's what I thought. Bummer, it would be nice if that were possible.

@HansMuller HansMuller force-pushed the list_tile_theme_data branch from f62adfe to b0fa008 Compare October 12, 2021 20:32
@HansMuller HansMuller merged commit 94ff520 into flutter:master Oct 12, 2021
@HansMuller HansMuller deleted the list_tile_theme_data branch October 12, 2021 22:05
renyou added a commit that referenced this pull request Oct 14, 2021
renyou added a commit that referenced this pull request Oct 14, 2021
renyou added a commit to renyou/flutter that referenced this pull request Oct 15, 2021
renyou added a commit that referenced this pull request Oct 15, 2021
* Revert "Refactored ListTileTheme: ListTileThemeData, ThemeData.listThemeData (#91449)" (#91811)

This reverts commit 94ff520.
clocksmith pushed a commit to clocksmith/flutter that referenced this pull request Oct 29, 2021
@anaurelian
Copy link

When is this going to be in the stable branch?

@HansMuller
Copy link
Contributor Author

@anaurelian - it's not likely until mid to late December 2021

@fredgrott
Copy link

Thanks for the info @HansMuller glad to know that the drop for it appearing is soon.

passsy added a commit to wiredashio/wiredash-sdk that referenced this pull request Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ListTileTheme should be a part of ThemeData
4 participants