【问题标题】:How to fix argument type 'int?' can't be assigned to the parameter type 'num'如何修复参数类型'int?不能分配给参数类型“num”
【发布时间】:2022-07-26 14:47:10
【问题描述】:

我正在尝试进行计算。但我的价值来自int?,它不允许我这样做。错误是The argument type 'int?' can't be assigned to the parameter type 'num'. 我不明白。

这是我的代码:

  String goal= "1000";
  String workout = "0";
  String remaining = "";
  int? _total;

  @override
  void initState() {
    super.initState();
    dbHelper = DbHelper();
    _calcTotal();
  }

  void _calcTotal() async{
    var total = (await dbHelper.calcTotal())[0]['total'];
    print(total);
    setState(() => _total = total);
  } 



int resulttext = int.parse(goal) - _total + int.parse(workout);
remaining = resulttext.toString();

【问题讨论】:

    标签: flutter


    【解决方案1】:

    我通过这个解决了我的问题。我只是添加了这一行:

    var total = _total?.toInt() ?? 0;
    

    在此之前:

    int resulttext = int.parse(goal) - (total + int.parse(workout));
    

    【讨论】:

      【解决方案2】:

       setState(() {
          sliderlength = _carouselImages!.length;
        });

      这将解决您的问题。

      【讨论】:

        猜你喜欢
        • 2021-09-15
        • 2019-04-13
        • 2021-12-15
        • 1970-01-01
        • 2021-10-03
        • 2020-12-03
        • 2021-03-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多