패키지, 저장소 및 앱 카테고리 검색

패키지 상세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 사용 개발자
  • 크로스 플랫폼 플러터 앱
  • 복잡한 탐색 시나리오
  • 상태 인식 라우팅이 필요한 앱
  • 유지보수 가능한 코드를 우선시하는 팀
  • 동적 경로 요구 사항이 있는 프로젝트

고려 사항

  • 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.