builder不建议使用,不应使用Flutter Provider

时间:2019-12-10 00:39:40

标签: flutter dart flutter-provider

如何解决此问题?我尝试添加create以及如何传递这些参数?

  ProxyProvider<YelloChatDb, UserDao>(
    builder: (context, yelloChatDb, userdAO) => UserDao(yelloChatDb),
  ),

  ProxyProvider<YelloVendorClient, VendorService>(
      builder: (context, yelloVendorClient, categoryService) =>
          VendorService.create(yelloVendorClient.chopperClient),
      dispose: (context, categoryService) => categoryService.client.dispose()),

道课

@UseDao(tables: [Users])
class UserDao extends DatabaseAccessor<YelloChatDb> with _$UserDaoMixin {
  UserDao(YelloChatDb db) : super(db);

...
}

1 个答案:

答案 0 :(得分:0)

更改日志3.2.0 https://pub.dev/packages/provider#320
已过时的提供商“构建者”赞成“创建”
您可以使用create代替builder
https://pub.dev/packages/provider#proxyprovider中的示例
代码段

Widget build(BuildContext context) {
  return MultiProvider(
    providers: [
      ChangeNotifierProvider(create: (_) => Counter()),
      ProxyProvider<Counter, Translations>(
        create: (_, counter, __) => Translations(counter.value),
      ),
    ],
    child: Foo(),
  );
}