statyx

Creator: coderz1093

Last updated:

0 purchases

statyx Image
statyx Images

Languages

Categories

Add to Cart

Description:

statyx

State management for Flutter.
Motivation #
Most of the time, I don't need all the features in GetX. Based on my experience, I extracted these frequently used
functions and made some changes.

Features #

All Rx types from GetX(RxInt, RxList..)
Obx from GetX
ViewModel that observes Widget life circle (onInit, onReady, onClose)


Usage #


Without state (No need to declare a VMState)
class HomePage extends Vmx<HomeViewModel> {
const HomePage({this.initialValue = 0});

final int initialValue;

@override
HomeViewModel createViewModel() => HomeViewModel();

@override
Widget build(context, vm) {
return Scaffold(
appBar: AppBar(title: const Text('Hello StatyX')),
floatingActionButton: FloatingActionButton(
onPressed: () => vm.counter.value++, child: const Icon(Icons.add)),
body: Center(child: Obx(() => Text('${vm.counter.value}'))),
);
}
}
copied to clipboard


With state (access vm everywhere in the VMState)
class HomePage extends StatefulWidget {
const HomePage({this.initialValue = 0});

final int initialValue;

@override
State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends VMState<HomePage, HomeViewModel> {
@override
ViewModel createViewModel() => HomeViewModel();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Hello StatyX')),
floatingActionButton: FloatingActionButton(
onPressed: () => vm.counter.value++, child: const Icon(Icons.add)),
body: Center(child: Obx(() => Text('${vm.counter.value}'))),
);
}
}
copied to clipboard



ViewModel
class HomeViewModel extends ViewModel<HomePage> {
final counter = 0.obs;

@override
void onInit() {
super.onInit();
counter.value = widget.initialValue;
}
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.