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

每次我在项目的任何地方添加这个 (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();
  }
}

请帮忙

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

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/118.html

大家都在问