Flutter 3.3.6 中FlatButton, RaisedButton, & OutlineButton找不到

在Flutter 3.3.6版本中,FlatButton, RaisedButton和OutlineButton已被废弃。这些控件被新版的 ElevatedButton, TextButton和OutlineButton所取代,同时使用了新的关联主题。开发者需要进行代码迁移以适配新版本。" 111737464,10293242,Flutter AOP实践:AspectD框架解析,"['Flutter框架', 'Dart编程', 'AOP实践', '代码增强', '自动化录制回放']

Flutter 3.3.6 中FlatButton, RaisedButton, & OutlineButton找不到

昨天将Flutter 的SDK升级到3.3.6,今天打开项目的时候红了一片,发现很多button控件找不到了。

报错如下:

在这里插入图片描述
我的FlutterSDK的版本信息是:

Flutter 3.3.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 6928314d50 (6 days ago) • 2022-10-25 16:34:41 -0400
Engine • revision 3ad69d7be3
Tools • Dart 2.18.2 • DevTools 2.15.0
去查了下api看到原文

Supported by Flutter Fix: no

The FlatButton, RaisedButton, and OutlineButton widgets were first deprecated in v1.20, and then extended in v1.26.

They are replaced by new buttons, TextButton, ElevatedButton, and OutlinedButton. These new widgets also use new associated themes, rather than the generic ButtonTheme.

Old WidgetOld ThemeNew WidgetNew Theme
FlatButtonButtonThemeTextButtonTextButtonTheme
RaisedButtonButtonThemeElevatedButtonElevatedButtonTheme
OutlineButtonButtonThemeOutlinedButtonOutlinedButtonTheme
总结:
  • FlatButton, RaisedButton, and OutlineButton这三个widget 已经有了新的控件替代,并且有新的主题

    做对应的替换即可

Code before migration:

FlatButton(
  onPressed: onPressed,
  child: Text('Button'),
  // ...
);

RaisedButton(
  onPressed: onPressed,
  child: Text('Button'),
  // ...
);

OutlineButton(
  onPressed: onPressed,
  child: Text('Button'),
  // ...
);

Code after migration:

TextButton(
  onPressed: onPressed,
  child: Text('Button'),
  // ...
);

ElevatedButton(
  onPressed: onPressed,
  child: Text('Button'),
  // ...
);

OutlinedButton(
  onPressed: onPressed,
  child: Text('Button'),
  // ...
);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值