11import 'package:flutter/material.dart' ;
22
3- typedef void RatingChangeCallback (double rating);
3+ typedef RatingChangeCallback = void Function (double rating);
44
55class GFRating extends StatelessWidget {
6- GFRating ({
6+ const GFRating ({
77 this .itemCount = 5 ,
88 this .spacing = 0.0 ,
99 this .rating = 0.0 ,
@@ -15,9 +15,7 @@ class GFRating extends StatelessWidget {
1515 this .filledIcon,
1616 this .halfFilledIcon,
1717 this .allowHalfRating = true ,
18- }) {
19- assert (this .rating != null );
20- }
18+ }) : assert (rating != null );
2119
2220 /// defines total number of rating items
2321 final int itemCount;
@@ -61,7 +59,7 @@ class GFRating extends StatelessWidget {
6159 size: itemSize,
6260 );
6361 } else if (index > rating - (allowHalfRating ? 0.5 : 1.0 ) &&
64- index < rating) {
62+ index <= rating) {
6563 icon = Icon (
6664 halfFilledIcon != null ? halfFilledIcon : Icons .star_half,
6765 color: color ?? Theme .of (context).primaryColor,
@@ -77,9 +75,10 @@ class GFRating extends StatelessWidget {
7775
7876 return GestureDetector (
7977 onTap: () {
80- if (onRatingChanged != null ) onRatingChanged (index + 1.0 );
78+ if (onRatingChanged != null ) {
79+ onRatingChanged (index + 1.0 );
80+ }
8181 },
82- // onHorizontalDragStart: ,
8382 child: icon,
8483 );
8584 }
@@ -88,9 +87,12 @@ class GFRating extends StatelessWidget {
8887 Widget build (BuildContext context) => Material (
8988 color: Colors .transparent,
9089 child: Wrap (
91- alignment: WrapAlignment .center,
92- spacing: spacing,
93- children: List .generate (
94- itemCount, (index) => buildRatingBar (context, index))),
90+ alignment: WrapAlignment .center,
91+ spacing: spacing,
92+ children: List .generate (
93+ itemCount,
94+ (index) => buildRatingBar (context, index),
95+ ),
96+ ),
9597 );
9698}
0 commit comments