flutter出现类转换异常“Error: The argument type 'dart.core::int' can't be assigned to the parameter type 'dart.core::double'”,int类型不能转化为double类型,小编的代码如下:
new MaterialButton( onPressed: _incrementCounter, child: new Text("增加按钮"), color: Colors.blue, textColor: Colors.white, minWidth: 80, height: 20, ),
错误分析:
由于minWidth与height传入的是double类型的值,而小编给的是int类型,所以flutter无法自动转换,就报错了,错误代码如下:
lib/main.dart:114:25: Error: The argument type 'dart.core::int' can't be assigned to the parameter type 'dart.core::double'. Try changing the type of the parameter, or casting the argument to 'dart.core::double'. minWidth: 80, ^ lib/main.dart:115:23: Error: The argument type 'dart.core::int' can't be assigned to the parameter type 'dart.core::double'. Try changing the type of the parameter, or casting the argument to 'dart.core::double'. height: 20,
解决方案:
将80与20分别改成80.0与20.0就可以自动转换double类型了,或者是如下这样使用toDouble()方法即可:
minWidth: 80.toDouble(), height: 20.toDouble(),