Skip to content

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

License

Notifications You must be signed in to change notification settings

danielmahon/flutter_atoms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚛️ 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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages