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.在 flutter_cupertino_date_picker-1.0.26+2\lib\src 文件内找到 shadowThemeOnly ,注释掉
- theme: Theme.of(context, /* shadowThemeOnly: true*/),
3.inheritFromWidgetOfExactType 报错
原因: inheritFromWidgetOfExactType 这个方法不在用了,改用了 dependOnInheritedWidgetOfExactType
解决办法:
- 找到: 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