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

패키지 상세v3.0.0

build_context

BuildContext 내에서 자주 사용하는 속성/함수에 쉽게 접근할 수 있도록 도와주는 패키지입니다.

30일 다운로드
169
좋아요
145
Pub 점수
60

패키지 설치

flutter pub add build_context

패키지 개요

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

build_context 패키지는 빌드 컨텍스트 클래스에 자주 사용되는 속성과 함수를 확장하여 플러터 개발을 향상시킵니다. 이로 인해 반복 코드가 줄어들고, 주제, 미디어 쿼리, 네비게이션 및 기타 필수 유틸리티에 직접 액세스할 수 있으며, 명시적인 컨텍스트 검색이 필요하지 않습니다. 이를 통해 위젯 생성이 간소화되고 코드의 가독성이 향상됩니다. 이 패키지는 가볍고 다양한 플러터 프로젝트에서 쉽게 사용할 수 있도록 설계되었습니다.

사용 사례

  • 위젯에서 테마 접근을 단순화하기
  • 컨텍스트를 포함한 빠른 탐색
  • 미디어 쿼리 데이터에 액세스하기
  • 반복적인 컨텍스트 검색 줄이기
  • 위젯 가독성 향상

주요 기능

  • 유용한 메서드를 가진 BuildContext 확장
  • 반복 코드를 줄입니다
  • 테마 및 미디어 쿼리 단축 기능 제공
  • 내비게이션 보조 기능 포함
  • 경량이며 통합이 쉬움

적합한 대상

  • 더 깔끔한 코드를 원하는 개발자
  • 자주 컨텍스트를 사용하는 프로젝트
  • 코드 유지보수를 우선시하는 팀
  • Flutter 초보자들이 컨텍스트 패턴을 배우고 있습니다
  • 복잡한 UI 레이아웃을 가진 앱

고려 사항

  • 패키지 크기가 약간 증가할 수 있습니다
  • 기본 유틸리티 확장에만 제한됨
  • 고급 사용자 정의 컨텍스트 로직에 적합하지 않음
  • BuildContext 기본 사항을 이해하고 있어야 합니다
  • 적절한 상태 관리와 함께 사용하는 것이 가장 좋습니다

원본 README

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

Languages: English | Brazilian Portuguse

Logo

BuildContext

Access most used properties in your BuildContext instance. This package relies on Dart's extension to provide easy access for the most used properties and functions that depends on the BuildContext instance.

Available Extensions

I update this package frequently to add more extensions, bellow you can see the currently available extensions in the latest version.

From the MediaQuery. Access properties right in the context instance. Available extensions:
  • context.mediaQuerySize

  • context.orientation

  • context.mediaQueryPadding

  • context.alwaysUse24HourFormat

  • context.devicePixelRatio

  • context.platformBrightness

  • context.textScaleFactor

  • context.isLandscape

  • context.isPortrait

  • context.mediaQueryViewPadding

  • context.mediaQueryViewInsets

  • context.mediaQueryShortestSide

  • context.isPhone

  • context.isTablet

  • context.isSmallTablet

  • context.isLargeTablet

From the Navigator class. Navigate with ease. Available extensions:
  • context.push()
  • context.pop()
  • context.canPop()
  • context.pushNamed()
  • context.popUntil()
From the Theme class. Access your themes right in the context instance. Available extensions:
  • context.theme
  • context.textTheme
  • context.primaryTextTheme
  • context.accentTextTheme
  • context.bottomAppBarTheme
  • context.bottomSheetTheme
  • context.appBarTheme
  • context.backgroundColor
  • context.primaryColor
  • context.buttonColor
  • context.scaffoldBackgroundColor
  • context.platform
  • context.isAndroid
  • context.isIOS
  • context.isWindows
  • context.isMacOS
  • context.isLinux
  • context.isFuchsia
  • context.headline1
  • context.headline2
  • context.headline3
  • context.headline4
  • context.headline5
  • context.headline6
  • context.subtitle1
  • context.bodyText1
  • context.bodyText2
  • context.caption
  • context.button
  • context.subtitle2
  • context.overline
From Scaffold class. Handle your scaffold in their context.

Note: those must be called in the context of a Scaffold widget otherwise you might have errors.

  • context.openDrawer()
  • context.openEndDrawer()
  • context.showSnackBar()
  • context.hideCurrentSnackBar()
  • context.removeCurrentSnackBar()
  • context.showBottomSheet()
From Form.of(context) class.

Note: those must be called in the context of a Scaffold widget otherwise you might have errors.

  • context.form.validate()
  • context.form.reset()
  • context.form.save()
From FocusScope.of(context) class.
  • context.focusScope.hasFocus

  • context.focusScope.isFirstFocus

  • context.focusScope.canRequestFocus

  • context.focusScope.hasPrimaryFocus

  • context.focusScope.unfocus()

  • context.focusScope.nextFocus()

  • context.focusScope.requestFocus()

  • context.focusScope.previousFocus()

  • context.focusScope.setFirstFocus()

  • context.focusScope.consumeKeyboardToken()

  • context.closeKeyboard()

From ModalRoute.of(context) class.
  • context.modalRoute
  • context.routeSettings

Install

Add it in your pubspec.yaml:

dependencies:
  build_context: ^3.0.0

Import it where you want to use it e.g, in your widget's file.

import "package:build_context/build_context.dart";

Here is a usage example:

import 'package:flutter/material.dart';
import "package:build_context/build_context.dart";

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: context.scaffoldBackgroundColor, // There is no Theme.of(context)
      body: Center(
        child: GestureDetector(
          onTap: () => context.pushNamed('/detailsPage'), // we use only context not Navigator.of(context)
          child: Text(
            'Press Me',
            style: context.primaryTextTheme.title, // we use only context not Theme.of(context)
          ),
        ),
      ),
    );
  }
}

Support

You liked this package? then give it a star. If you want to help then:

  • Start this repository
  • Send a Pull Request with new features
  • Share this package
  • Create issues if you find a Bug or want to suggest something

카테고리

소스 저장소

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