简体   繁体   English

如何在 Flutter 中将“RaisedButton”升级为“ElevatedButton”?

[英]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 ?但我不知道如何处理paddingcolortextColor

Here's how to convert the RaisedButton to an ElevatedButton .以下是将RaisedButton转换为ElevatedButton的方法。

On the ElevatedButton use:ElevatedButton上使用:

  • For the textColor use the TextStyle on the Text widget.对于textColor ,请使用Text小部件上的TextStyle
  • For rounded corners, instead of shape , use the style property.对于圆角,使用style属性代替shape
  • For the color , use the style property.对于color ,使用style属性。
  • For 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,
    )

See also:也可以看看:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM