Last updated:
0 purchases
raw state
RawState is a super simple state container for your Dart and Flutter apps
Features #
Flutter widgets are encapsulated. It is, on purpose, difficult to share data between widgets. To help manage that, many state management packages like flutter_riverpod, provider, flutter_bloc, getx, and mobx have been written. And they are really good, but they're also really complicated. This is a barrier to entry for many Flutter developers.
RawState makes it incredibly easy to set state in one widget and read it in another.
Getting started #
After pub add raw_state or flutter pub add raw_state, just import it at the top of every file that needs to read or write state:
import 'package:raw_state/raw_state.dart';
copied to clipboard
This exposes a new global variable called rawState.
Usage #
To set a value in any file #
rawState.set('someInt', 77);
rawState.set('someMap', {"foo":"bar","baz":"qux"});
rawState.set('someString', "Can it really be this simple?");
copied to clipboard
To read a value in any file #
This could be the same file/widget or a completely different one.
int i = rawState.get<int>('someInt');
Map m = rawState.get<Map>('someMap');
String s = rawState.get<String>('someString');
copied to clipboard
Note: .get() throws if the the key is non-existent or contains a null. For nullables, use .maybeGet()
To read a nullable value or one that hasn't been set #
int? i = rawState.maybeGet<int>('someInt');
Map? m = rawState.maybeGet<Map>('someMap');
String? s = rawState.maybeGet<String>('someString');
copied to clipboard
That's really all you have to do.
Additional information #
The other state management packages are much more robust with protections built in. This package is focused on simplicity and rapid development. If your app is a MVP (minimum viable product) or a prototype, rawState will get you up and running incredibly quickly. Even if it is a simple app and you're rigorous in your coding, it is perfectly fine. But if your app is huge and built by a large team, you may want to bite the bullet and learn one of those other state managers.
Contributing #
Propose an enhancement
Report a bug
Fix a bug
Send in a Pull Request
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.