搜索插件、代码仓与 APP 分类

插件详情v0.2.4

stacked_hooks

使用 stacked 包时帮助您使用钩子的类

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
7100
喜欢数
70
Pub 分数
140

安装插件

flutter pub add stacked_hooks

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Stacked Hooks 是一个 Flutter 包,通过提供实用类来扩展 Stacked 架构,使 React 风格的 hooks 能够无缝集成到您的状态管理流程中。它允许开发者在 Stacked 的视图模型中使用 useState、useEffect 和 useStream 等 hooks,从而实现更简洁、更模块化的代码。专为已使用 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 项

源码仓库

使用此插件的项目