Builder widget for ChangeNotifier in Flutter

Issue

Background

  • A ValueNotifier has a ValueListenableBuilder widget.
  • A Stream has a StreamBuilder widget.
  • A Future has a FutureBuilder widget.

Question

  • What is the builder for ChangeNotifier?

What I tried

I tried using a ValueListenableBuilder with ChangeNotifier but ChangeNotifier doesn’t implement ValueListenable.

I know I could use ChangeNotifierProvider from the Provider package, but I’d like to know if there is a solution that doesn’t require a third-party package.

Solution

ChangeNotifier is a direct implementation of the Listenable Widget and for the Listenable, you can use AnimatedBuilder, which triggers rebuilds from a Listenable without passing back a specific value
Also, your class could extend from ChangeNotifier and add new capability to it and you can create a custom Builder widget base on these new functionalities

Answered By – Amir Hossein Mirzaei

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

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