パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.2.1-prerelease

riverpod_navigation

riverpod を使って Flutter のナビゲーションを管理する

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
14
いいね数
27
Pub ポイント
120

パッケージをインストール

flutter pub add riverpod_navigation

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

RiverpodNavigation は、Riverpod ステート管理システムとシームレスに統合することで、ナビゲーション管理を簡素化する Flutter パッケージです。ルートおよびナビゲーションイベントの処理に対してリアクティブで型安全なアプローチを提供し、開発者がアプリのナビゲーションを宣言的にかつ効率的に管理できるようにします。Riverpod の依存性注入とステート管理機能を活用することで、ルーティングロジックと UI コンポーネント間の責任の明確な分離が可能になります。このパッケージは、Android、iOS、Web、macOS、Windows、Linux などすべての主要プラットフォームをサポートしており、クロスプラットフォームアプリに最適です。

用途

  • 宣言的ルート管理
  • クロスプラットフォームナビゲーション
  • リアクティブなナビゲーションフロー
  • ステート駆動ルーティング
  • Riverpod ステートとの統合
  • ダイナミックルート処理

主な機能

  • Riverpod ベースのナビゲーション
  • 型安全なルート定義
  • リアクティブなナビゲーションの更新
  • プラットフォームに依存しない設計
  • ルーティングロジックの明確な分離
  • ネストされたナビゲーターのサポート

適している対象

  • Riverpod を使用する開発者
  • クロスプラットフォームのFlutterアプリ
  • 複雑なナビゲーションシナリオ
  • 状態認識ルーティングを必要とするアプリ
  • 保守可能なコードを重視するチーム
  • 動的ルート要件を備えたプロジェクト

注意事項

  • Riverpodに精通している必要がある
  • シンプルなアプリのためのボイラープレートが増える可能性があります
  • 新規ユーザー向けの学習曲線
  • 他の代替品と比べてドキュメントが限られている
  • 非Riverpodプロジェクトには適していません
  • 大規模なナビゲーターにおける潜在的なパフォーマンスオーバーヘッド

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Navigation for Riverpod

Managing Flutter navigation with riverpod.

Usage

Bootstrap

Replace your root ProviderScope with a RiverpodNavigation widget with your routing hierarchy and give the provided delegate and parser to your MaterialApp.router factory.

  final routes = RouteDefinition(
      template: UriTemplate.parse('/'),
      builder: (context, entry) => MaterialPage(
        child: HomeLayout(),
      ),
      next: [
        RouteDefinition(
          template: UriTemplate.parse('/articles/:id'),
          builder: (context, entry) => MaterialPage(
            child: ArticleLayout(
              id: entry.parameters['id']!,
            ),
          ),
        ),
      ],
    );
    return RiverpodNavigation( // Replaces your root ProviderScope
      routes: routes,
      builder: (context, delegate, parser) => MaterialApp.router(
        title: 'Flutter Demo',
        routerDelegate: delegate,
        routeInformationParser: parser,
      ),
    );
Navigate
From a provider

A navigationProvider is exposed and can be used to read the current navigation state.

To access the underlying notifier that allows various actions, use the navigationProvider.notifier provider.

final myProvider = Provider<MyState>((ref) {
        final navigation = ref.watch(navigationProvider.notifier);
        return MyState(
            navigateToArticles: () {
                navigation.navigate(Uri.parse('/articles'))
            },
            pop: () {
                navigation.pop();
            }
        );
    },
);
From a BuildContext

The notifier can be accessed with the navigation extension method from the BuildContext.

@override
Widget build(BuildContext context) {
    return TextButton(
        child: Text('Articles'),
        onPressed: () {
            context.navigation.navigate(Uri.parse('/articles'))
        }
    );
}
Pop behaviour

To customize the behaviour of pops when navigating back, a PopBehavior callback can be provided to the RiverpodNavigation instance. The result indicates whether the current pop action should be updated, cancelled or auto (default behavior which simply replace the route with the parent one).

 RiverpodNavigation(
    popBehaviour: (notifier, stack) {
        if (stack.lastRoute?.key == Key('share-article')) {
          return PopResult.update(Uri.parse('/'));
        }
        return PopResult.auto();
      },
    // ...
 )
URI rewriting

The uri can be modified before they are processed by the router with the uriRewriter property. This can be useful for redirecting or normalizing uris.

 RiverpodNavigation(
    uriRewriter: (notifier, uri) {
        if (uri == Uri.parse('/home')) {
            return Uri.parse('/');
        }
        const publicPrefix = 'https://example.com';
        final stringUri = uri.toString();
        if (stringUri.startsWith(publicPrefix)) {
            return Uri.parse(stringUri.substring(publicPrefix.length);
        }
        return uri;
    },
    // ...
);

カテゴリー

依存関係

依存関係一覧 4 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。