flutter_dva_hooks 1.0.9 copy "flutter_dva_hooks: ^1.0.9" to clipboard
flutter_dva_hooks: ^1.0.9 copied to clipboard

Declarative hooks for Flutter Dva state management. Provides useDvaConnect, useDvaProps, and useDvaStore hooks on flutter_hooks for reactive store access in Flutter widgets.

flutter_dva_hooks #

pub package

Flutter Dva Hooks — A hook library built on top of flutter_hooks for Flutter Dva state management. It allows you to use Dva state management in Flutter in a declarative, functional way.

English | 中文


📦 Installation #

Add flutter_dva_hooks to your pubspec.yaml:

dependencies:
  flutter_dva_hooks: ^1.0.8

Or install via command:

flutter pub add flutter_dva_hooks

✨ Features #

Hook Description
useDvaConnect Listens to Store state changes and automatically refreshes the widget, while providing access to both Props and Store
useDvaProps Retrieves Props only, without listening to Store changes
useDvaStore Retrieves the Store instance only, without listening to Store changes

1. useDvaConnect — Full connection with auto-refresh #

Automatically subscribes to Store state changes and triggers widget rebuild when specified state changes. Supports namespace filtering, custom state mapping, and custom update strategies.

final connect = useDvaConnect(
  namespace: 'counter',      // Listen to specific namespace
  listenKeys: ['count'],     // Only listen to specific keys
  mapState: (rootState) {    // Custom state mapping
    return {
      'counter': rootState['counter'],
    };
  },
  shouldUpdate: (lState, nState) {  // Custom update strategy
    return lState.updateAt != nState.updateAt;
  },
  didMounted: () {           // Callback after mount
    print('Component mounted');
  },
);

// Access props
connect.props?.dispatch(Type('increment'));
connect.props?.history;

// Access store
connect.store?.subscribe((lState, nState) {});
connect.store?.rootState;

// Access mapped state
connect.state?['counter'];

2. useDvaProps — Props only #

Use this when you only need Props (dispatch, history, etc.) without subscribing to state changes.

final props = useDvaProps(namespace: 'counter');

// Dispatch actions
props.dispatch(Type('increment'));

// Navigation
props.history;

3. useDvaStore — Store only #

Use this when you only need the Store instance without subscribing to changes.

final store = useDvaStore();

// Access root state
store.rootState;

// Subscribe to state changes
store.subscribe((lState, nState) {
  // Handle state change
});

📚 API Reference #

useDvaConnect Parameters #

Parameter Type Description
namespace String? Namespace to listen to
listenKeys List<String>? Only listen to specific state keys under the namespace
mapState MapState? Custom state mapping function from rootState
shouldUpdate ShouldUpdate? Custom update decision function
didMounted VoidCallback? Callback after first mount and state initialization

Return Types #

  • DvaConnect: Contains props, state, and store
  • Props: Contains dispatch, history, and namespace-related properties
  • Store: The Store instance from flutter_dva

🔗 Dependencies #


📄 License #

This project is licensed under the MIT License.


0
likes
160
points
238
downloads

Documentation

API reference

Publisher

verified publisher17ued.top

Weekly Downloads

Declarative hooks for Flutter Dva state management. Provides useDvaConnect, useDvaProps, and useDvaStore hooks on flutter_hooks for reactive store access in Flutter widgets.

Homepage
Repository

License

MIT (license)

Dependencies

flutter, flutter_dva, flutter_hooks

More

Packages that depend on flutter_dva_hooks