1. 準備工作
1.1 添加依賴
在pubspec.yaml文件下添加
dependencies:
path_provider: ^1.6.9
1.2 安裝
如果保存了有自動執行則最好,如果沒有那麼在終端運行flutter packages get命令
1.3 導入
import 'package:path_provider/path_provider.dart';
2. 方法
2.1 獲取臨時文件路徑(IOS和安卓通用)
getTemporaryDirectory().then((value) => print(value));
2.2 獲取應用支持目錄(IOS和安卓通用)
getApplicationSupportDirectory().then((value) => print(value));
2.3 獲取應用文件目錄(IOS和安卓通用)
getApplicationDocumentsDirectory().then((value) => print(value));
2.4 獲取應用持久存儲目錄路徑(僅IOS可用)
getLibraryDirectory().then((value) => print(value));
2.5 獲取外部存儲目錄(僅安卓可用)
getExternalStorageDirectory().then((value) => print(value));
2.6 獲取外部存儲目錄列表(僅安卓可用)
getExternalStorageDirectories().then((value) => print(value));
2.7 獲取外部緩存目錄(僅安卓可用)
getExternalCacheDirectories().then((value) => print(value));
2.8 獲取下載目錄(僅桌面可用 安卓和IOS報錯)
getDownloadsDirectory().then((value) => print(value));
插件的內容較少,使用也比較簡單,僅僅只是用於獲取路徑,並沒有操作文件和目錄的功能,因此,需要搭配Director和File等進行操作。