flutter_obx 0.0.3 flutter_obx: ^0.0.3 copied to clipboard
Simple state management for flutter
Integation Tutorial #
- Create a State Like this
classHomeState {
int? count;
HomeState({
this.count,
});
HomeStatecopyWith({int? count}) {
returnHomeState(count: count ?? this.count);
}
}
- Then import'package:flutter_obx/flutter_obx.dart';
- After importin the plagin create controller like this
Obx<HomeState>
homeController=Obx<HomeState>
(
value:HomeState(
count:0,
));
- Ater this use ObxProvider for reflect value in ui.
ObxProvider<HomeState>
(
obxController:homeController,
builder: (BuildContext context, HomeState value, Widget? child) {
returnSizedBox(
width:MediaQuery.of(context).size.width,
child:Column(
mainAxisAlignment:MainAxisAlignment.center,
children:`<Widget>`[
constText(
'You have pushed the button this many times:',
),
Text(
'${value.count}',
),
],
),
);
}
-
For update value follow this.
homeController.emit(homeController.obs.copyWith(count:count+1));