Issue
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?
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,
),
),
Solution
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.black45forBrightness.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,
),
),
Answered By - Yeasin Sheikh

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.