1

Is someone able to explain to me why 'context' in there is undefined? i Watched like 5 videos about BuildContext and i still don't understand it. Yes i'm beginner with dart

class ZmienneClass extends ChangeNotifier {
void decrementCounter(int liczba) {
      if (_rundy == 0) {
        Navigator.push(context,
            MaterialPageRoute(builder: (context) => resGamePage(title: "")));
      };}}

2 Answers 2

3

The BuildContext is needed to tell Flutter where it should build its widgets. Currently you are trying to access a context without actually providing a valid BuildContext, if you really want to access the context, you could provide it trough the decrementCounter by passing one more parameter in it, decrementCounter(int liczba, BuildContext context) and pass the context from where you are calling it.

Sign up to request clarification or add additional context in comments.

1 Comment

Okey, error dissapeared, but now when _rundy are 0 nothing happens, can u help me with it? question: stackoverflow.com/questions/68996718/…
3

You dont declare BuildContext try below code refer BuildContext here

class ZmienneClass extends ChangeNotifier {

void decrementCounter(int liczba,BuildContext context) {
      if (_rundy == 0) {
        Navigator.push(context,
            MaterialPageRoute(builder: (context) => resGamePage(title: "")));
      };}}

1 Comment

Okey, error dissapeared, but when _rundy are 0 nothing happens, can u help me with it? question: stackoverflow.com/questions/68996718/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.