解决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);
相关文章
|
2月前
|
缓存 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
54 3
|
2月前
Flutter更改主题颜色报错:type ‘Color‘ is not a subtype of type ‘MaterialColor‘
Flutter更改主题颜色报错:type ‘Color‘ is not a subtype of type ‘MaterialColor‘
36 4
|
2月前
|
开发工具 iOS开发
解决Flutter运行报错Could not run build/ios/iphoneos/Runner.app
解决Flutter运行报错Could not run build/ios/iphoneos/Runner.app
120 2
|
2月前
|
Dart
Flutter使用Scaffold报错。
Flutter使用Scaffold报错。
38 3
|
2月前
|
iOS开发
解决Flutter运行IOS报错:Podfile is out of date
解决Flutter运行IOS报错:Podfile is out of date
60 1
|
2月前
解决Flutter报错boxconstraints has non-normalized height/width constraints
解决Flutter报错boxconstraints has non-normalized height/width constraints
36 0
|
2月前
|
Android开发
解决Android、Flutter编译时Gradle报错:javax.net.ssl.SSLException: Connection reset
解决Android、Flutter编译时Gradle报错:javax.net.ssl.SSLException: Connection reset
252 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
|
Linux 开发者 Windows
Flutter报错Building with plugins requires symlink support的解决方法
Flutter报错Building with plugins requires symlink support的解决方法