Reputation: 153
i'm using provider package for state management , anyone can show me the right way reset field or variable ? example code here : i want to reset _counter back to 0 after i navigate to other screen , i need the right way to do it , thank you in advance :)
class AppProvider with ChangeNotifier {
int _counter = 0;
int get counter => _counter;
void incrementCounter() {
_counter++;
notifyListeners();
}
}
Upvotes: 0
Views: 675
Reputation: 336
add this method and call it when you navigate to other page:
class AppProvider with ChangeNotifier {
int _counter = 0;
int get counter => _counter;
void incrementCounter() {
_counter++;
notifyListeners();
}
void clear(){
_counter = 0;
notifyListeners();
}
}
Upvotes: 2