preface
Flutter is Google’s mobile UI framework for quickly building high-quality native user interfaces on iOS and Android.
Nicholas Gaulbag, a famous IT expert, once said: The wheel is the ladder of IT progress! Popular frames are the same, with wheels pick one in a million! Flutter, a cross-platform development framework that has been on the rise for the last two years, has a smaller third-party ecosystem than other mature frameworks, but it has a lot of wheels. This series of articles select the wheels commonly used in daily APP development to share, so as to improve the efficiency of brick moving, and hope that the ecology of Flutter will become more and more perfect, with more and more wheels.
This series of articles has been prepared with over 50 wheel recommendations, working for reasons that try to produce an article every 1-2 days.
This series of articles is for those who already have some of the basics of FLUTTER
The body of the
The wheel
- Wheel name: Flutter_rating_bar
- Overview of the Wheels: Flutter’s customizable scoring components.
- Wheels by Sarbagya. Me
- ★★★★ ★
- ★★★
- Effect preview:
The installation
dependencies:
flutter_rating_bar: ^ 3.0.0
Copy the code
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
Copy the code
Method of use
Default effect:
RatingBar(
initialRating: rate1, // The initial score is double
allowHalfRating: true.// Allow 0.5 points
itemCount: 5.// Score the number of components
itemPadding: EdgeInsets.symmetric(horizontal: 4.0),
itemBuilder: (context, _) => Icon(
Icons.star,
color: Colors.amber,
),
onRatingUpdate: (rating) {
setState(() {
this.rate1=rating; }); },)Copy the code
Custom scoring style:
RatingBar(
initialRating: rate2,
direction: Axis.horizontal,
allowHalfRating: true,
itemCount: 5,
ratingWidget: RatingWidget(// Customize the scoring component
full: Image.asset('assets/heart.png',color: Colors.amber,),
half: Image.asset('assets/heart_half.png',color: Colors.amber,),
empty: Image.asset('assets/heart_border.png',color: Colors.amber,),
),
itemPadding: EdgeInsets.symmetric(horizontal: 4.0),
onRatingUpdate: (rating) {
setState(() {
this.rate2=rating; }); },),Copy the code
Control style with index:
RatingBar(
initialRating: rate3,
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) {
setState(() {
this.rate3=rating; }); },),Copy the code
Vertical direction:
RatingBar(
initialRating: rate4,
direction: Axis.vertical,/ / vertical direction
allowHalfRating: true,
itemCount: 5,
itemPadding: EdgeInsets.symmetric(horizontal: 4.0),
itemBuilder: (context, _) => Icon(
Icons.star,
color: Colors.amber,
),
onRatingUpdate: (rating) {
setState(() {
this.rate4=rating; }); },),Copy the code
At the end
- Address of wheel warehouse: pub.flutter-io.cn/packages/fl…
- Series demo source: github.com/826327700/f…