有人可以帮助指出我们如何定义按钮的基本主题并在每个按钮上使用它吗?我到处寻找才发现textTheme
但不是buttonTheme
例子?
Even on buttonTheme
我们如何定义文本颜色?
因为在按钮本身上我们可以直接这样做color: Colors.blue
一种方法是定义buttonTheme
in theme
in MaterialApp
:
E.g:
void main() {
runApp(MaterialApp(
home: Home(),
theme: ThemeData(
accentColor: Colors.redAccent,
buttonTheme: ButtonThemeData(
buttonColor: Colors.blueAccent,
shape: RoundedRectangleBorder(),
textTheme: ButtonTextTheme.accent,
....
)),
));
}
class Home extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Button Theme"),
backgroundColor: Colors.green),
body: Center(
child: RaisedButton( //Button Color is as define in theme
onPressed: () {},
child: Text("Send"), //Text Color as define in theme
)),
);
}
}
在此下定义的所有按钮MaterialApp
将携带此主题风格。
文本颜色将是accentColor
定义在ThemeData
正如我所定义的textTheme: ButtonTextTheme.accent
所以它会选择accentColor
按钮选择主题样式定义于theme
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)