path_provider_riverpod 1.0.0+1 copy "path_provider_riverpod: ^1.0.0+1" to clipboard
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 #

  1. pubspec.yaml に依存関係を追加します:
dependencies:
  path_provider_riverpod: ^1.0.0
  1. アプリケーション起動時に 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 ページで受け付けています。

0
likes
135
points
33
downloads

Publisher

unverified uploader

Weekly Downloads

Riverpod Provider for path_provider

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_riverpod, path_provider

More

Packages that depend on path_provider_riverpod