ChangeNotifierProvider构建器已弃用

ChangeNotifierProvider构建器已弃用

本文介绍了Flutter ChangeNotifierProvider构建器已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的main.dart中有以下代码:

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(),
    ),
  );
}

大约2天前,我的视觉工作室代码显示以下警告:

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

所以我认为ChangeNotifierProvider上的构建器参数已弃用。我到处搜索,但找不到该构建器参数的替代项。那么如何消除这些警告呢?下面是我在Windows 10上使用 flutter --version 命令的flutter版本

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

推荐答案

自提供程序版本3.2.0开始, builder被标记为

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

更多信息可以在

应该这样做:

ChangeNotifierProvider(create: (context) => Auth())

这篇关于Flutter ChangeNotifierProvider构建器已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 02:29