flutter_scatter icon indicating copy to clipboard operation
flutter_scatter copied to clipboard

my font size doesn't work

Open veronica-pignotti opened this issue 5 years ago • 3 comments

Hi! I've tried to create my item for word cloud, replacing flutter hashtags. Color works but the font size no. In file flutter_scatter/example/lib/screens/word_cloud.dart, at the line 35, "body1" is deprecated, I've tried to use "bodyText1", "bodyText2" and others, but nothing changed. What can I do? Thanks. There is my code:

class WordsCloudItem extends StatelessWidget { final String text; Color color; double size; int rotated; final int index;

WordsCloudItem( this.text, this.index ){ setSizeAndColor(); this.rotated = Random().nextInt(2); }

@override Widget build(BuildContext context) => RotatedBox( quarterTurns: rotated, child: Text( this.text, style: TextStyle( fontSize: size, color: color ) ), );

void setSizeAndColor(){ if(index>81){color = Colors.red; size = 30.0;} else if(index>61){color = Colors.orange; size = 28.0; } else if(index>41){color = Colors.green; size = 26.0;} else if(index>21){color = Colors.blue; size = 24.0;} else color = Colors.purple; size = 22.0; } }

veronica-pignotti avatar Oct 18 '20 07:10 veronica-pignotti

The last else condition is not wrapped in curly braces. Therefore the size=22.0 statement does not come under any condition and is always executed when setSizeAndColor is called and hence defaults the size to 22.0

The fixed function :

void setSizeAndColor(){ if(index>81){color = Colors.red; size = 30.0;} else if(index>61){color = Colors.orange; size = 28.0; } else if(index>41){color = Colors.green; size = 26.0;} else if(index>21){color = Colors.blue; size = 24.0;} else {color = Colors.purple; size = 22.0;} }

rithik-dev avatar Oct 18 '20 10:10 rithik-dev

Oh, that's stupid error! Sorry and thank's for the answer ^^

veronica-pignotti avatar Oct 18 '20 12:10 veronica-pignotti

You're welcome 😃

rithik-dev avatar Oct 18 '20 15:10 rithik-dev