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

black_hole_flutter 封面
套件詳情v2.0.0

black_hole_flutter

一個吸收所有 Flutter 工具函數的套件,包含擴展函數和常見使用的組件

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.7萬
喜歡數
70
Pub 分數
160

安裝套件

flutter pub add black_hole_flutter

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Black_Hole_Flutter 是一個全面的 Flutter 工具包,將常用的擴展函數和可重用元件整合到一個易於匯入的解決方案中。專為簡化開發而設計,它提供了跨多個平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)的時間節省工具。該套件充當頻繁所需功能的中央樞紐,減少樣板程式碼並促進 Flutter 項目的一致性。非常適合尋求效率和快速原型設計的開發者。

適用情境

  • 快速使用者介面開發
  • 跨專案的程式碼重用
  • 簡化常見任務
  • 跨平台實用工具
  • Prototyping
  • 減少樣板程式碼

主要特色

  • 統一的實用程式擴展
  • 可重用的組件
  • 多平台支援
  • 最小設定
  • 一致的編碼風格
  • 可擴展的設計

適合對象

  • 從初學者到進階的Flutter開發者
  • 大規模應用開發
  • 重視程式碼一致性的團隊
  • 需要快速迭代的專案
  • 希望依賴項目最少的開發者

使用建議

  • 可能包含未使用的實用工具
  • 依賴項膨脹的潛在風險
  • 每個功能的自訂選項有限
  • 不適合高度專業化的需求
  • 需要仔細審查包含的函數
  • 在專案範圍與包含的工具相符時效果最佳

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

🛠 A package absorbing all Flutter utility functions, including extension functions and commonly used widgets.

📄 Bottom Sheet

Show modal bottom sheets using: context.showModalBottomSheet().

FancyBottomSheet demo

Also, this package adds a custom FancyBottomSheet with a drag indicator at the top. You can create one using context.showFancyModalBottomSheet().

🏗 BuildContext

In Flutter, you often see the pattern <Class>.of(context) (e.g., Theme.of(context)). This package adds extension getters on BuildContext for those classes so you can just say:

Extension Shortcut for
context.colorScheme ColorScheme.of(context)
context.defaultTextStyle DefaultTextStyle.of(context)
context.directionality Directionality.of(context)
context.form Form.of(context)
context.locale Localizations.localeOf(context)
context.materialLocalizations MaterialLocalizations.of(context)
context.mediaQuery MediaQuery.of(context)
context.overlay Overlay.of(context)
context.pageStorage PageStorage.of(context)
context.scaffold Scaffold.of(context)
context.scaffoldOrNull Scaffold.of(context, nullOk: true)
context.textTheme TextTheme.of(context)
context.theme Theme.of(context)

🎨 Colors

Handy extensions on Brightness:

Extension Explanation
brightness.isDark ≙ brightness == Brightness.dark
brightness.isLight ≙ brightness == Brightness.light
brightness.opposite opposite Brightness
brightness.color Color representing this brightness, i.e.:
· Colors.white for Brightness.light
· Colors.black for Brightness.dark
brightness.contrastColor opposite of brightness.color (above)

isDark, isLight, and contrastColor can also be used on ThemeData directly.

Handy extensions on Color:

Extension Explanation
color.estimatedBrightness estimated Brightness based on color's luminance
color.isOpaque if opacity is 1.0
color.alphaBlendOn(Color background) resulting Color when drawing color on top of background
color.withAdditionalOpacity(double opacity) applies opacity by multiplying it to the existing opacity
color.withAdditionalAlpha(int alpha) like above, but with an integer alpha
color.hsl ≙ HSLColor.fromColor(color)
color.hsv ≙ HSVColor.fromColor(color)

And if you can't decide on a color, just use random.nextColor(), random.nextColorHsl() or random.nextColorHsv()!

Convert between alpha and opacity with int.alphaToOpacity and double.opacityToAlpha.

🌈 Material Design colors

Material Design specifies different opacities of white and black colors to use for text of different emphases on colored backgrounds. You can now use the highEmphasisOnColor, mediumEmphasisOnColor and disabledOnColor extension getters on Color to make your text legible! The raw opacity values are also available as MaterialColors.highEmphasisTextAlpha, MaterialColors.mediumEmphasisTextAlpha, and MaterialColors.disabledTextAlpha.

🧭 Navigation

Access your navigation-related information via extension methods:

Extension Shortcut for
context.navigator Navigator.of(context)
context.rootNavigator Navigator.of(this, rootNavigator: true)
context.modalRoute ModalRoute.of(context)

Push a new route and pop all previous routes (e.g., when signing out the user):

navigator.pushAndRemoveAll(/* new route */);
// Or using a named route:
navigator.pushNamedAndRemoveAll(/* route name */);

Log navigation events to the console:

MaterialApp(
  navigatorObservers: [LoggingNavigatorObserver()],
  // ...
)
// Prints:
// Navigator: didPush /dashboard → /articles/12345
// Navigator: didPop /dashboard ← /articles/12345

Note: This uses the name of routes, so it only works with named routes.

📱 Widgets

🔳 Buttons

Did you ever want to show a progress indicator inside a button? Or were annoyed to conditionally set a Button's onPressed to disable it? Fear no more — black_hole_flutter has got you covered!

Button demo

This screenshot only shows an excerpt of all available button types and variants.

In FancyFab (a FloatingActionButton), FancyTextButton, FancyOutlinedButton, FancyElevatedButton, FancyFilledButton, and FancyIconButton, we introduce some new parameters:

🥙 FillOrWrap
FillOrWrap demo

A layout with two different behaviors:

  • By default, all children are positioned next to each other with equal widths. This is comparable to a Row with all children wrapped in Expanded.
  • If the children are too wide to fit in a single line, or one child would become smaller than its reported minimum width, the children get positioned below each other ("wrapped"). This is similar to a Column with MainAxisSize.min.
🎯 LeftCenterRight

A layout taking optional left, center, and right children. It will try to keep center in the center of itself, even if only one of left and right is set, or they have different widths.

🟢 Circle

A circle with optional diameter, background color, padding, and child.

🖼 RenderObject

When writing a custom layout, you might find this extension on ContainerRenderObjectMixin useful:

Extension Explanation
containerRenderObjectMixin.children Returns all children using firstChild and childAfter

↕ Size

Extension Explanation
size.diagonal length of the diagonal of a rectangle with this Size
size.squaredDiagonal ≙ size.diagonal * size.diagonal
size.coerceAtLeast(Size minimum) Ensures size is not smaller than minimum in any axis
size.coerceAtMost(Size maximum) Ensures size is not larger than minimum in any axis

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案