The method 'truncate' was called on null. Receiver: null Tried calling: truncate()

119 Views Asked by At

I'm getting this error while showing rating from firebase to ratingbarindicator. Please help Here is my ratingbarindicator code:

RatingBarIndicator(
                  rating: widget.doctor.rating,
                  itemBuilder: (context, index) => Icon(
                        Icons.star,
                        color: Colors.amber,
                      ),
                  itemCount: 5,
                  itemSize: 15.0,
                  direction: Axis.horizontal),
1

There are 1 best solutions below

0
Peter Haddad On

According to the code inside the class RatingBarIndicator, the truncate() method is being called on the rating property:

  @override
  void initState() {
    super.initState();
    _ratingNumber = widget.rating.truncate() + 1;
    _ratingFraction = widget.rating - _ratingNumber + 1;
  }

Therefore the value of widget.doctor.rating is null and that's why you get this error.