rx_notifier_generator 1.0.2
rx_notifier_generator: ^1.0.2 copied to clipboard
Generate RxNotifier getter and setter. Use annotations @store and @rx
rx_notifier_generator #
Generate RxNotifier getter and setter. Use annotations @store and @rx;
OPTIONAL Code generator #
If you prefer a leaner syntax for RxNotifier objects, use code generation with build_runner.
- Add the rx_notifier_generator and build_runner packages to dev_dependencies.
dependencies:
rx_notifier: <current-version>
dev_dependencies:
rx_notifier_generator: <current-version>
build_runner: <current-version>
- Use the @RxStore annotation on the class and @RxValue on the properties.
part 'app_store.g.dart';
@RxStore()
abstract class _AppStore {
@RxValue()
int count = 0;
@RxValue()
String name = 'Barney';
}
- Run the build runner:
dart pub run build_runner --delete-conflicting-outputs
- Just use:
final appStore = AppStore();
rxObserver((){
print(appStore.count);
});
appStore.count++; // update
-
The class that will be annotated with @RxStore must be abstract and private. The generator will start a public instance with transparent RxNotifier.
-
Properties with @RxValue must be mutable and public.