my font size doesn't work
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; } }
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;} }
Oh, that's stupid error! Sorry and thank's for the answer ^^
You're welcome 😃