【问题标题】:The method 'addSystemCategories' was called on null. in Flutter在 null 上调用了方法“addSystemCategories”。在颤振中
【发布时间】:2021-06-05 00:13:05
【问题描述】:

为什么这个方法调用会在这个错误中崩溃?我只想在切换开关时在我的数据库中添加一些数据。

在处理手势时引发以下 NoSuchMethodError: 在 null 上调用了方法“addSystemCategories”。接收方:空 尝试调用:addSystemCategories()

void toggleCategoriesSupport () {
    CategoriesProvider categoriesProvider;
    categoriesProvider.addSystemCategories();
    _categoriesSupport = !_categoriesSupport;
    _saveToPreferences();
    notifyListeners();
  }

这是我调用的方法:

void addSystemCategories() {
    final categoryAll = ProductCategory(createdTime: DateTime.now(), id: '0', title: 'Alle', type: 'category');
    final categoryNothing = ProductCategory(createdTime: DateTime.now(), id: '1', title: 'Keine', type: 'category');
    addCategory(categoryAll);
    addCategory(categoryNothing);
  }

【问题讨论】:

    标签: flutter google-cloud-firestore


    【解决方案1】:

    您在toggleCategoriesSupport 中写道:CategoriesProvider categoriesProvider;。你声明了categoriesProvider,但是你没有给它赋值,所以默认情况下它的值是null。你可能是想说CategoriesProvider categoriesProvider = CategoriesProvider();

    【讨论】:

      猜你喜欢
      • 2019-03-31
      • 2021-03-08
      • 1970-01-01
      • 1970-01-01
      • 2021-11-20
      • 2021-05-29
      • 1970-01-01
      • 2021-09-17
      • 2021-01-24
      相关资源
      最近更新 更多