🧳

【Flutter】パッケージを追加できない時にやったこと

2023/05/04に公開

パッケージをライブラリとして追加する方法(確認)

コマンドを実行

$ flutter pub add <パッケージ名>

もしくは

pubspec.yamlに追記

dependencies:
  <パッケージ名>: <バージョン>

追記したら下記を実行します。(エディタによっては、pubspec.yamlを保存したタイミングで、自動で実行されます)

flutter pub get

今回起こったエラー

https://pub.dev/packages/cloud_firestore
cloud_firestore 4.5.3をコマンドから追加しました。
pubspec.yamlでも追加が確認できましたが、importのところでエラーが出ました。

エラー文

Target of URI doesn't exist: 'package:cloud_firestore/cloud_firestore.dart'.
Try creating the file referenced by the URI, or try using a URI for a file that does exist.

やったこと

flutter clean

特に問題は解決せず。

flutter packages get
flutter packages upgrade
VScodeを再起動

問題解決👏

(参考)
https://stackoverflow.com/questions/44909653/visual-studio-code-target-of-uri-doesnt-exist-packageflutter-material-dart

Discussion