Search packages, repositories and app categories

GitHub repositoryMohiuddinM/flutter_state_management

flutter_state_management

MohiuddinM/flutter_state_management open-source repository details.

flutter_state_management project cover
Stars
6
Forks
0
Last push (UTC)
Jul 29, 2025
Project status
Active

Original README

English project snapshot. Visit GitHub for the latest content.

Flutter State Management

Just a couple of utility classes to make it easier to use Flutter framework's built-in ChangeNotifier and Listenable for state management.

Features

  • No learning curve if you already know Flutter
  • Simple package based on ChangeNotifier (No bloatware)

Usage

Create your model class

class Counter extends StateNotifier<int, String> {
  Counter() : super(const Active(data: 0));

  void increment() async {
    setWaiting();

    await Future.delayed(const Duration(seconds: 2));

    if (data > 20) {
     setFailed('greater than 20');
    } else {
      setActive(data + 1);
    }
  }
}

Or if you want the state to persist across restarts

class Counter extends PersistedStateNotifier<int, String> {
  Counter() : super(IsarKeyValue(), startState: 0);

  void increment() async {
    setWaiting();

    await Future.delayed(const Duration(seconds: 2));

    if (data > 20) {
      setFailed('greater than 20');
    } else {
      setActive(data + 1);
    }
  }
}

Handle State Changes in UI

To only rebuild specific parts:
  1. Use ValueListenableBuilder from the Flutter framework:
final counter = Counter();

ValueListenableBuilder(
  valueListenable: counter,
  child: Text()
  builder: (context, state, child) => // return updated UI here (can also use counter.builderArg here)
  child: const Text('Hello'),
  ),
);

You can also use builderArg helper:

builder: counter.builderArg(
  onActive: ,
  onWaiting: ,
  onNone: ,
  onFailure: ,
),
  1. Or use StateNotifierBuilder that comes with this package and is more user friendly:
final counter = Counter();

counter.builder(
  onActive: (context, data) => Text(data.toString()),
),


\

To rebuild whole widget

Convert your existing StatelessWidget to RStatelessWidget, and StatefulWidget to RStatefulWidget and and just watch the model inside the build method:

class CounterText extends RStatelessWidget {
  @override
  Widget build(BuildContext context) {
    counter.watch(context); // call watch inside the build method (do not use any if) 
    return Text(data.toString());
  }
}
Muhammad Mohiuddin GitHub avatar
GitHub author

Muhammad Mohiuddin ↗

engineer by profession, engineer by hobby

Regensburg
LanguagesC++DartCMakeSwiftHTMLCKotlinObjective-C

Packages published by this repository

Dependencies used

Dependency list 4 items

  • flutter{"sdk":"flutter"}
  • flutter_testDevelopment{"sdk":"flutter"}
  • flutter_lintsDevelopment^5.0.0
  • mockitoDevelopment^5.0.0

How do I choose a repository?

Start with your use case, compare repository activity, and check the original project before adopting it.

  1. Search by repository name, owner or description, then narrow the results by topic.
  2. Compare stars, forks and recent pushes. Stars show community interest, not a guarantee of quality.
  3. Read the README, license and issues on GitHub before using a project.

Sources and maintenance

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗