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

패키지 상세v1.0.9

nested_navigators

자신의 라우트 스택을 가진 여러 중첩된 네비게이터를 구현하기 위한 Flutter 위젯입니다.

30일 다운로드
22
좋아요
17
Pub 점수
40

패키지 설치

flutter pub add nested_navigators

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

NestedNavigators는 여러 중첩된 네비게이터를 구현할 수 있도록 해주는 Flutter 패키지로, 각각이 자체적으로 독립적인 라우트 스택을 관리합니다. 탭 인터페이스나 화면 내 모달과 같은 계층적 UI를 가진 앱에서 복잡한 네비게이션 시나리오를 단순화합니다. 각 네비게이터마다 고립된 네비게이션 동작을 허용함으로써 의도하지 않은 라우트 간섭을 방지하고 유지보수성을 향상시킵니다. 기존의 Flutter 프로젝트에 원활하게 통합되며, 중첩 구조 내에서 동적 라우팅을 지원합니다.

사용 사례

  • 복잡한 탭 인터페이스
  • 화면 내 모달 대화 상자
  • 다중 레벨 탐색 흐름
  • 컴포넌트 내 독립적인 라우트 스택
  • 중첩된 화면 전환

주요 기능

  • 각 내비게이터의 경로 스택 격리
  • 딥 링크 지원
  • 네비게이션 로직의 명확한 분리
  • MaterialApp과의 간편한 통합
  • 동적 루트 관리

적합한 대상

  • 다중 탐색 레이어를 가진 앱
  • 복잡한 라우팅을 관리하는 개발자
  • 독립적인 탐색 컨텍스트가 필요한 UI
  • 모듈러 스크린 아키텍처를 사용하는 프로젝트
  • 유지보수 가능한 탐색 코드를 우선시하는 팀

고려 사항

  • 신중한 상태 관리가 필요합니다
  • 과도하게 사용할 경우 앱의 복잡성이 증가할 수 있습니다
  • 간단한 탐색에는 필요하지 않음
  • 핵심 플러터에 비해 문서가 제한적
  • 과도한 중첩으로 인한 성능 오버헤드 가능성

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

NestedNavigators

Flutter widget for implementing multiple nested navigators with their own route stacks.

Usage

To use, you must at least specify two arguments items and generateRoute:

class RootPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _RootPageState();
}

class _RootPageState extends State<RootPage> {
  @override
  Widget build(BuildContext context) {
    return NestedNavigators(
      items: {
        NestedNavItemKey.blue: NestedNavigatorItem(
          initialRoute: Routes.blue,
          icon: Icons.access_time,
          text: "Blue",
        ),
        NestedNavItemKey.red: NestedNavigatorItem(
          initialRoute: Routes.red,
          icon: Icons.send,
          text: "Red",
        ),
        NestedNavItemKey.green: NestedNavigatorItem(
          initialRoute: Routes.green,
          icon: Icons.perm_identity,
          text: "Green",
        ),
      },
      generateRoute: Routes.generateRoute,
    );
  }
}

See Routes.generateRoute()

By default NestedNavigators displays BottomNavigationBar, but you can hide it if you want:

clearStackAfterTapOnCurrentTab: false

You can customize BottomNavigatosBar items in two ways:

  • configure BottomNavigationBarItem:
buildBottomNavigationItem: (key, item, selected) => BottomNavigationBarItem(
           icon: Icon(
             item.icon,
             color: Colors.blue,
           ),
           title: Text(
             item.text,
             style: TextStyle(fontSize: 20),
           ),
         )
  • Define your own widget:
buildCustomBottomNavigationItem: (key, item, selected) => Container(
            height: 60,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Icon(
                  item.icon,
                  size: 24,
                  color: selected ? Colors.blue : null,
                ),
                Text(
                  item.text,
                  style: TextStyle(fontSize: 20, color: selected ? Colors.blue : null),
                ),
              ],
            ),
          )

Initial selected navigator:

  • If number of navigators is even number, than it will be the first elemnt of items;
  • If number of navigators is odd number, than it will be the middle element of items;
  • You can specify your navigator key:
 initialNavigatorKey: NestedNavItemKey.green

You can specify the color of ripple effect in your app theme or in bottomNavigationBarTheme:

bottomNavigationBarTheme: Theme.of(context).copyWith(
       splashColor: Colors.blue[100],
   )

By default, if a user clicks on an already selected tab item, the route stack will be cleared and the initial route will be displayed. You can disable this option:

clearStackAfterTapOnCurrentTab: false

When you navigate to another route within nested navigator, you can hide BottomNavigatorsBar for specific route, just add hideNavTabBar: true to route arguments:

Navigator.of(context).pushNamed(
                    Routes.red,
                    arguments: {
                      hideNavTabBar: true,
                    },
                  );

You can select another navigator from your routes:

NestedNavigatorsBlocProvider.of(context).select(NestedNavItemKey.green)

You can also switch displayed navigator and at the same time make navigation in the new navigator:

NestedNavigatorsBlocProvider.of(context).selectAndNavigate(
                      NestedNavItemKey.green,
                      (navigator) => navigator.pushNamed(
                            Routes.green,
                            arguments: {
                              ArgumentKeys.value: 100,
                            },
                          ));

Add NestedNavigatorsBlocProvider to app widget if you want to use the root navigator and need access to nested navigators from there:

class App extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _AppState();
}

class _AppState extends State<App> {
  final NestedNavigatorsBloc _bloc = NestedNavigatorsBloc<NestedNavItemKey>();

  @override
  Widget build(BuildContext context) {
    return NestedNavigatorsBlocProvider(
      bloc: _bloc,
      child: MaterialApp(
        title: 'Flutter Demo',
        home: RootPage(),
        onGenerateRoute: (routeSettings) => Routes.generateRoute(routeSettings),
      ),
    );
  }
}

You can use Drawer instead of BottomNavigationBar, use drawer or endDrawer for this:

drawer: (items, selectedItemKey, selectNavigator) => Drawer(
            child: ListView(
              children: items.entries
                  .map((entry) => ListTile(
                        title: Text(
                          entry.value.text,
                          style: TextStyle(
                            color: entry.key == selectedItemKey
                                ? Colors.blue
                                : null,
                          ),
                        ),
                        trailing: Icon(
                          entry.value.icon,
                          color:
                              entry.key == selectedItemKey ? Colors.blue : null,
                        ),
                        onTap: () => selectNavigator(entry.key),
                      ))
                  .toList(),
            ),
          ),

Also you can open drawers from your pages:

NestedNavigatorsBlocProvider.of(context).actionWithScaffold(
                  (scaffoldState) => scaffoldState.openDrawer(),
                );

카테고리

소스 저장소

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

아직 데이터가 없습니다.