'Can't change color of a "Leading Icon" of a ListTile in Flutter
I have a Drawer with a ListView, inside that I have the ListTiles. In every ListTile there is a leading element, the Icon. I want to change the color of all Icons inside ListTiles from my ThemeData. I tried however it doesn't work.
Here is my current code (the class only):
class _UniversalConverter extends State<UniversalConverter> {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
iconTheme: const IconThemeData(color: Colors.blue),
),
home: Scaffold(
appBar: AppBar(
title: const Text("Universal Converter"),
),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
const DrawerHeader(
child: Text('Drawer Header'),
),
ListTile(
title: const Text('Home'),
leading: const Icon(Icons.home),
onTap: () {},
),
ListTile(
title: const Text('Angle'),
leading: const Icon(Icons.block),
onTap: () {},
),
],
),
),
));
}
}
As you can see I have the iconTheme: const IconThemeData(color: Colors.blue), but it doesn't do anything.
Any help would be appreciated, Thanks!
Solution 1:[1]
Icon itself having a property called color. Consider below code snippet.
ListTile(
title: Text('Hi'),
leading: Icon(Icons.block,
color : Colors.orange,
),
onTap: () {
// To do
}, ),
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kalpesh Khandla |
