Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振/飞镖:在小部件参数中将int转换为双精度不工作_Flutter_Dart_Casting_Int_Double - Fatal编程技术网

Flutter 颤振/飞镖:在小部件参数中将int转换为双精度不工作

Flutter 颤振/飞镖:在小部件参数中将int转换为双精度不工作,flutter,dart,casting,int,double,Flutter,Dart,Casting,Int,Double,我正在尝试从文本小部件中以参数fontSize在flatter/dart中转换一个int以加倍,但我有一个例外: “引发了另一个异常:“int”类型不是类型转换中“double”类型的子类型” 我一直在按照这里的指示行事:但这还不起作用 以下是我的组件小部件中的文本: class ButtonLogin extends MaterialButton { ButtonLogin({this.fontSize, ...}); final fontSize; ... @override Wid

我正在尝试从文本小部件中以参数fontSize在flatter/dart中转换一个int以加倍,但我有一个例外:

“引发了另一个异常:“int”类型不是类型转换中“double”类型的子类型”

我一直在按照这里的指示行事:但这还不起作用

以下是我的组件小部件中的文本:

class ButtonLogin extends MaterialButton {
  ButtonLogin({this.fontSize, ...});

final fontSize;
...

@override
Widget build(BuildContext context){
double fontSizeDouble = (fontSize as num) as double; 
...
Text(
 label,
 style: TextStyle(
   fontSize: fontSizeDouble,
   color: labelColor,
   fontWeight: FontWeight.bold
 ),
),
...
}
从组件中,我以param fontSize传递一个Int值,如下所示:

...
 ButtonLogin(
      backgroundColor: ColorsCustom.loginScreenUp,
      labelColor: Colors.white,
      label: 'Back to other session?',
      fontSize: 16,
      mOnPressed: () => _login(),
 );
...

省略号只是表示有更多的代码,而不是代码的一部分

我没有收到任何错误。我可以给您一个避免错误的建议,就是在定义变量时在代码中使用数据类型。

我没有收到任何错误。我可以给您一个避免错误的建议,就是在定义变量时在代码中使用数据类型。

您好,我没有收到任何错误。我可以给你一个避免错误的建议,就是在定义变量时在代码中使用数据类型。在使用数字之前尝试使用
.toDouble()
吗?谢谢@camillo777,我刚刚在final之后添加了type double,就像这样:“final double fontSize”,这就行了。@JuniorMachado我很高兴它起作用,如果它对你有帮助,你能按向上箭头说它有用吗?谢谢大家!@卡米洛777我试过了,但我得到了回报:“你不能为自己的职位投票”,我做错了什么(您好,我没有收到任何错误。我可以给您一个避免错误的建议,就是在定义变量时在代码中使用数据类型。在使用数字之前尝试使用
.toDouble()
?谢谢@camillo777,我刚刚在final之后添加了type double,如下图所示:“final double fontSize”,这很有效。@JuniorMachado我很高兴它有效,如果它能帮助你,你能按向上箭头说它有用吗?谢谢!@camillo777我试过了,但我得到了回报:“你不能为你自己的帖子投票”,我做错了什么(