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

问题描述

Flutter SDK更新到3.7.9后,运行项目出来以下错误提示。

Could not build the precompiled application for the device.
Error (Xcode): ../../../.pub-cache/hosted/pub.flutter-io.cn/file-6.1.2/lib/src/interface/file.dart:15:16: Error: The method 'File.create' has fewer named arguments than those of overridden method 'File.create'.


Error launching application on iPhone.

解决方案

根据错误提示,是某个库依赖了google的file库的6.1.2版本,File.create方法需要几个参数。

我们进入pub中查看file的更新信息。

file|dart package:https://pub.flutter-io.cn/packages/file/changelog

可以看到,从6.1.3开始,create方法增加了一个bool类型的参数,所以我们只需要将file库的版本升级到6.1.3以上即可。

项目中覆盖库版本

最粗暴的方式是直接在项目的pubspec.yaml中指定file库的版本,这样编译时会统一库的版本。

name: wiki assit
description: A new Flutter application 

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.2.0+4

environment:
  sdk: ">=2.17.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  # 指定 file 版本,6.1.3及以上就行
  file: ^6.1.4

使用pub命令

因为不是在项目中直接引用的,所以只能通过pub命令的方式解决依赖。

首先,要清除一下缓存.

flutter clean.

然后使用pub upgrade更新依赖

flutter pub upgrade

等待依赖更新完成,重新运行项目就能正常跑起来了。

相关文章
|
2月前
Flutter更改主题颜色报错:type ‘Color‘ is not a subtype of type ‘MaterialColor‘
Flutter更改主题颜色报错:type ‘Color‘ is not a subtype of type ‘MaterialColor‘
32 4
|
2月前
|
开发工具 iOS开发
解决Flutter运行报错Could not run build/ios/iphoneos/Runner.app
解决Flutter运行报错Could not run build/ios/iphoneos/Runner.app
101 2
|
2月前
解决Flutter报错The named parameter |method ‘xxxx‘ isn‘t defined.
解决Flutter报错The named parameter |method ‘xxxx‘ isn‘t defined.
84 3
|
2月前
|
Dart
Flutter使用Scaffold报错。
Flutter使用Scaffold报错。
33 3
|
2月前
|
iOS开发
解决Flutter运行IOS报错:Podfile is out of date
解决Flutter运行IOS报错:Podfile is out of date
45 1
|
2月前
解决Flutter报错boxconstraints has non-normalized height/width constraints
解决Flutter报错boxconstraints has non-normalized height/width constraints
30 0
|
2月前
|
Android开发
解决Android、Flutter编译时Gradle报错:javax.net.ssl.SSLException: Connection reset
解决Android、Flutter编译时Gradle报错:javax.net.ssl.SSLException: Connection reset
177 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的解决方法
下一篇
无影云桌面