I'm confused about how to use stateNotifier with riverpod. Most of the tutorials out there uses the counter example which is good but still not that clear to me. I'm trying to implement a stateNotifier with 2 states : isDrawerOpen and isDrawerColor which returns boolean result. Some functions will trigger the changes in those state. Below is what I have implemented and could really use some clarification.
import 'package:flutter_riverpod/all.dart';
class DrawerNotifier extends StateNotifier{
DrawerNotifier() : super(false);
bool isDrawerOpen = false;
bool isDrawerColor = false;
void toggleDrawer() {
isDrawerOpen = !isDrawerOpen;
}
void toggleColor() {
isDrawerColor = !isDrawerColor;
}
}
final drawerProvider = StateNotifierProvider((_) => DrawerNotifier());
final isDrawerOpen = StateNotifierProvider((ref){
final state = ref.watch(drawerProvider);
return state.isDrawerOpen;
});
final isDrawerColor = StateNotifierProvider((ref){
final state = ref.watch(drawerProvider);
return state.isDrawerColor;
});