I'm trying casting a int to double in flutter/dart at param fontSize from Text Widget but I have this exception:
"Another exception was thrown: type 'int' is not a subtype of type 'double' in type cast"
I have been follow the instructions here: Why can't I convert a Number into a Double? but that's not working yet.
here is Text inside my component widget:
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
),
),
...
}
Out from component I'm passing at param fontSize a Int value like this:
...
ButtonLogin(
backgroundColor: ColorsCustom.loginScreenUp,
labelColor: Colors.white,
label: 'Back to other session?',
fontSize: 16,
mOnPressed: () => _login(),
);
...
the ellipsis is just to indicate there is more of code, its not part of code.
I am not getting any error. An advice I can give you to avoid errors is to use data types in your code when you define variables.