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

パッケージ詳細v3.0.0

build_context

BuildContext 内で最も使われるプロパティや関数に簡単にアクセスできるようにするパッケージです。

30日間ダウンロード
169
いいね数
145
Pub ポイント
60

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

flutter pub add build_context

パッケージ概要

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

build_context パッケージは、BuildContext クラスに頻繁に使用されるプロパティや関数を拡張することで、Flutter 開発を強化し、ボイラープレートコードを削減します。テーマ、メディアクエリ、ナビゲーション、その他の重要なユーティリティへの直接アクセスが可能になり、明示的なコンテキスト検索の必要がありません。これによりウィジェット作成が簡素化され、コードの読みやすさが向上します。このパッケージは軽量であり、さまざまな Flutter プロジェクトでの使いやすさを目的としています。

用途

  • ウィジェットでのテーマアクセスの簡素化
  • コンテキスト付きの素早いナビゲーション
  • メディアクエリデータにアクセスする
  • 繰り返しのコンテキスト検索を減らす
  • ウィジェットの読みやすさの向上

主な機能

  • 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

カテゴリー

ソースリポジトリ

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