我已经迁移到 Flutter 2.0,这只是现在的新版本。在我的项目中我使用过Flat Buttons
,但它现在在 Flutter 2.0 中已被弃用,并且弹出建议使用Text Button
而不是Flat Buttons
.
现在的问题在于Flat Buttons
有选项可以直接设置按钮的属性,例如,color, padding etc.
但是当我将其替换Text Button
为使用此属性时出现错误。我检查了文档,发现有style: ButtonStyle(backgroundcolor: ____________)
. 但是当我放入Colors.blue
属性backgroundcolor
时,它给了我错误。
所以我想知道Buttons
Flutter 2.0 中的行为如何以及我们如何style
做到Buttons
?
我的代码片段在这里,我想在其中设置按钮样式。
Container(
width: 200.0,
child: TextButton(
style: ButtonStyle(), // I want to style this.
onPressed: () => Navigator.pushNamed(context, SignupPage.id),
/*color: Colors.blue,
padding: const EdgeInsets.all(10.0),*/ //Commented code is deprecated in Flutter 2.0
child: Text(
'Create Account',
style: TextStyle(color: Colors.white, fontSize: 16.0),
),