在嘗試組合 Rows、Columns 和 ListTile 時,我找不到適合我的圖示的顏色。在以下示例中,Row 中有三個圖示,ListTile 中有一個。Row(Expanded())容器中的圖示是黑色的,而圖示中的圖示ListTile()是灰色的。我希望所有圖示都是灰色的,但我在Theme.of(context). 誰能告訴我這個灰色在主題中隱藏在哪里?

這是產生如圖所示的輸出的代碼:
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'),
),
],
),
);
}
}
添加:
我使用了@Yeasin Sheikh 的答案,但對其進行了一些更改以保留我的primarySwatch 顏色的選擇:
theme: ThemeData(primarySwatch: Colors.purple).copyWith(
iconTheme: Theme.of(context).iconTheme.copyWith(
color: Colors.black45,
),
),
uj5u.com熱心網友回復:
leading圖示的默認顏色來自ListTileThemeData
更改主色
theme: Theme.of(context).copyWith(
listTileTheme: Theme.of(context).listTileTheme.copyWith(
iconColor: Colors.pink, // your color
),
),
默認前導圖示的顏色
Colors.black45用于Brightness.light
您可以查看源代碼。
要icon使用主題更改的顏色,請執行
return MaterialApp(
theme: Theme.of(context).copyWith(
iconTheme: Theme.of(context).iconTheme.copyWith(
color: Colors.black45,
),
),
uj5u.com熱心網友回復:
顏色:Theme.of(context).primaryColor;
在這一行中,點擊 ctrl primaryColor,您將前往 theme_data 頁面,在那里您可以根據自己的喜好更改主題顏色。
uj5u.com熱心網友回復:
試試這個 iconTheme: IconThemeData(color: Colors.grey),
uj5u.com熱心網友回復:
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'),
),
],
),
);
}
}
將以下代碼添加到 ThemeData 中
iconTheme: IconThemeData(color: Colors.grey)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/401087.html
標籤:扑
