gpt4 book ai didi

ButtonBar 中的 Flutter 主题 FlatButton textColor

转载 作者:行者123 更新时间:2023-12-04 15:50:23 24 4
gpt4 key购买 nike

将 Flutter 升级到版本后:
[✓] Flutter (Channel master, v0.10.2-pre.82)

我的 FlatButton 中的primaryColor 已经消失了。

小部件:

new ButtonTheme.bar(
// make buttons use the appropriate styles for cards

child: new ButtonBar(
children: <Widget>[
new FlatButton(
child: const Text('DISMISS'),
onPressed: () {/* ... */},
),
new FlatButton(
child: const Text('LEARN MORE'),
onPressed: () {/* ... */},
),
],
),
),

主题:
final originalTextTheme = ThemeData.light().textTheme;
final originalButtonTheme = ThemeData.light().buttonTheme;
final originalBody1 = originalTextTheme.body1;

return ThemeData.light().copyWith(
primaryColor: Colors.green[700],
accentColor: Colors.green[500],
buttonColor: Colors.grey[800],
buttonTheme: originalButtonTheme,
textTheme: originalTextTheme.copyWith(
body1:
originalBody1.copyWith(decorationColor: Colors.transparent)));

如何为我的 FlatButtons 的 textColor 设置主题?

最佳答案

如果您想要您的 FlatButtontextColorThemeData.primaryColor 相同,还需要设置ColorScheme.primary具有相同的值。

const primaryColor = Colors.deepOrange;

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: primaryColor,
colorScheme: ColorScheme.light(
primary: primaryColor, // -------> This will be your FlatButton's text color
),
accentColor: Colors.amber,
),
title: 'YourAwesomeApp',
home: Scaffold(
body: PageWithFlatButtons(),
),
);
}
}

class PageWithFlatButtons extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
child: ButtonBar(
alignment: MainAxisAlignment.center,
children: <Widget>[
new FlatButton(
child: const Text('DISMISS'),
onPressed: () {},
),
new FlatButton(
child: const Text('LEARN MORE'),
onPressed: () {},
),
],
),
);
}
}

关于ButtonBar 中的 Flutter 主题 FlatButton textColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53035466/

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