错误:在提供程序包中找不到类型“ SingleChildCloneableWidget”

时间:2019-12-24 12:37:49

标签: flutter dart flutter-provider

我更新了提供商。现在不起作用

  

lib / di / global_providers.dart:13:6:错误:找不到类型'SingleChildCloneableWidget'。   列出globalProviders = [        ^^^^^^^^^^^^^^^^^^^^^^^^^^^   lib / di / global_providers.dart:18:6:错误:找不到类型'SingleChildCloneableWidget'。   列出dependentServices = [        ^^^^^^^^^^^^^^^^^^^^^^^^^^^   lib / di / global_providers.dart:23:6:错误:找不到类型'SingleChildCloneableWidget'。   列出dependentServices = [        ^^^^^^^^^^^^^^^^^^^^^^^^^^^   lib / main.dart:18:16:错误:无法将参数类型“列表”分配给参数类型“列表”。    -“列表”来自“ dart:core”。    -'SingleChildWidget'来自'package:nested / nested.dart'('../../flutter/.pub-cache/hosted/pub.dartlang.org/nested-0.0.4/lib/nested.dart' )。       提供者:globalProviders,                  ^   lib / di / global_providers.dart:13:6:错误:“ SingleChildCloneableWidget”不是类型。   列出globalProviders = [        ^^^^^^^^^^^^^^^^^^^^^^^^^^^   lib / di / global_providers.dart:18:6:错误:“ SingleChildCloneableWidget”不是类型。   列出dependentServices = [        ^^^^^^^^^^^^^^^^^^^^^^^^^^^   lib / di / global_providers.dart:23:6:错误:“ SingleChildCloneableWidget”不是类型。   列出dependentServices = [

代码

List<SingleChildCloneableWidget> globalProviders = [
  ...independentServices,
  ...dependentServices,
];

List<SingleChildCloneableWidget> independentServices = [
  Provider.value(value: YelloChatDb()),
  Provider.value(value: YelloChatClient()),
];

List<SingleChildCloneableWidget> dependentServices = [
  ProxyProvider<YelloChatDb, CategoryDao>(
      update: (context, yelloChatDb, categoryDao) => CategoryDao(yelloChatDb)),

  ProxyProvider<YelloChatDb, SubCategoryDao>(
      update: (context, yelloChatDb,subCategoryDao) => SubCategoryDao(yelloChatDb)),

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

  ProxyProvider<YelloChatDb, EnquiriesDao>(
    update: (context, yelloChatDb, enquiriesDao) => EnquiriesDao(yelloChatDb),
  ),

  ProxyProvider<YelloChatClient, CategoryService>(
      update: (context, yelloChatClient, categoryService) =>
          CategoryService.create(yelloChatClient.chopperClient),
      dispose: (context, categoryService) => categoryService.client.dispose()),


  ProxyProvider2<CategoryDao, CategoryService, CategoriesRepository>(
      update: (context, categoryDao, categoryService, categoryRepository) =>
          CategoriesRepository(categoryDao: categoryDao, categoryService: categoryService)),

  ProxyProvider2<UserDao, CategoryService, UserRepository>(
      update: (context, userDao, categoryService, categoryRepository)=>
          UserRepository(userDao: userDao, categoryService: categoryService)
  ),

  ProxyProvider2<SubCategoryDao, CategoryService, SubCategoriesRepository>(
      update: (context, subCategoryDao, categoryService, subCategoryRepository) =>
          SubCategoriesRepository(categoryDao: subCategoryDao, categoryService: categoryService)),

  ProxyProvider2<EnquiriesDao, CategoryService, EnquiriesRepository>(
      update: (context, enquiriesDao, categoryService, enquiriesRepository) =>
          EnquiriesRepository(enquriesDao: enquiriesDao, categoryService: categoryService))
];

3 个答案:

答案 0 :(得分:3)

来自提供商v4.0.0

SingleChildCloneableWidget接口已被删除,并由SingleChildWidget接口和两个实现取代:

  • SingleChildStatelessWidget
  • SingleChildStatefulWidget

MultiProvider将接受SingleChildWidget而不是SingleChildCloneableWidget

在GitHub上查看此issue

答案 1 :(得分:3)

试试

import 'package:provider/single_child_widget.dart';

并替换

List<SingleChildCloneableWidget> independentServices

List<SingleChildWidget> independentServices

它有效。我已与依赖项提供程序核对:^4.3.2+3

答案 2 :(得分:0)

首先,我不建议您这样做。考虑直接在您的MultiProvider内部创建此列表。

做您当前正在做的事情会增加不必要的复杂性和仪式,而没有真正的好处。 实际上,您实际上正在降低可测试性。

但是,如果您坚持要这样做,那么自述文件就很清楚了:

用SingleChildWidget替换SingleChildCloneableWidget(来自provider / single_child_widget.dart)