Flutter: Getting an error about using notifyListeners in a class that doesn't extend ChangeNotifier, but it seems to work?

38 views Asked by At

I have these two problems reported by vscode 98 times in my project, every time that I use classModelName.notifyListeners to update the state using the provider:

The member 'notifyListeners' can only be used within instance members of subclasses of 'package:flutter/src/foundation/change_notifier.dart'.

The member 'notifyListeners' can only be used within 'package:flutter/src/foundation/change_notifier.dart' or a test.

Initially, I tried extending every relevant class with ChangeNotifier, but I ran into the issue outlined in this github issue, where widgets don't dispose correctly. https://github.com/flutter/flutter/issues/24293

So I just removed the class extensions, and the app works perfectly, but the 95 reported problems are back.

Is it something I should be worried about? I'm concerned it might cause issues down the line, or be causing performance issues I'm unaware of etc.

0

There are 0 answers