reset field or variable in Provider

303 views
Skip to first unread message

You Sour

unread,
Feb 1, 2021, 2:00:44 AM2/1/21
to Flutter Development (flutter-dev)
hi, 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();
}
}

1.gif

Suzuki Tomohiro

unread,
Feb 1, 2021, 8:41:00 AM2/1/21
to Flutter Development (flutter-dev)
2 questions to help that.

1. Are you able to print(“hello”) when you navigate to other screen?

2. The AppProvider does not have a method to reset counter to 0. Can you add such method?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/6cb348cf-ad92-4edf-b973-82c995bfc500n%40googlegroups.com.

You Sour

unread,
Feb 1, 2021, 10:02:30 AM2/1/21
to Flutter Development (flutter-dev)
yes , i can print it when navigate to other screen , yeah , i know provider don't kind of that method , i just want to how everyone do it in the right way :) 

Suzuki Tomohiro

unread,
Feb 1, 2021, 5:31:25 PM2/1/21
to You Sour, Flutter Development (flutter-dev)
Then I would call such reset method when navigate to other screen.

You Sour

unread,
Feb 1, 2021, 8:09:40 PM2/1/21
to Flutter Development (flutter-dev)
i did like that too , so no other way ?

Suzuki Tomohiro

unread,
Feb 1, 2021, 8:15:10 PM2/1/21
to Flutter Development (flutter-dev)
It seems that there's something you don't like about that approach. Do you want to elaborate on that?

You Sour

unread,
Feb 1, 2021, 11:35:57 PM2/1/21
to Flutter Development (flutter-dev)
i just want to know if possible it has other way to do it , if not that's ok , thank you 
so much for your time 
Reply all
Reply to author
Forward
0 new messages