ButtonBar中的Flutter主题FlatButton textColor

问题描述 投票:5回答:1

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

primaryColor已从我的FlatButton中消失。

小部件:

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设置主题?

flutter themes flutter-layout
1个回答
0
投票

如果您希望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: () {},
          ),
        ],
      ),
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.