flutter_atoms 0.0.2 copy "flutter_atoms: ^0.0.2" to clipboard
flutter_atoms: ^0.0.2 copied to clipboard

A simple state management solution inspired by Unity Atoms and built on Riverpod and Flutter Hooks.

⚛️ Flutter Atoms #

(WORK IN PROGRESS)

A simple state management solution inspired by Unity Atoms and built on riverpod and flutter_hooks

This is bascially a thin wrapper on top of riverpod providers that exposes some preset factory functions to generate simple providers. Is it worth it?! I dunno. Feel free to let me know if you think it's worth continuing to develop.

FYI: You can do everything this package can do directly with riverpod providers.

Features #

  • Void Events
  • Value Events
  • Pair Events (Value events with history)
  • Variables (StateNotifiers with optional events)
  • Constants (immutable variables)
  • Void Conditions (pointless?)
  • Value Conditions (reusable conditions)

Example Usage #

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:flutter_atoms/flutter_atoms.dart';

final changedEvent = createAtomEvent<String>();
final changedHistoryEvent = createAtomPairEvent<String, String>();
final textVariable = createAtomVariable(
  'hello world',
  changedEvent: changedEvent,
  changedWithHistoryEvent: changedHistoryEvent,
);

class AtomsExample extends HookWidget {
  @override
  Widget build(BuildContext context) {
    useAtomEvent(changedEvent, (String value) {
      print('Text Updated: $value');
    });

    return Center(
      child: ElevatedButton(
        onPressed: () => context.read(changedEvent).raise('foo bar'),
        child: const Text('Update Text'),
      ),
    );
  }
}

class SomeOtherClass extends HookWidget {
  @override
  Widget build(BuildContext context) {
    final myText = useAtomVariable(textVariable);

    useAtomPairEvent(changedHistoryEvent, (String previous, String current) {
      print('Text Updated from "$previous" to "$current"');
    });

    return Center(child: Text(myText));
  }
}

Getting Started #

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

2
likes
30
pub points
0%
popularity

Publisher

unverified uploader

A simple state management solution inspired by Unity Atoms and built on Riverpod and Flutter Hooks.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter, flutter_hooks, hooks_riverpod

More

Packages that depend on flutter_atoms