Using a Flutter package FlutterRatingBarIndicator
, I need to use a double
to determine a x/5 rating. Using another package, flutter_google_places
to be specific, I get the num
value f.rating
.
With f.rating
, I should be able to convert from num
to double
using something like f.rating.toDouble()
but this is returning null
.
I'm not sure why it's returning null
as f.rating.toString()
returns a non-null value such as 3.5
Is there any special casting I need to apply before a num
can be used as a double
value?
Thanks
Edit; How I get f.rating
:
Using flutter_google_places
I receive rating
as a num
value from result
:
void getNearbyPlaces(LatLng center) async {
final location = Location(lat, lng);
final result = await _places.searchNearbyWithRadius(location, 2500, type: 'restaurant');
setState(() {
if (result.status == "OK") {
this.places = result.results;
}
print(result.status);
print(places.toString());
});
}
This later appears as places.map
:
final placesWidget = places.map((f) {}).toList();
Finally this is used in a flutter_rating_bar
:
FlutterRatingBarIndicator(
rating: f.rating,
itemCount: 5,
itemSize: 15.0,
emptyColor: Colors.amber.withAlpha(100),
itemPadding: EdgeInsets.only(top: 2.5, bottom: 6),
),
f.rating.runtimeType
? Can you show code?f.rating.runtimeType
returns adouble
f.rating
when you check itsruntimeType
and where passing it generates atype 'int' is not a subtype of type 'double'
runtime error. (Also, how do you know that that error comes fromf.rating
?) You also are not showing your real code sinceplaces.map((f) {}.toList();
isn't syntactically valid. Really you need to distill your problem into a minimal, complete, verifiable example. (Doing so might help you identify the problem on your own too.)