323 文字
2 分
[flutter] Error: The class 'FileSystemEvent' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. の対処メモ
flutterでアプリ開発してたらエラーではまったのでその対応メモです。
なお開発環境は次の通りです。
- Windows 10
- flutter 3.22.0
事象
mockを更新しようと次のコマンドを実行すると
$ dart run build_runner build以下のようなエラーが出て失敗しました。
Resolving dependencies in `E:\sample_project`...Downloading packages...Got dependencies in `E:\sample_project`.Building package executable... (1.0s)Failed to build build_runner:build_runner:/C:/Users/User/AppData/Local/Pub/Cache/hosted/pub.dev/watcher-1.0.2/lib/src/constructable_file_system_event.dart:7:57: Error: The class 'FileSystemEvent' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.abstract class _ConstructableFileSystemEvent implements FileSystemEvent { ^Failed to build build_runner:build_runner:/C:/Users/User/AppData/Local/Pub/Cache/hosted/pub.dev/watcher-1.0.2/lib/src/constructable_file_system_event.dart:7:57: Error: The class 'FileSystemEvent' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.abstract class _ConstructableFileSystemEvent implements FileSystemEvent {原因
watcher 1.0.2を利用しているのが原因です。現時点の最新バージョンであるwatcher 1.1.0にバージョンを上げると解決しました。
対応方法
pubspec.lockで指定されているwatcherのバージョンを1.1.0に上げられればいいわけです。
pubspec.ymlでバージョンを固定していないなら、次のコマンドで手っ取り早くwatcherのバージョンだけ更新できます。
$ flutter pub upgrade watcher更新後のpubspec.lockを確認すると、watcher 1.1.0に上がって問題のエラーが出なくなっていると思います。
参考