nobody
nobody

Reputation: 146

Where to find ListTile theme colors

While trying to combine Rows, Columns and ListTile, I cannot find the right colors for my icons. In the following example there are three icons in a Row, and one in a ListTile. Icons in Row(Expanded()) containers are black, while an Icon in ListTile() is gray. I would like all icons to be gray, but I cannot find that color in a Theme.of(context). Can anyone tell me where this gray is hidden in the Theme?

enter image description here

Here is the code that produces an output show in the picture:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.purple,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  final String title;

  const MyHomePage({
    Key? key,
    required this.title,
  }) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Column(
        children: [
          Row(
            children: const [
              Expanded(
                child: Icon(Icons.settings),
              ),
              Expanded(
                child: Icon(Icons.share),
              ),
              Expanded(
                child: Icon(Icons.photo),
              ),
            ]
          ),
          const ListTile(
            leading: Icon(Icons.home),
            title: Text('Home'),
          ),
        ],
      ),
    );
  }
}

Addition:

I used @Yeasin Sheikh answer, but changed it a little to keep the selection of my primarySwatch color:

theme: ThemeData(primarySwatch: Colors.purple).copyWith(
         iconTheme: Theme.of(context).iconTheme.copyWith(
           color: Colors.black45,
         ),
       ),

Upvotes: 0

Views: 648

Answers (4)

Yunus Kocatas
Yunus Kocatas

Reputation: 316

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        iconTheme: IconThemeData(color: Colors.grey),
        primarySwatch: Colors.purple,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  final String title;

  const MyHomePage({
    Key? key,
    required this.title,
  }) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Column(
        children: [
          Row(children: [
            Expanded(
              child: Icon(Icons.settings),
            ),
            Expanded(
              child: Icon(Icons.share),
            ),
            Expanded(
              child: Icon(Icons.photo),
            ),
          ]),
          ListTile(
            leading: Icon(Icons.home),
            title: Text('Home'),
          ),
        ],
      ),
    );
  }
}

Add the following code into ThemeData

iconTheme: IconThemeData(color: Colors.grey)

Upvotes: 0

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63569

The default color of leading's icon comes from ListTileThemeData

To change leading color

theme: Theme.of(context).copyWith(
  listTileTheme: Theme.of(context).listTileTheme.copyWith(
        iconColor: Colors.pink, // your color
      ),
),

Default leading icon's color is Colors.black45 for Brightness.light

You can check it on source code.

To change icon's color using theme, do

return MaterialApp(
  theme: Theme.of(context).copyWith(
    iconTheme: Theme.of(context).iconTheme.copyWith(
          color: Colors.black45,
        ),
  ),

Upvotes: 1

try this iconTheme: IconThemeData(color: Colors.grey),

Upvotes: 0

Yashu Agrawal
Yashu Agrawal

Reputation: 79

color: Theme.of(context).primaryColor;

In this Line click on ctrl + primaryColor, You will be Headed to theme_data page and there you can change your theme color according to your convience.

Upvotes: 0

Related Questions