Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

dart - Flutter ChangeNotifierProvider builder is deprecated

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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())

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...