【问题标题】:Reduce the amount on the flutter counter, error: The operator '-' isn't defined for the type 'String'减少颤振计数器上的数量,错误:未为“字符串”类型定义运算符“-”
【发布时间】:2021-09-15 20:55:11
【问题描述】:

我正在尝试减少柜台上购物车数量的金额,但我遇到了这个错误,谁能帮助我?谢谢你

【问题讨论】:

    标签: flutter android-studio dart mobile


    【解决方案1】:

    您收到此错误是因为您的 dataCart[index].price 类型是 String。 当您使用dataCart[index].price *= _count[index] 时,它实际上返回了另一个字符串。假设您的dataCart[index].price 值为"21"_counter[index] 值为3。然后dataCart[index].price *= _count[index] 将返回"212121"。这就是为什么dataCart[index].price *= _count[index] 这个没有任何错误。但是,当您尝试从 String 中减去 Integer 时,它会报错。

    因此,您应该将price String 的类型更改为int

    【讨论】:

      【解决方案2】:

      我认为您必须将price 的类型从String 更改为int。 这是您的错误的解决方案。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-03-05
        • 2020-12-28
        • 1970-01-01
        • 1970-01-01
        • 2015-12-14
        • 2020-12-20
        • 2021-01-03
        • 1970-01-01
        相关资源
        最近更新 更多