Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 通过在Flatter应用程序中应用主题数据,Appbar颜色、工具栏颜色、文本、字体和按钮不会改变_Flutter_Flutter Theme - Fatal编程技术网

Flutter 通过在Flatter应用程序中应用主题数据,Appbar颜色、工具栏颜色、文本、字体和按钮不会改变

Flutter 通过在Flatter应用程序中应用主题数据,Appbar颜色、工具栏颜色、文本、字体和按钮不会改变,flutter,flutter-theme,Flutter,Flutter Theme,例如,若要在按钮上应用主题,我正在执行此操作,但主题在按钮上不起作用 @override Widget build(BuildContext context) { return MaterialApp( title: 'Personal Expenses', theme: ThemeData( brightness: Brightness.light, primaryColor: Colors.lightGreen

例如,若要在按钮上应用主题,我正在执行此操作,但主题在按钮上不起作用

  @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(),
    );
  }

您可以在
AppBarTheme
下设置按钮文本颜色,而不是在
textTheme
中设置按钮文本颜色,您可以在
FlatButton
中引用该主题

这可能会解决你的问题

FlatButton(
  color: Colors.white,
  textColor: Theme.of(context).textTheme.button.color,
  onPressed: _presentDatePicker,
  child: Text(
    'Choose Date',
    style: TextStyle(fontWeight: FontWeight.bold),
  ),
)
或者你可以像这样设置按钮颜色

FlatButton(
  color: Colors.white,
  textColor: Theme.of(context).AppBarTheme.textTheme.button.color,
  onPressed: _presentDatePicker,
  child: Text(
    'Choose Date',
    style: TextStyle(fontWeight: FontWeight.bold),
  ),
)
theme: ThemeData(
    primarySwatch: Colors.purple,
    accentColor: Colors.amber,
    buttonColor: Colors.white,
),
平面按钮中使用该按钮颜色,如下所示

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