3
1

More than 1 year has passed since last update.

【Flutter】デバイスのローカルファイルをアクセス

Posted at

目的

Flutterで端末にファイルを保存したら、読み取りしたり、削除したりしたいするのが目的です。
下記のSDKを使うことで実現できます。

SDK導入

dependencies:
  flutter:
    sdk: flutter
  path_provider: ^2.0.15

サポートするフラットフォーム

各種ディレクトリサポートされるフラットフォームは下記Githubリポジトリに記載されています。

Directory Android iOS Linux macOS Windows
Temporary ✔️ ✔️ ✔️ ✔️ ✔️
Application Support ✔️ ✔️ ✔️ ✔️ ✔️
Application Library ❌️ ✔️ ❌️ ✔️ ❌️
Application Documents ✔️ ✔️ ✔️ ✔️ ✔️
External Storage ✔️ ❌️ ❌️
External Cache Directories ✔️ ❌️ ❌️
External Storage Directories ✔️ ❌️ ❌️
Downloads ✔️ ✔️ ✔️ ✔️

Temporary

関数:

Future<Directory> getTemporaryDirectory() async {

バックアップされておらず、ダウンロードされたファイルのキャッシュを保存するのに適したデバイス上の一時ディレクトリへのパス。

  • iOS
    /Users/<user>/Library/Developer/CoreSimulator/Devices/<device_id>/data/Containers/Data/Application/<app_id>/Library/Caches
    
  • Android
    /data/user/0/YOUT_APP_ID/cache
    

Application Support

関数:

Future<Directory> getApplicationSupportDirectory() async {

アプリケーションがアプリケーションサポート ファイルを配置するディレクトリへのパス。

  • iOS
    /Users/<user>/Library/Developer/CoreSimulator/Devices/<device_id>/data/Containers/Data/Application/<app_id>/Library/Application Support
    
  • Android
    /data/user/0/YOUT_APP_ID/files
    

Application Library

関数;

Future<Directory> getLibraryDirectory() async {

アプリケーションが永続的なファイルを保存できるディレクトリへのパス。例えば:sqlite.db。

  • iOS
    /Users/<user>/Library/Developer/CoreSimulator/Devices/<device_id>/data/Containers/Data/Application/<app_id>/Library
    
  • Android
    サポートされてない

Application Documents

関数:

Future<Directory> getApplicationDocumentsDirectory() async {

アプリケーションがデータを配置するディレクトリへのパス
ユーザーが生成したもの、またはアプリケーションで再作成できないもの。

  • iOS
  • Android
    /data/user/0/YOUT_APP_ID/app_flutter
    

External Storage

関数:

Future<Directory?> getExternalStorageDirectory() async {

アプリケーションが最上位のストレージにアクセスできるディレクトリへのパス。
この機能は Android でのみ利用できるため、この関数呼び出しを発行する前に現在のOSを確認する必要があります。

  • iOS
    サポートされてない
  • Android
    /storage/emulated/0/Android/data/YOUT_APP_ID/files
    

External Cache Directories

関数:

Future<List<Directory>?> getExternalCacheDirectories() async {

アプリケーション固有の外部キャッシュ データを保存できるディレクトリへのパス。 これらのパスは通常、個別のパーティションや SD カードなどの外部ストレージ上に存在します。

  • iOS
    サポートされてない
  • Android
    [Directory: '/storage/emulated/0/Android/data/YOUT_APP_ID/cache']
    

External Storage Directories

関数:

Future<List<Directory>?> getExternalStorageDirectories({

アプリケーション固有の外部キャッシュ データを保存できるディレクトリへのパス。 これらのパスは通常、個別のパーティションや SD カードなどの外部ストレージ上に存在します。

  • iOS
    サポートされてない
  • Android
    [Directory: '/storage/emulated/0/Android/data/YOUT_APP_ID/files']
    

Downloads

関数:

Future<Directory?> getDownloadsDirectory() async {

ダウンロードしたファイルを保存できるディレクトリへのパス。
返されたディレクトリは存在することが保証されていないため、サポートするフラットフォームの確認が必要です。

  • iOS
    /Users/<user>/Library/Developer/CoreSimulator/Devices/<device_id>/data/Containers/Data/Application/<app_id>/Documents
    
  • Android
    サポートされてない
3
1
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
3
1