[英]How can I upgrade a "RaisedButton" to "ElevatedButton" in Flutter?
I got the following code and want to make it work:我得到以下代码并想让它工作:
RaisedButton(
child:
Text(_authMode == AuthMode.Login ? 'LOGIN' : 'SIGN UP'),
onPressed: _submit,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
padding:
EdgeInsets.symmetric(horizontal: 30.0, vertical: 8.0),
color: Theme.of(context).primaryColor,
textColor: Theme.of(context).primaryTextTheme.button.color,
),
I tried to change it to some point as the following:我试图将其更改为如下所示:
ElevatedButton(
child:
Text(_authMode == AuthMode.Login ? 'LOGIN' : 'SIGN UP'),
onPressed: _submit,
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
)
)
),
padding:
EdgeInsets.symmetric(horizontal: 30.0, vertical: 8.0),
color: Theme.of(context).primaryColor,
textColor: Theme.of(context).primaryTextTheme.button.color,
),
But I don't know what to do with padding
, color
, and textColor
?但我不知道如何处理
padding
、 color
和textColor
?
Here's how to convert the RaisedButton
to an ElevatedButton
.以下是将
RaisedButton
转换为ElevatedButton
的方法。
On the ElevatedButton
use:在
ElevatedButton
上使用:
textColor
use the TextStyle
on the Text
widget.textColor
,请使用Text
小部件上的TextStyle
。shape
, use the style
property.style
属性代替shape
。color
, use the style
property.color
,使用style
属性。padding
, use the style
property.padding
,使用style
属性。 Your code should look like this:您的代码应如下所示:
ElevatedButton(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 8.0),
backgroundColor: Theme.of(context).primaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
),
child: Text(
_authMode == AuthMode.Login ? 'LOGIN' : 'SIGN UP',
style: TextStyle(
color: Theme.of(context).primaryTextTheme.button?.color),
),
onPressed: _submit,
)
Try this试试这个
ElevatedButton(
child: Text(_authMode == AuthMode.Login ? 'LOGIN' : 'SIGN UP',
style:TextStyle(color:
Theme.of(context).primaryTextTheme.button?.color)),
onPressed: _submit,
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 8.0),
backgroundColor: Theme.of(context).primaryColor,
),
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.