0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

FileNotFoundErrorというエラーについて

Posted at

FileNotFoundErrorが起きた状況

APIキーをハードコーディングしていましたが、セキュリティの面で推奨されないので、.envファイルを作成しそこで管理するように変更したところエラーが起きました。

解決方法

pubspec.yamlに追加できていない項目があったのでそれを追加した。

dependencies:
  flutter:
    sdk: flutter
  flutter_dotenv: ^5.2.1   //ここは追加していた
flutter:
  uses-material-design: true
  assets:
    - .env    //ここが追加できていなかった

解決理由

  • Flutter では、アプリ内で使用する静的リソース(画像、フォント、JSON ファイルなど)を アセットとして管理します。
  • .envファイルも静的リソースの一種であるため、Flutter にその存在を認識させる必要があります。
  • そのため、.envファイルを見つけることができずにFileNotFoundErrorというエラが表示されました。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?