Search packages, repositories and app categories

Package detailsv0.2.4

stacked_hooks

Classes that help you make use of hooks when using the stacked package

AndroidiOSWebmacOSWindowsLinux
30-day downloads
6.9K
Likes
70
Pub points
140

Install package

flutter pub add stacked_hooks

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

Stacked Hooks is a Flutter package that extends the Stacked architecture by providing utility classes to seamlessly integrate React-style hooks into your state management workflow. It enables developers to use hooks like useState, useEffect, and useStream within Stacked's view models, promoting cleaner, more modular code. Designed for developers already using the Stacked package, it simplifies state handling in UI components without requiring a full rewrite of existing logic. The package supports all major platforms, ensuring consistent behavior across Android, iOS, Web, macOS, Windows, and Linux.

Use cases

  • Building reactive UIs with minimal boilerplate
  • Managing local state in stacked view models
  • Simplifying side effects with useEffect-like logic
  • Integrating streams and async operations
  • Creating reusable stateful widgets
  • Enhancing maintainability of complex views

Key features

  • Built-in hook utilities for Stacked
  • Support for useState, useEffect, useStream
  • Seamless integration with Stacked architecture
  • Cross-platform compatibility
  • Minimal setup required
  • Type-safe and intuitive API

Suitable for

  • Developers using the Stacked package
  • Teams seeking cleaner state management
  • Flutter apps with complex UI logic
  • Projects aiming to reduce boilerplate
  • Those familiar with React hooks
  • Apps targeting multiple platforms

Considerations

  • Requires the Stacked package
  • Limited to Stacked-based projects
  • May require learning curve for new hook users
  • Not suitable for non-Stacked architectures
  • Best used in medium to large-scale apps
  • Depends on Dart's async and stream handling

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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();
  }
}

Categories

Dependencies

Dependency list 2 items

Source repository

Projects using this package