Flutter中RaisedButton替换为ElevatedButton的样式适配求助
直接上转换后的完整代码:
Padding( padding: const EdgeInsets.symmetric(horizontal: 40.0), child: ElevatedButton( child: Text( "Gruppen Id kopieren", style: TextStyle( color: Colors.white, ), ), onPressed: () => _copyGroupId(context), style: ButtonStyle( // 对应原RaisedButton的color属性 backgroundColor: MaterialStateProperty.all(Color.fromRGBO(245, 168, 0, 1)), // 对应原RaisedButton的shape属性 shape: MaterialStateProperty.all(RoundedRectangleBorder( borderRadius: BorderRadius.circular(20.0), side: BorderSide( color: Theme.of(context).secondaryHeaderColor, width: 2, ), )), ), ), ),
关键属性映射说明:
- 原
RaisedButton的color:需要放到ButtonStyle的backgroundColor中,用MaterialStateProperty.all()包裹颜色值——ElevatedButton的样式属性支持区分不同状态(如按下、禁用)的样式,若不需要区分状态,用all()设置固定值即可。 - 原
RaisedButton的shape:直接移到ButtonStyle的shape字段,同样用MaterialStateProperty.all()包裹原有RoundedRectangleBorder配置。 child、onPressed这类属性用法和原代码完全一致,无需修改。
内容的提问来源于stack exchange,提问作者paddy708
相关产品推荐
相关产品推荐

