flutter - Flutter FlatButton is deprecated - alternative solution with width and height
问题描述
After Flutter Upgrade "FlatButton" is deprecated and I have to use TextButton instead. I didn't find a solution for a new button-type with width and height.
This is my working FlatButton. How can I solve it with textButton or elevatedButton?
_buttonPreview(double _height, double _width) {
return FlatButton(
onPressed: () { },
height: _height,
minWidth: _width,
color: Colors.grey,
padding: EdgeInsets.all(0),
child: Text(
"some text",
style: TextStyle(color: Colors.white),
),
);
}
解决方案
I followed the guide here: https://flutter.dev/docs/release/breaking-changes/buttons.
_buttonPreview(double _height, double _width) {
final ButtonStyle flatButtonStyle = TextButton.styleFrom(
minimumSize: Size(_width, _height),
backgroundColor: Colors.grey,
padding: EdgeInsets.all(0),
);
return TextButton(
style: flatButtonStyle,
onPressed: () {},
child: Text(
"some text",
style: TextStyle(color: Colors.white),
),
);
}
推荐阅读
- php - 使用 PHP 和 Proxy 卷曲并返回结果
- javascript - CSS:拉伸 div 以适应宽度,仅当它们在彼此的 y 轴空间内时
- java - 程序不能从 ZyBooks 读取文件,但可以在 Eclipse 上运行
- jdbc - HSQL 中的 setArray() 异常
- javascript - 如何使用 JavaScript 创建用户名正则表达式?
- python - 更改 sklearn 管道的参数
- javascript - 需要回答“参数 (number[]) 与 SpreadsheetApp.Range.setValues 的方法签名不匹配”错误
- r - R Regex:修改字符串末尾不同长度的数字
- firebase - 无法从数据库获取 DataSnapshot 并获取空值
- python - 对于特定的 pep8 问题,什么是解析 python 代码的更好方法