coderx 0.0.2
coderx: ^0.0.2 copied to clipboard
A simple, fast Flutter state management tool for theme, locale, and UI with builder, listener, and reactive state support.
coderx #
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.
๐ Features #
โ 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)
๐ฆ Installation #
Add this to your pubspec.yaml:
dependencies:
coderx: ^latest_version
๐ ๏ธ Basic Usage #
๐น Import
import 'package:coderx/coderx.dart';
๐น Create a State
final counter = CoderState<int>(0);
๐น Use CoderConsumer to rebuild on state change
CoderConsumer<int>(
state: counter,
builder: (context, count) => Text('Count: $count'),
);
๐น Update State
counter.value++;
๐งฑ Multi-State Consumption #
Use CoderMultiConsumer to listen to multiple states.
CoderMultiConsumer(
states: [themeMode, locale],
builder: (context) {
return MaterialApp(
themeMode: themeMode.value,
locale: locale.value,
home: const HomeScreen(),
);
},
);
๐ง Listen for State Changes (Side Effects)
CoderListener<String?>(
state: errorState,
listener: (context, value) {
if (value != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Error: $value")),
);
}
},
child: const HomeScreen(),
);
๐งฎ Computed State
final username = CoderState<String>("Guest");
final welcomeMessage = CoderComputed<String>(
compute: () => "๐ Welcome, ${username.value}!",
dependencies: [username],
);
๐ Async State
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();
๐ About Me #
๐จโ๐ป Senior Flutter Developer
๐ก One principle I always code by:
"Donโt just develop โ Develop Innovative"
๐ Author Profile #
Support #
Feel free to contribute or raise issues. For support, email thoriyaprahalad@gmail.com