flutter_simple_usestate 0.0.1
flutter_simple_usestate: ^0.0.1 copied to clipboard
A simple and lightweight state management library.
πͺΆ Flutter Simple UseState #
A simple and minimal state management solution built on top of Flutterβs ValueNotifier.
This library provides a clean, hook-like API to manage state with almost zero boilerplate.
β¨ Features #
- β‘ Extremely lightweight
- π§ Built on native Flutter primitives (
ValueNotifier) - π Reactive UI updates
- π¦ No external dependencies
- π― Easy to learn and use
π Getting Started #
Import the library #
import 'package:flutter_simple_usestate/flutter_simple_usestate.dart';
π§© Usage #
1. Create state #
final counter = useState<int>(0);
2. Update state #
counter.value++;
3. Bind state to UI #
useStateBuilder<int>(
counter,
(value) {
return Text('$value');
},
);
π Full Example #
import 'package:flutter/material.dart';
class CounterPage extends StatelessWidget {
final counter = useState<int>(0);
CounterPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Counter')),
body: Center(
child: useStateBuilder<int>(
counter,
(value) => Text(
'$value',
style: const TextStyle(fontSize: 24),
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => counter.value++,
child: const Icon(Icons.add),
),
);
}
}
π API #
useState<T>(T initialValue) #
Creates a ValueNotifier<T>.
final state = useState<String>('hello');
useStateBuilder<T>(ValueNotifier<T> value, Widget Function(T value) builder) #
A wrapper around ValueListenableBuilder to rebuild UI when state changes.
useStateBuilder(counter, (value) => Text('$value'));
π€ Why use this? #
If you:
- donβt want heavy frameworks
- prefer simple and readable code
- just need basic reactive state
π This is perfect for small to medium apps.
β οΈ Limitations #
- Not suitable for very complex state logic
- No dependency injection
- No advanced features like scoped providers
π License #
MIT License
π‘ Contributing #
Feel free to open issues or submit pull requests!