[Flutter]「Don’t import implementation files from another package」の意味と対処法

このページには広告が含まれる場合があります。

 

Flutter(フラッター)のプロジェクトを作る際に、他のパッケージなど、他のDartファイル(ライブラリ)を使うために「import」文を入力すると、

Don’t import implementation files from another package.

という警告と共にimport文の箇所にニョロニョロが表示されることがあります。

これは、他のパッケージ内部で使っている実装用のDartファイルをパッケージ外から直接importしようとする際に発生するようです。

そのような実装用のファイルは、そのパッケージの実装用に使っているファイルであり、パッケージ外から使おうとするとプログラムが壊れてしまう可能性があるため、注意喚起のために警告文を出してくれているようです。

The libraries inside lib are publicly visible: other packages are free to import them. But much of a package’s code is internal implementation libraries that should only be imported and used by the package itself. Those go inside a subdirectory of lib called src. You can create subdirectories in there if it helps you organize things.

You are free to import libraries that live in lib/src from within other Dart code in the same package (like other libraries in lib, scripts in bin, and tests) but you should never import from another package’s lib/src directory. Those files are not part of the package’s public API, and they might change in ways that could break your code.

もし、この警告にも関わらず、今回の動画の例のように使っても大丈夫という確信がある場合は、「Suppress ‘implementation_imports’ warning」を押してやると、ニョロニョロを消すことができます。

(詳しくは、以下の動画で解説してしまうので、よろしければご覧下さい)

こんな記事も読まれています

イチオシ

40代から感じるモヤモヤを解消できる 無料動画セミナー

あすコロ式・40代からの人生アップデート【新】戦略

アラフォーでキャリアを失ったバリバリ左脳人間・スピリチュアル耐性ゼロの元金融マンが、人生どん底から立ち上がる過程でたどり着いた「人生再構築メソッド」。40代・50代を過ぎて多くの人が感じる「このままでいいんかな?」「この先どうしたらいいかわからない」というモヤモヤを解消し、人生後半戦をアップデートさせる【新】戦略。

今すぐ無料で動画セミナー(80分)を見る ▶

TOP