gpt4 book ai didi

flutter - 图标主题不适用于默认主题?

转载 作者:行者123 更新时间:2023-12-05 06:49:43 24 4
gpt4 key购买 nike

似乎图标主题不适用于具有默认主题的卡片。

theme: ThemeData(
brightness: Brightness.light,
iconTheme: IconThemeData(
color: Colors.red, // this does not work, it renders in grey color
),
),
darkTheme: ThemeData(
brightness: Brightness.dark,
iconTheme: IconThemeData(
color: Colors.red, // it is OK
),
),

有一张卡片

Card(
child: ListTile(
trailing: const Icon(Icons.brightness_4)), // renders in grey
),
),

如何解决?

最佳答案

以下是如何在具有浅色主题的 ListTile 尾随属性中使用图标颜色。

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(
brightness: Brightness.light,
primaryColor: Colors.red,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatelessWidget {
final String title;
MyHomePage({Key? key, required this.title}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Card(
child: ListTile(
selected: true,
trailing: Icon(Icons.brightness_4),
),
),
),
);
}
}

关于flutter - 图标主题不适用于默认主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66554171/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com