在flutter中访问提供者setter时不存在获取函数返回错误

时间:2021-08-02 00:23:35

标签: flutter provider flutter-change-notifier

每次我在项目的任何地方添加这个 (Provider.of<NutritionState>(context, listen: true).ChangeCalories = 4;) 时,我都会收到这个错误

The following _TypeError was thrown building StreamBuilder<QuerySnapshot<Object?(dirty, state: _StreamBuilderBaseState<QuerySnapshot<Object?>, AsyncSnapshot<QuerySnapshot<Object?>>>#345e0):
type 'Null' is not a subtype of type 'String' of 'function result'

这里是通知程序

    class NutritionState extends ChangeNotifier {
  double _calories = 15;

  double get Calories => _calories;

  void set calorieChange(double newCal) {
    _calories = newCal;
    notifyListeners();
  }
}

请帮忙

0 个答案:

没有答案