【问题标题】:calculate discount of prices in flutter计算颤动中的价格折扣
【发布时间】:2020-05-05 04:56:33
【问题描述】:

我想尝试定义以下公式来计算旧价格和新价格之间的计算并将其显示在文本小部件上,但是当我想在双变量中使用它时出现此错误:“只能访问静态成员初始化器" 这就是我想做的:

class ProductDetails extends StatefulWidget {
 final prod_fullName;
 final prod_pic;
 final prod_old_price;
 final prod_price;
 double percent=(prod_old_price - prod_price)/prod_old_price*100;
ProductDetails({
 this.prod_fullName,
 this.prod_pic,
 this.prod_old_price,
 this.prod_price,
});

@override
_ProductDetailsState createState() => _ProductDetailsState();
}
class _ProductDetailsState extends State<ProductDetails> {
 Row{
  child:new Text("$percent%");
}

【问题讨论】:

    标签: math flutter formula percentage discount


    【解决方案1】:
    class ProductDetails extends StatefulWidget {
      final String prod_fullName;
      final String prod_pic;
      final double prod_old_price;
      final double prod_price;
    
      const ProductDetails({Key key, this.prod_fullName, this.prod_pic, this.prod_old_price, this.prod_price}) : super(key: key);
    
      @override
      _ProductDetailsState createState() => _ProductDetailsState();
    }
    class _ProductDetailsState extends State<ProductDetails> {
      double percent;
      @override
      void initState() {
        percent=(widget.prod_old_price - widget.prod_price)/widget.prod_old_price*100;
        super.initState();
      }
    
      @override
      Widget build(BuildContext context) {
        return Text("$percent%");
      }
    }
    

    【讨论】:

    • 在khata ro mide dadash damet garm vali:类'String'没有实例方法'-'。
    • @MehrdadHosseini。 جوابویرایششد。 دقت که که همه پارامترها الزامی اند
    • منونم ازت الان تستش میکنم
    • type 'int' 不是 type 'String' 的子类型
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多