You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello guys,
I had trouble implementing this code when I copied and pasted it into project, so I added some code snippets to make it work for me.
// befor
@Ange0 the builder function requires a widget to return. In this case, you are returning the widget but it is in a switch statement. This means that if the switch statement didn't satisfy, your builder will return null which is not acceptable.
You can fix it by just adding a default case for the switch statement like this: default: return const SizedBox();
Hello guys,
I had trouble implementing this code when I copied and pasted it into project, so I added some code snippets to make it work for me.
// befor
RatingBar.builder(
initialRating: 3,
itemCount: 5,
itemBuilder: (context, index) {
switch (index) {
case 0:
return Icon(
Icons.sentiment_very_dissatisfied,
color: Colors.red,
);
case 1:
return Icon(
Icons.sentiment_dissatisfied,
color: Colors.redAccent,
);
case 2:
return Icon(
Icons.sentiment_neutral,
color: Colors.amber,
);
case 3:
return Icon(
Icons.sentiment_satisfied,
color: Colors.lightGreen,
);
case 4:
return Icon(
Icons.sentiment_very_satisfied,
color: Colors.green,
);
}
},
onRatingUpdate: (rating) {
print(rating);
},
;
// after
RatingBar.builder(
initialRating: 3,
itemCount: 5,
itemBuilder: (context, index) {
switch (index) {
case 0:
return Icon(
Icons.sentiment_very_dissatisfied,
color: Colors.red,
);
case 1:
return Icon(
Icons.sentiment_dissatisfied,
color: Colors.redAccent,
);
case 2:
return Icon(
Icons.sentiment_neutral,
color: Colors.amber,
);
case 3:
return Icon(
Icons.sentiment_satisfied,
color: Colors.lightGreen,
);
case 4:
return Icon(
Icons.sentiment_very_satisfied,
color: Colors.green,
);
}
return Container();
},
onRatingUpdate: (rating) {
print(rating);
},
)
The text was updated successfully, but these errors were encountered: