首页 > 解决方案 > 如何在颤动的文本小部件中使用双值?

问题描述

我正在使用数据表来显示产品列表和月收入。我也需要显示年收入,但我没有从 JSON 获得年收入。我只获得月收入,我需要将月收入乘以 12 才能获得年收入。这是我的数据表代码

DataTable(
            headingRowColor:
            MaterialStateColor.resolveWith((states) => Color(0xFF00105C)),
            columns: [
              DataColumn(
                  label: Text("Product",
                style: TextStyle(
                    fontSize: 12,
                    fontFamily: 'Roboto Bold',
                    color: Colors.white
                ),)),
              // DataColumn(label: Text("Code")),
              DataColumn(label: Text("Revenue(M)",
                style: TextStyle(
                    fontFamily: 'Roboto Bold',
                    color: Colors.white
                ),
              )
              ),
              DataColumn(label: Text("Revenue(A)",
                style: TextStyle(
                    fontSize: 12,
                    fontFamily: 'Roboto Bold',
                    color: Colors.white
                ),)),
            ],
            rows: snapshot.data.map((e) => DataRow(
              cells: [

                DataCell(Text(e.product.productName,
                  style: TextStyle(
                      fontFamily: 'Roboto Regular',
                      color: Colors.black
                  ),),),
                // DataCell(Text(e.product.code)),
                DataCell(Text(e.expectedRevenue.toString(),
                  style: TextStyle(
                      fontFamily: 'Roboto Regular',
                      color: Colors.black
                  ),)),
                DataCell(Text(e.expectedRevenue*12.toString(),
                  style: TextStyle(
                      fontFamily: 'Roboto Regular',
                      color: Colors.black
                  ),)),

              ]
            )).toList(),
          ),

expectedRevenue 是 JSON 中的动态数据类型。

String id;
int leadProductId;
int leadId;
int productId;
dynamic expectedRevenue;
DateTime createdDate;
int createdBy;
int recordStatus;
dynamic lead;
Product product;

在这里,我收到了年度收入数据单元格的错误

type 'String' is not a subtype of type 'num' of 'other'

如何解决这个问题? 如何找到收入(M)列数据单元格的总值?

标签: flutter

解决方案


尝试这个

double.parse(e.expectedRevenue)*12

推荐阅读