Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter ChangeNotifierProvider builder is deprecated

Tags:

I have this code in my main.dart:

main() {   runApp(     MultiProvider(       providers: [         ChangeNotifierProvider(builder: (context) => Auth()), // /**problem here. builder displayed with strikethrough line**/       ],       child: App(),     ),   ); } 

since about 2 days ago, my visual studio code showing this warning:

enter image description here

so I guess builder parameter on ChangeNotifierProvider is deprecated. I searched everywhere but can't find alternative to this builder parameter. So how to remove these warning? Below is my flutter version using flutter --version command on Windows 10

> flutter --version Flutter 1.9.1+hotfix.6 • channel stable • https://github.com/flutter/flutter.git Framework • revision 68587a0916 (3 months ago) • 2019-09-13 19:46:58 -0700 Engine • revision b863200c37 Tools • Dart 2.5.0 

For any help, thanks in advance

like image 469
Dika Avatar asked Nov 29 '19 07:11

Dika


People also ask

What is the difference between provider and ChangeNotifierProvider?

Now instead of the Provider class, we subscribe to this model using the ChangeNotifierProvider. The difference between the ChangeNotifierProvider and the Provider is that: The Provider takes a value and exposes it to all the widgets, but it does not listen to changes from that value.

How do I get rid of ChangeNotifierProvider Flutter?

You need to use the dispose() method of State or the default constructor of ChangeNotifierProvider . The latter automatically disposes of the object created in the create function.

What is ChangeNotifierProvider in Flutter?

According to the Flutter docs, a ChangeNotifier is 'a class that can be extended or mixed in that provides a change notification API using VoidCallback for notifications.

What is create in ChangeNotifierProvider?

Creates a ChangeNotifier using create and automatically disposes it when ChangeNotifierProvider is removed from the widget tree.


1 Answers

Since provider version 3.2.0 "builder" is marked as deprecated in favor of "create".

More info can be found in the change log

So should do:

ChangeNotifierProvider(create: (context) => Auth()) 
like image 200
Nuts Avatar answered Sep 21 '22 01:09

Nuts