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

套件詳情v0.2.4

stacked_hooks

使用 stacked 包時幫助您使用鈎子的類別

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
6890
喜歡數
70
Pub 分數
140

安裝套件

flutter pub add stacked_hooks

套件介紹

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

Stacked Hooks 是一個 Flutter 套件,透過提供實用類別來擴展 Stacked 架構,讓 React 風格的 hooks 能夠無縫整合至您的狀態管理流程中。它允許開發者在 Stacked 的檢視模型中使用 useState、useEffect 和 useStream 等 hook,促進更乾淨、更具模組化的程式碼。專為已經使用 Stacked 套件的開發者設計,可簡化 UI 元件中的狀態處理,無需重寫現有邏輯。該套件支援所有主要平台,確保在 Android、iOS、Web、macOS、Windows 和 Linux 上行為一致。

適用情境

  • 使用最少的樣板代碼構建響應式 UI
  • 在堆疊的檢視模型中管理本機狀態
  • 使用 useEffect 類似邏輯簡化副作用
  • 整合流和異步操作
  • 建立可重複使用的狀態化小部件
  • 增強複雜視圖的可維護性

主要特色

  • Stacked 的內建鈎子工具
  • 對 useState、useEffect、useStream 的支援
  • 與 Stacked 架構的無縫整合
  • 跨平台相容性
  • 所需的設定最少
  • 類型安全且直覺的 API

適合對象

  • 使用 Stacked 包的開發者
  • 尋求更乾淨狀態管理的團隊
  • 具有複雜 UI 邏輯的 Flutter 應用
  • 旨在減少樣板程式碼的專案
  • 熟悉 React Hooks 的人
  • 針對多個平台的應用程式

使用建議

  • 需要 Stacked 包
  • 僅限基於堆疊的項目
  • 新鈎子使用者可能需要一定的學習曲線
  • 不適用於非堆疊架構
  • 最適合在中大型應用程式中使用
  • 依賴於 Dart 的非同步和串流處理

原始 README

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

Stacked Hooks

This package contains widgets that allow you to use the Flutter Hooks package with the StackedView in the Stacked architecture.

StackedHookView

The StackedView is an implementation of a widget class that returns a value provided by Provider as a parameter in the build function of the widget. This allows for easier consumption and use of ViewModel without boilerplate. The StackedHookView allows you to use this widget and make use of Flutter Hooks inside the build function. This is very useful when you want to use TextEditing controllers and you're implementing this architecture.

// View that creates and provides the viewmodel
class StackedHookViewExample extends StackedView<HomeViewModel> {
  const StackedHookViewExample({Key key}) : super(key: key);

  @override
  Widget builder(BuildContext context, HomeViewModel model, Widget? child) {
    return Scaffold(
      body: Center(child: _HookForm()),
    );
  }

  @override
  HomeViewModel modelBuilder(BuildContext context) {
    return HomeViewModel();
  }
}

// Form that makes use of the ViewModel provided above but also makes use of hooks
class _HookForm extends StackedHookView<HomeViewModel> {
  @override
  Widget buildStackedView(BuildContext context, HomeViewModel model) {
    final title = useTextEditingController();
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        Text(model.title),
        TextField(controller: title, onChanged: model.updateTitle),
      ],
    );
  }
}

// ViewModel
class HomeViewModel extends BaseViewModel {
  String title = 'default';

  void updateTitle(String value) {
    title = value;
    notifyListeners();
  }
}

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案