解决Flutter报错The named parameter |method ‘xxxx‘ isn‘t defined.

简介: 解决Flutter报错The named parameter |method ‘xxxx‘ isn‘t defined.

场景

更新Flutter到2.0后,某些代码或三方库编译出错。

../../../dev_tools/flutter/.pub-cache/hosted/pub.flutter-io.cn/city_pickers-0.1.18/lib/src/cities_selector/cities_selector.dart:387:9: Error: No named parameter with the name 'resizeToAvoidBottomPadding'.
        resizeToAvoidBottomPadding: false,                              
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
../sdk/flutter/packages/flutter/lib/src/material/scaffold.dart:1437:9: Context: Found this candidate, but the arguments don't match.
const Scaffold({
      ^^^^^^^^ 
 
../../../dev_tools/flutter/.pub-cache/hosted/pub.flutter-io.cn/city_pickers-0.1.18/lib/src/mod/inherit_process.dart:20:20: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../../apps/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inheritFromWidgetOfExactType'.
        context.inheritFromWidgetOfExactType(PageProvider);
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

解决方案

查看具体代码发现,是Scaffold的命名参数未定义,BuildContext的方法未定义 。

resizeToAvoidBottomPadding是Scaffold以前版本的参数,Flutter 2.0后改成了resizeToAvoidBottomInset。

同样的地,inheritFromWidgetOfExactType是BuildContext以前的方法,2.0后改成了dependOnInheritedWidgetOfExactType。

Scaffold(
  backgroundColor: Colors.white,
  // resizeToAvoidBottomPadding: false,
  resizeToAvoidBottomInset: false,
)
//context.inheritFromWidgetOfExactType(PageProvider);
context.dependOnInheritedWidgetOfExactType(aspect: PageProvider);
相关文章
|
3月前
|
缓存 Dart 开发工具
解决Flutter报错The method ‘File.create‘ has fewer named arguments than those of overridden method
解决Flutter报错The method ‘File.create‘ has fewer named arguments than those of overridden method
61 3
|
15天前
|
存储 测试技术 Shell
Flutter UT太多导致跑覆盖率报错
Flutter UT太多导致跑覆盖率报错
25 2
|
3月前
Flutter更改主题颜色报错:type ‘Color‘ is not a subtype of type ‘MaterialColor‘
Flutter更改主题颜色报错:type ‘Color‘ is not a subtype of type ‘MaterialColor‘
44 4
|
3月前
|
开发工具 iOS开发
解决Flutter运行报错Could not run build/ios/iphoneos/Runner.app
解决Flutter运行报错Could not run build/ios/iphoneos/Runner.app
145 2
|
3月前
|
Dart
Flutter使用Scaffold报错。
Flutter使用Scaffold报错。
44 3
|
3月前
|
iOS开发
解决Flutter运行IOS报错:Podfile is out of date
解决Flutter运行IOS报错:Podfile is out of date
79 1
|
3月前
解决Flutter报错boxconstraints has non-normalized height/width constraints
解决Flutter报错boxconstraints has non-normalized height/width constraints
44 0
|
3月前
|
Android开发
解决Android、Flutter编译时Gradle报错:javax.net.ssl.SSLException: Connection reset
解决Android、Flutter编译时Gradle报错:javax.net.ssl.SSLException: Connection reset
378 0
|
API Android开发
Flutter导入第三方包后报错The number of method references in a .dex file cannot exceed 64K
Flutter导入第三方包后报错The number of method references in a .dex file cannot exceed 64K
Flutter的setState的使用注意事项以及报错The method ‘setState‘ isn‘t defined for the type
Flutter的setState的使用注意事项以及报错The method ‘setState‘ isn‘t defined for the type