flutter - Flutter 全局定义按钮样式
问题描述
所以我想全局定义我的按钮样式,以便我可以一次访问它们。我已经为 TextStyle 启用了这个功能,如下所示:
abstract class ThemeText {
static const TextStyle exampleStyle= TextStyle(
fontFamily: 'Montserrat',
color: Colors.black,
fontSize: 40,
height: 0.5,
fontWeight: FontWeight.w600);
}
当我像这样在我的文本中访问它时:
child: TextButton(
onPressed: (){},
child: Text("Test",
style: ThemeText.progressHeader,),
)
它就像一个魅力。
现在我想对我的 ButtonStyle 做同样的事情:
TextButton(
style: TextButton.styleFrom(
primary: Colors.white,
backgroundColor: Colors.green[900],
textStyle: TextStyle(fontSize: 18, fontStyle: FontStyle.italic)),
child: Text("Test!"),
)
但是,如果我尝试相同的方法,无论我如何编写它,我总是会收到消息“const variables must be initialized with a constant value”。如何为按钮设置它的格式,以便它像 TextStyle 一样工作?
非常感谢您!
解决方案
推荐阅读
- loops - 从两个表中获取不相交的元素
- git - Azure Devops 触发管道,从 Bitbucket 推送标签
- java - 相同的颜色在不同的视图上显示不同
- php - 如何使用 curl 在 watson 助手中传递 apikey 和助手 url 而不是用户名和密码
- ruby-on-rails - 从 Rails 类实例获取信息
- javascript - 从锚点到锚点滚动多个 div
- angular - PrimeNG 不能在 Angular 库中使用?
- c++ - 如何使用 boost::asio 为 UDP 发现和 TCP 连接序列化类
- python - Plotly AttributeError:“Figure”对象没有属性“update_traces”
- mysql - WHERE 在时间范围内不与 LEFT JOIN 一起工作,我该如何纠正?