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

패키지 상세v3.0.0

no_context_navigation

context (BuildContext)를 사용하지 않고 화면(라우트) 간 이동을 위한 Flutter 패키지입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
845
좋아요
20
Pub 점수
150

패키지 설치

flutter pub add no_context_navigation

패키지 개요

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

no_context_navigation 패키지는 BuildContext 없이도 Flutter 개발자가 화면 간에 이동할 수 있도록 합니다. 비동기 작업 중이나 전역 메서드를 사용할 때 컨텍스트가 사용 불가능한 상황에서 특히 유용합니다. 간단하고 정적인 네비게이션 API를 제공함으로써 앱 전체의 라우트 관리를 단순화합니다. 이 패키지는 Android, iOS, Web, macOS, Windows, Linux 등 주요 플랫폼을 모두 지원하여 크로스플랫폼 애플리케이션에 적합합니다.

사용 사례

  • 백그라운드 작업에서 탐색
  • 전역 오류 핸들러
  • 비동기 콜백
  • 상태 관리 통합
  • 앱 초기화 흐름

주요 기능

  • BuildContext가 필요하지 않습니다
  • 정적 탐색 방법
  • 크로스 플랫폼 지원
  • 간단한 API
  • 모든 상태 관리와 호환됩니다

적합한 대상

  • 개발자들이 컨텍스트 종속성을 피하는 방법
  • 복잡한 상태 로직을 가진 앱
  • 글로벌 탐색 유틸리티
  • 대규모 플러터 프로젝트
  • 위젯이 아닌 컨텍스트 탐색

고려 사항

  • 올바른 초기화가 필요합니다
  • 관리되지 않으면 라우트 가드를 우회할 수 있음
  • 위젯 전용 탐색에 적합하지 않습니다
  • 기본적인 경로 전환에 제한됨
  • 라우팅 구성과 함께 사용하는 것이 가장 좋습니다

원본 README

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

No Context Navigation

No Context Navigation Package - pub.dev

Instead of using Navigator.of(context).pushNamed or some other method like pop() or pushReplacementNamed() USING context. With this package you don't need to anymore.

This service use a GlobalKey of type NavigatorState which can be used across the entire applicaton.

Now, you only need to this:

navService.pushNamed('/detail_screen', args: 'From Home Screen');

But first, add the navigationKey to your MaterialApp's navigationKey property:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      //Over here
      navigatorKey: NavigationService.navigationKey,
      onGenerateRoute: (RouteSettings settings) {
        switch (settings.name) {
          case '/':
            return MaterialPageRoute(builder: (_) => HomeScreen());
          case '/detail_screen':
            return MaterialPageRoute(builder: (_) => DetailScreen(message: settings.arguments));
          default:
            return null;
        }
      },
    );
  }
}

Use navService object to be able to acess those methods:

import 'package:flutter/material.dart';

final NavigationService navService = NavigationService();

class NavigationService<T, U> {
  static GlobalKey<NavigatorState> navigationKey = GlobalKey<NavigatorState>();

  Future<T> pushNamed(String routeName, {Object args}) async =>
      navigationKey.currentState.pushNamed<T>(
        routeName,
        arguments: args,
      );

  Future<T> push(Route<T> route) async =>
      navigationKey.currentState.push<T>(route);

  Future<T> pushReplacementNamed(String routeName, {Object args}) async =>
      navigationKey.currentState.pushReplacementNamed<T, U>(
        routeName,
        arguments: args,
      );

  Future<T> pushNamedAndRemoveUntil(
    String routeName, {
    Object args,
    bool keepPreviousPages = false,
  }) async =>
      navigationKey.currentState.pushNamedAndRemoveUntil<T>(
        routeName,
        (Route<dynamic> route) => keepPreviousPages,
        arguments: args,
      );

  Future<T> pushAndRemoveUntil(
    Route<T> route, {
    bool keepPreviousPages = false,
  }) async =>
      navigationKey.currentState.pushAndRemoveUntil<T>(
        route,
        (Route<dynamic> route) => keepPreviousPages,
      );

  Future<bool> maybePop([Object args]) async =>
      navigationKey.currentState.maybePop<bool>(args);

  bool canPop() => navigationKey.currentState.canPop();

  void goBack({T result}) => navigationKey.currentState.pop<T>(result);
}

Hope you enjoy!

카테고리

소스 저장소

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

아직 데이터가 없습니다.