Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/unacorbatanegra/occam
Minimalist State Manager
https://github.com/unacorbatanegra/occam
dart flutter state-management
Last synced: 16 days ago
JSON representation
Minimalist State Manager
- Host: GitHub
- URL: https://github.com/unacorbatanegra/occam
- Owner: unacorbatanegra
- License: mit
- Created: 2021-12-21T19:57:50.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-11T15:02:07.000Z (about 1 year ago)
- Last Synced: 2024-04-18T02:05:59.009Z (9 months ago)
- Topics: dart, flutter, state-management
- Language: Dart
- Homepage: https://pub.dev/packages/occam
- Size: 289 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Occam
Simple state manager based on native fluter stateful for my personal use.
Credits to: @roipeker
## Index
- [Why another state manager?](#why)
- [State Manager](#state-manager)
- [Rx Types](#rx-types)## Why
When I started coding Flutter there were a lots of state managers and was hard to choose between them because I like some features of each of one.
Also as a package get bigger there's a lot of unnused code or features that become part of a project unnecesarily, so the result is a project with a lot of pieces of code recreating the wheel.
The purpose of this package is to be as simple as posible and provide an easy and safety way to developers create his applications quickily and also easily maintanable by providing only one way to handle:
* View
* ControllerThe premisse is to have
1 view = 1 controller
View have only widgets withouth logic unless is a UI logic
and controllers have no widgets.The result is a clean UI file and a clean logic file.
The `RxTypes` are a refactor that follows the GetX pattern to create reactives types, but without the `Obs` widget.
`Obs` widget made usafe dispose correctly rx types sinces there's not a explicit declaration and remove over the listeners attached to a `RxType`.> This package is for my personal use and it could change the API over the time.
## Usage
```dart
class HomePage extends StateWidget {
const HomePage({Key? key}) : super(key: key);
/// You can override this and pass your own providers
@override
HomeController createState() => HomeController();@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Occam Demo'),
),
floatingActionButton: FloatingActionButton(
onPressed: state.onButton,
child: const Icon(Icons.add),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
RxWidget(
notifier: state.counter,
builder: (ctx, v) => Text('reactive $v'),
),
RxWidget(
notifier: state.model,
builder: (ctx, v) => Text('reactive $v'),
),
Center(
child: ElevatedButton(
onPressed: state.toSecondPage,
child: const Text('To Second page'),
),
),
Center(
child: ElevatedButton(
onPressed: state.toBottom,
child: const Text('To Bottom'),
),
),
],
),
);
}
}
class HomeController extends StateController{final counter=1.rx;
@override
void initState() {
//Executed when the widget is mounted
super.initState();
}
@override
void readyState() async {
/// Is executed after the widget is mounted but with context safe,
/// Here you can safely call:
final arguments =ModalRoute.of(context)?.settings.arguments;
}
void onButton() {
counter.value++;
}
void toSecondPage() async {
final result = await navigator.pushNamed(
'/secondPage',
arguments: 'test arguments',
);
}
@override
void dispose() {
counter.dispose();
super.dispose();
}
}
}```