问题复现
flutter运行:flutter packages pub run build_runner build时报错:
Deprecated. Use `dart run` instead.
Building package executable... (1.3s)
Failed to build build_runner:build_runner:
/C:/Users/11072/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/build_runner_core-7.2.2/lib/src/logging/build_for_input_logger.dart:13:7: Error: The non-abstract class 'BuildForInputLogger' is missing implementations for the
se members:
- Logger.onLevelChanged
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class BuildForInputLogger implements Logger {
^^^^^^^^^^^^^^^^^^^
/C:/Users/11072/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/logging-1.2.0/lib/src/logger.dart:162:22: Context: 'Logger.onLevelChanged' is defined here.
Stream<Level?> get onLevelChanged {
^^^^^^^^^^^^^^
/C:/Users/11072/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/build_runner-2.1.11/lib/src/build_script_generate/bootstrap.dart:76:40: Error: Method not found: 'NullThrownError'.
final error = e[0] as Object? ?? NullThrownError();
^^^^^^^^^^^^^^^
造成原因
这个是flutter版本与dart版本不匹配导致的,需要更新版本。
解决步骤
1.运行命令flutter upgrade
有些运行此命令后,会提示:Unknown flutter tag. Abandoning upgrade to avoid destroying local changes. It is recommended to use git directly if not working on an official channel.
如果遇到这种情况需要强制更新,运行命令:flutter upgrade --force
等待更新结束即可:
2.运行命令:dart pub upgrade
等待更新完成