1

Using Google places and RatingBarIndicator. Everything is working as it should however, in addition to the rating stars I would love to have the rating number to the right of the stars, however, all documentation I have seen on RatingBarIndicator doesn't show how to get the number from the API.

places.dart

class Place {
  final String name;
  final double rating;
  final int userRatingCount;
  final String vicinity;
  final Geometry geometry;

  Place(
      {this.name,
      this.rating,
      this.userRatingCount,
      this.vicinity,
      this.geometry});

  Place.fromJson(Map<dynamic,dynamic> parsedJson)
    :name = parsedJson['name'],
  rating = (parsedJson['rating'] !=null) ? parsedJson['rating'].toDouble() : null,
  userRatingCount = (parsedJson['user_rating_total'] != null) ? parsedJson['user_rating_total'] : null,
  vicinity = parsedJson['vicinity'],
  geometry = Geometry.fromJson(parsedJson['geometry']);
}

Map.dart

Expanded(
                                  child: ListView.builder(
                                      itemCount: places.length,
                                      itemBuilder: (context, index) {
                                        return FutureProvider(
                                          create: (context) =>
                                              geoService.getDistance(
                                            currentPosition.latitude,
                                            currentPosition.longitude,
                                            places[index].geometry.location.lat,
                                            places[index].geometry.location.lat,
                                          ),
                                          child: Card(
                                            child: ListTile(
                                              title: Text(places[index].name),
                                              subtitle: Column(children: <Widget>[
                                                (places[index].rating != null) ? Row(children: <Widget>[
                                                  RatingBarIndicator(
                                                      rating: places[index].rating,
                                                    itemBuilder: (context, index) => Icon(Icons.star, color: Colors.amber),
                                                    itemCount: 5,
                                                    itemSize: 10,
                                                    direction: Axis.horizontal,
                                                  ),
                                                ],) : Row(),
                                                Consumer<double>(
                                                  builder: (context, meters, widget){

                                                  }
                                                ),
                                              ],),
                                            ),
                                          ),
                                        );
                                      }),
                                )
Scubadivingfool
  • 1,227
  • 2
  • 10
  • 23
  • You've given us not much detail to work with... have you read [this document](https://developers.google.com/maps/documentation/places/web-service/details#fields)? – ttyip Apr 01 '21 at 19:10
  • Yes, I have and have been working with it. From the goolge places API and calling ratings I am able to get the stars to show but I also want to get the number which I have not been able too. As the document shows ""rating" : 4.5," I am able to show 4.5 stars, and not the number. – Scubadivingfool Apr 01 '21 at 19:22
  • Just saw your edit, so your question is on how to show the number of ratings instead of how to access that number, am I right? – ttyip Apr 01 '21 at 19:31
  • Correct. I have been able to get the correct number of stars according to the rating, ie rating: 4.5, shows 4.5 stars. I also want to show the number. – Scubadivingfool Apr 01 '21 at 19:33
  • 1
    I don't think `RatingBarIndicator` has this functionality. You might be better off just adding a `Text` widget next to it. – ttyip Apr 01 '21 at 19:35

1 Answers1

1

RatingBarIndicator does not provide this functionality, you can add a Text widget with styling to the right of the indicator to mimic that appearance.

ttyip
  • 1,231
  • 1
  • 13
  • 21