我试图在复制ThemeData.light()
之后更改accentColor
,然后我有了一个带有FloatingActionButton
的示例屏幕。
class Sample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.add),
),
)}}
接下来在main.dart
中的主widget中调用runApp
,如果我为MaterialApp
widget设置ThemeData
,如此设置,FloatingActionButton
将具有橙色。
theme: ThemeData(
accentColor: Colors.orange
)
但是如果我尝试从Themedata.light().copyWith
继承颜色,那么FloatingActionButton
仍然会从浅色主题中继承蓝色。
theme: ThemeData.light().copyWith(
accentColor: Colors.orange
)
我原本期望浮动操作按钮(FloatingActionButton)的颜色是橙色的,因为它继承了“亮色”主题并覆盖了“强调颜色”(accentColor)。