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

Issue

I am using ChangeNotifier and i change their value and notify like below,

// Declare
ValueNotifier<bool> isDisplay = new ValueNotifier(false);

// Change value
isDisplay.value = false;
isDisplay.notifyListeners();

It’s working fine. but it’s raise warning like below,
enter image description here

Can we resolve this using proper implementation or other things ?

Solution

You do not need to call notifyListeners, as this is automatically called when a new value is set.

ChangeNotifier implementations like ValueListener should never require notifyListeners to be called manually.

Answered By – hacker1024

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *