【问题标题】:The operator '/' isn't defined for the type 'Double'. Try defining the operator '/'没有为“Double”类型定义运算符“/”。尝试定义运算符'/'
【发布时间】:2021-09-28 04:35:09
【问题描述】:

没有为“Double”类型定义运算符“/”。 尝试定义运算符'/'.dart(undefined_operator)

 Padding(
    padding: const EdgeInsets.only(right: 8.0),
    child: Text("\$${product.price! / 100}", style: TextStyle(   //error at this line
    fontWeight: FontWeight.bold,

【问题讨论】:

  • product.price 的数据类型是什么?
  • 价格翻倍
  • 如果您绝对肯定 price 是双精度数,您可能需要尝试重新安装 Dart/Flutter。
  • product.price 的值是多少?您是否先打印了值?请提供您将获得的 product.value 的值。
  • 错误是指Double还是double?内置类型为double。如果您收到关于 Double 的错误,那么这是其他一些类,您应该指出该类的来源。

标签: firebase flutter dart mobile-application


【解决方案1】:

如果价格是一个字符串,你应该使用它来解析它 double.parse(product.price!)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-11
    • 2021-04-03
    • 2021-12-02
    • 1970-01-01
    • 2021-06-11
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多