简体   繁体   English

Flutter:如何在 ThemeData 中设置 TextButton 样式

[英]Flutter: How to set TextButton Style in ThemeData

I am trying to set the TextButtonTheme in my ThemeData file.我正在尝试在我的 ThemeData 文件中设置TextButtonTheme

ButtonThemeData _basicButtonTheme(ButtonThemeData base) {
    return base.copyWith(
      buttonColor: Colors.orange,
    );
  }

  TextButtonThemeData _basicTextButtonTheme(TextButtonThemeData base) {
    return base.copyWith(ButtonStyle());
  }

However, I can not quite set the theme for TextButton.但是,我不能完全设置 TextButton 的主题。 I've read about TextButtonTheme on Flutter Doc.我在 Flutter Doc 上阅读了有关 TextButtonTheme 的信息。 But, I can't figure it out how I can set it as TextButton variable.但是,我无法弄清楚如何将其设置为 TextButton 变量。 How can I set the theme for TextButton to pass down to my ThemeData.copyWith() ?如何设置TextButton的主题以传递给我的ThemeData.copyWith()

To set the theme for a textbutton you can do the following in your MaterialApp :要为 textbutton 设置主题,您可以在MaterialApp中执行以下操作:

@override
Widget build(BuildContext context) {
  return MaterialApp(
    theme: ThemeData(
      primarySwatch: Colors.blue,
      colorScheme: ColorScheme.fromSwatch(
        primarySwatch: Colors.blue,
      ).copyWith(),      
    ),
    home: Home(),
  );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM