flutter - 如何从 RaisedButton 创建 ElevatedButton?
问题描述
有很多属性,RaisedButton
我在ElevatedButton
. 那么,如何将 a RaisedButton
(具有所有属性)转换或复制到 new ElevatedButton
?
喜欢:
RaisedButton(
onPressed: () {},
color: Colors.indigoAccent,
disabledColor: Colors.indigo,
textColor: Colors.white,
disabledTextColor: Colors.grey,
hoverColor: Colors.pinkAccent,
splashColor: Colors.black,
elevation: 12.0,
padding: EdgeInsets.all(20),
shape: StadiumBorder(),
child: Text('Button'),
)
解决方案
您应该改用您的theme
属性MaterialApp()
和相应的按钮主题,例如:
MaterialApp(
theme: ThemeData(
primaryColor: Colors.blue,
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
primary: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
textStyle: TextStyle(fontSize: 20.0)
)
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
primary: Colors.black,
textStyle: TextStyle(
fontWeight: FontWeight.bold
)
)
),
),
)
对于单个按钮样式,您可以使用:
ElevatedButton(
style: ElevatedButton.styleFrom(
minimumSize: Size(30.0, 36.0),
primary: Colors.green,
padding: EdgeInsets.all(15.0),
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(10.0)
),
),
),
另请参阅新按钮和按钮主题
推荐阅读
- java - Cloud Pub/Sub Java 客户端 API 示例无法在本地运行
- java - 我正在尝试从每个循环的两个中检索结果
- javascript - 反应不重新获取过期的缓存文件
- android - Play Store 应用程序不会自动更新并出现错误:APP_IN_FOREGROUND
- unity3d - 使用 Physics 2D 拖动播放器对象
- r - R,时变因子。如何找到最接近某个时间的值?
- ruby-on-rails - 如何检查数组中是否存在值?
- azure - 使用 JSON 表处理逻辑应用中的空值并编写对象
- c++ - 使用 ASIO SDK 2.3 I/O 的任意播放软件的实时均衡器
- postgresql - 在没有互联网的情况下从 mac 连接到 docker postgresql