path_provider_riverpod 1.0.0+1
path_provider_riverpod: ^1.0.0+1 copied to clipboard
Riverpod Provider for path_provider
path_provider
ライブラリを Riverpod で使用するための Provider 集です。
アプリケーションで使用する各種ディレクトリパスを同期的に取得できます。
Features #
以下のディレクトリパスを Riverpod の Provider として提供します:
applicationCacheDirectory
- アプリケーションキャッシュディレクトリapplicationDocumentsDirectory
- アプリケーションドキュメントディレクトリapplicationSupportDirectory
- アプリケーションサポートディレクトリdownloadsDirectory
- ダウンロードディレクトリexternalStorageDirectory
- 外部ストレージディレクトリlibraryDirectory
- ライブラリディレクトリtemporaryDirectory
- テンポラリディレクトリ
Getting started #
pubspec.yaml
に依存関係を追加します:
dependencies:
path_provider_riverpod: ^1.0.0
- アプリケーション起動時に Provider を初期化します:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final overrides = await PathProviders.inject();
runApp(
ProviderScope(
overrides: overrides,
child: MyApp(),
),
);
}
Usage #
Provider を使用してディレクトリパスを取得できます:
class MyWidget extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final cacheDir = ref.watch(PathProviders.applicationCacheDirectory);
final documentsDir = ref.watch(PathProviders.applicationDocumentsDirectory);
return Column(
children: [
Text('Cache: ${cacheDir.path}'),
Text('Documents: ${documentsDir.path}'),
],
);
}
}
テスト時には injectWithValue
メソッドを使用して任意のディレクトリを設定できます:
testWidgets('test', (tester) async {
await tester.pumpWidget(
ProviderScope(
overrides: PathProviders.injectWithValue(
temporaryDirectory: Directory('/tmp/test'),
),
child: MyApp(),
),
);
});
Additional information #
このパッケージは path_provider
ライブラリの Riverpod ラッパーです。
各ディレクトリの詳細については path_provider
パッケージのドキュメントを参照してください。
バグレポートや機能要求は、GitHub リポジトリの Issues ページで受け付けています。