2
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Personal Expenses',
      theme: ThemeData(
    
        brightness: Brightness.light,
        primaryColor: Colors.lightGreen[800],
        primarySwatch: Colors.amber,
        errorColor: Colors.red,
        accentColor: Colors.cyan[600],
        fontFamily: 'Quicksand',
        textTheme: ThemeData.light().textTheme.copyWith(
            title: TextStyle(
              fontFamily: 'Quicksand',
              backgroundColor: Colors.grey,
              fontSize: 18,
            ),
        ),
        appBarTheme: AppBarTheme(
          textTheme: ThemeData.light().textTheme.copyWith(
              title: TextStyle(
                  fontFamily: 'OpenSans',
                  fontSize: 20,
                  fontWeight: FontWeight.bold,
                  fontStyle: FontStyle.italic),
                  button: TextStyle(color: Colors.white),
              ),
          )
        ),
        home: MyHomePage(),
    );
  }

例如,要在 Button 上应用主题,我正在这样做,但主题不适用于它

FlatButton(
  color: Colors.white,
  textColor: Theme.of(context).textTheme.button.color,
  onPressed: _presentDatePicker,
  child: Text(
    'Choose Date',
    style: TextStyle(fontWeight: FontWeight.bold),
  ),
)
4

1 回答 1

0

您将按钮文本颜色设置为您AppBarTheme在.textThemeFlatButton

这可能会解决您的问题。

FlatButton(
  color: Colors.white,
  textColor: Theme.of(context).AppBarTheme.textTheme.button.color,
  onPressed: _presentDatePicker,
  child: Text(
    'Choose Date',
    style: TextStyle(fontWeight: FontWeight.bold),
  ),
)

或者你可以像这样设置buttonColor

theme: ThemeData(
    primarySwatch: Colors.purple,
    accentColor: Colors.amber,
    buttonColor: Colors.white,
),

FlatButton并像这样使用那个buttonColor

FlatButton(
  color: Colors.white,
  textColor: Theme.of(context).buttonColor,
  onPressed: _presentDatePicker,
  child: Text(
    'Choose Date',
    style: TextStyle(fontWeight: FontWeight.bold),
  ),
)
于 2020-07-29T11:32:46.593 回答