将已弃用的 RaisingButton 替换为 ElevatedButton

use*_*216 2 button dart deprecation-warning flutter

我用的是RaisedButton这样的方式:

RaisedButton(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24.0)),
                        onPressed: null,
                        padding: EdgeInsets.all(12.0),
                        color: Colors.blue,
                        child: Text("Button", style: TextStyle(color: Colors.white)))
Run Code Online (Sandbox Code Playgroud)

他们决定RaisedButton弃用并ElevatedButton应该使用。但是,paddingshape属性缺失。如何获得相同的效果ElevatedButton

小智 5

只需用这个替换你的代码

ElevatedButton(
style: ElevatedButton.styleFrom(
  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24.0)),
  padding: const EdgeInsets.all(12.0),
  primary: Colors.blue,
),
onPressed: null,
child: const Text('Button', style: TextStyle(color: Colors.white))),
Run Code Online (Sandbox Code Playgroud)