flutter1.9升级flutter2.0错误整理

flutter 2.0 变化还是比较大了,好多代码都变了,下面整理一些升级过程中遇到的错误.

1 resizeToAvoidBottomPadding

city_pickers插件:
resizeToAvoidBottomPadding:false, 改为 resizeToAvoidBottomInset: false,

2.Error: No named parameter with the name ‘shadowThemeOnly’

../../flutter/.pub-cache/hosted/pub.flutter-io.cn/flutter_cupertino_date_picker-1.0.26+2/lib/src/date_picker.dart:103:34: Error: No named parameter with the name 'shadowThemeOnly'.
        theme: Theme.of(context, shadowThemeOnly: true),
                                 ^^^^^^^^^^^^^^^
../../flutter/packages/flutter/lib/src/material/theme.dart:106:20: Context: Found this candidate, but the arguments don't match.
  static ThemeData of(BuildContext context) {

出错原因: shadowThemeOnly 被移除
解决方案:

  1. 1.在 flutter_cupertino_date_picker-1.0.26+2\lib\src 文件内找到 shadowThemeOnly ,注释掉
  2. theme: Theme.of(context, /* shadowThemeOnly: true*/),

3.inheritFromWidgetOfExactType 报错

原因: inheritFromWidgetOfExactType 这个方法不在用了,改用了 dependOnInheritedWidgetOfExactType
解决办法:

  1. 找到: hosted\pub.flutter-io.cn\provide-1.0.2\lib\provide.dart 570行
final widget = context.inheritFromWidgetOfExactType(_InheritedProviders);

2.改成:

 final widget = context.dependOnInheritedWidgetOfExactType(aspect:_InheritedProviders);

4.Error Type ‘‘DiagnosticableMixin‘ not found’.

原因: flutter1.20 之后 DiagnosticableMixin 被移除了
解决办法:
	1. 在lib/src/date_picker_theme.dart中找到DateTimePickerTheme类
	2.  将继承的DiagnosticableMixin 类替换为 Diagnosticable类

5.Error: No named parameter with the name ‘nullOk’

移除nullOK 参数

// final ScaffoldState scaffold = Scaffold.of(context, nullOk: true);
final ScaffoldState scaffold = Scaffold.of(context);

// Localizations.localeOf(context, nullOk: true);
Localizations.localeOf(context);

6.ancestorInheritedElementForWidgetOfExactType is deprecated

flutter 1.12.1 之后 ancestorInheritedElementForWidgetOfExactType 改为了
getElementForInheritedWidgetOfExactType
解决办法:
找到provide 文件 32 line
将 context.ancestorInheritedElementForWidgetOfExactType(type)?.widget;
改为 context.getElementForInheritedWidgetOfExactType(type)?.widget;

7.关于状态管理插件provide 最好换成provicer 因为 provide 插件好久都没有更新了,关于 provider的用法参考 pub.dev

	操作某个实体时候 用 Provider.of<?>(context,listen: false)  
	context 声明为: BuildContext 
	注意listen 置为false
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值