flutter - 如何在颤动的文本小部件中使用双值?
问题描述
我正在使用数据表来显示产品列表和月收入。我也需要显示年收入,但我没有从 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)列数据单元格的总值?
解决方案
尝试这个
double.parse(e.expectedRevenue)*12
推荐阅读
- google-analytics - Load Google Analytics js file with CSP nonce
- jquery - jQuery - 当类显示不止一次时如何获取当前的 div id
- couchdb - 从命令行使用 _find
- python - ValueError:形状不匹配:形状(30,)的值数组无法广播到形状(9,30)的索引结果
- javascript - 安装本地节点类型时的重复标识符
- angular - 将一个 observable 与其管道的结果组合成一个 observable
- javascript - Javascript - 添加两个哈希映射
- sql - NBA篮球比赛查询
- jquery - jQuery ionCalendar - 如何将一周的第一天设置为星期一
- javascript - 即使某些元素不存在,Jquery 也会使侦听器工作