A lightweight and reactive state management system for Flutter. Easily manage global or local state, handle async states, computed values, and react to changes with builders, consumers, listeners, and observers — all with simple Dart classes.
- ✅ Simple and lightweight
- 🔄 Reactive updates with ChangeNotifier
- 💥 Built-in builder, listener, observer, and consumer widgets
- 📦 Global or local state
- 🌍 App config (theme, locale) management
- 🧮 Computed values (CoderComputed)
- 🔁 Async state (CoderAsync)
Add this to your pubspec.yaml:
dependencies:
coderx: ^latest_version
import 'package:coderx/coderx.dart';
final counter = CoderState<int>(0);
CoderConsumer<int>(
state: counter,
builder: (context, count) => Text('Count: $count'),
);
counter.value++;
Use CoderMultiConsumer to listen to multiple states.
CoderMultiConsumer(
states: [themeMode, locale],
builder: (context) {
return MaterialApp(
themeMode: themeMode.value,
locale: locale.value,
home: const HomeScreen(),
);
},
);
CoderListener<String?>(
state: errorState,
listener: (context, value) {
if (value != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Error: $value")),
);
}
},
child: const HomeScreen(),
);
final username = CoderState<String>("Guest");
final welcomeMessage = CoderComputed<String>(
compute: () => "👋 Welcome, ${username.value}!",
dependencies: [username],
);
final userAsync = CoderAsync<List<String>>();
Future<void> loadUsers() async {
await userAsync.run(() async {
await Future.delayed(Duration(seconds: 2));
return ['Alice', 'Bob', 'Charlie'];
});
}
// Display UI based on async state
CoderConsumer<CoderAsyncState<List<String>>>(
state: userAsync.state,
builder: (context, async) {
if (async.isLoading) return CircularProgressIndicator();
if (async.hasError) return Text("Error: ${async.error}");
if (async.hasData) return Column(
children: async.data!.map((e) => Text(e)).toList(),
);
return SizedBox();
},
);
#### ⚙️ AppConfig (Global States)
```dart
class AppConfig {
final themeMode = CoderState<ThemeMode>(ThemeMode.light);
final locale = CoderState<Locale>(const Locale('en'));
final counter = CoderState<int>(0);
final username = CoderState<String>('Guest');
final loading = CoderState<bool>(false);
final error = CoderState<String?>(null);
final userList = CoderState<List<String>>([]);
late final welcomeMessage = CoderComputed<String>(
compute: () => "👋 Welcome, ${username.value}!",
dependencies: [username],
);
static final AppConfig _instance = AppConfig._internal();
factory AppConfig() => _instance;
AppConfig._internal();
}
final config = AppConfig();
👨💻 Senior Flutter Developer
💡 One principle I always code by:
"Don’t just develop — Develop Innovative"
Feel free to contribute or raise issues. For support, email thoriyaprahalad@gmail.com