搜尋套件、儲存庫與 APP 分類

套件詳情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

所屬分類

原始碼儲存庫

使用此套件的專案