解决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);

你可能感兴趣的:(Flutter踩坑集合,Flutter,Scaffold,BuildContext)