how-to-implement-rating-bar-in-flutter

How to Implement Rating Bar in Flutter?

User feedback is essential in mobile app development – it shapes product improvements, drives user engagement, and ultimately impacts the success of your application. A simple and intuitive method for collecting this feedback is through a rating bar system. In this post, we’ll walk through how to create a responsive and customizable Rating Screen in Flutter using the powerful flutter_rating_bar package.

Whether you’re building a food delivery app, e-commerce store, or service platform, enabling users to leave ratings can provide you with the insights you need while enhancing their overall experience.

Why Use a Rating Bar in Your App?

A rating bar provides users with a familiar, visual way to assess their experience. It simplifies the feedback process by reducing cognitive effort, making it easier to share opinions quickly. Ratings can:

  • Guide future users with peer insights.
  • Provide quantifiable data for analytics.
  • Help developers understand usability gaps.
  • Improve your app’s credibility and engagement metrics.

Flutter’s flexibility makes it easy to implement visually attractive, feature-rich rating widgets that match your design needs, and with the flutter_rating_bar plugin, the process becomes even simpler.

1. Getting Started

Before jumping into code, let’s get the basics out of the way. Follow these steps to create a new Flutter project:

  • Open Android Studio or VS Code.
  • Go to File > New > New Flutter Project.
  • Name your project (e.g., flutter_rating_app).
  • Select the Flutter SDK path and finish the setup.

To test the app, launch a Test Device:

  • Click Create Device in the left panel.
  • Choose a device type and launch it.

2. Add Required Dependencies

To use the flutter_rating_bar package, you’ll need to add it to your ubspec.yaml file:

				
					dependencies:
  flutter:
    sdk: flutter
  flutter_rating_bar: ^4.0.0
				
			

Run the following command to install the dependency:

				
					flutter pub get
				
			

This command fetches the package and makes it available in your app.

3. Import Packages

At the top of your Dart file, import the necessary libraries:

				
					import 'package:flutter/material.dart';
import 'package:flutter_rating_bar/flutter_rating_bar.dart';

				
			

4. Build the Rating Screen

4.1 Create the Screen

Let’s build a stateful widget to handle dynamic updates when a user interacts with the rating bar.

				
					class RatingBarScreen extends StatefulWidget {
  @override
  _RatingBarState createState() => _RatingBarState();
}

				
			

4.2 Define the State Class

				
					class _RatingBarState extends State<RatingBarScreen> {
  double value = 3.5;
  double _userRating = 3.0;
  IconData? _selectedIcon;
  TextEditingController _ratingController = TextEditingController();
  bool _isVertical = false;

  @override
  void initState() {
    super.initState();
    _ratingController = TextEditingController(text: '3.0');
  }

				
			

Here, we’re initialising the rating controller and updating it dynamically as the user interacts with the rating bar.

5. Build the UI

Now it’s time to design the screen layout and plug in our rating bar.

5.1 Scaffold and Layout

				
					

 @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Rating Screen'),
      ),
      body: Padding(
        padding: EdgeInsets.symmetric(horizontal: 16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text("Rate our service"),
            SizedBox(height: 10),
            RatingBar.builder(
              initialRating: 2,
              minRating: 1,
              direction: Axis.horizontal,
              allowHalfRating: true,
              itemCount: 5,
              itemBuilder: (context, _) => Icon(
                Icons.star,
                color: Colors.amber,
              ),
              onRatingUpdate: (rating) {
                print("User rated: \$rating");
              },
            ),
          ],
        ),
      ),
    );
  }
}

				
			

The user sees a set of stars to rate the service, and the numeric rating updates in a read-only text field.

6. Customize Your Rating Bar

You can also fully customize the icons using RatingWidget:

				
					RatingBar(
  ratingWidget: RatingWidget(
    full: Icon(Icons.star, color: Colors.green),
    half: Icon(Icons.star_half, color: Colors.green),
    empty: Icon(Icons.star_border, color: Colors.green),
  ),
  onRatingUpdate: (rating) => print(\"Rated: \$rating\"),
  itemSize: 40,
  initialRating: 4.5,
  itemCount: 5,
)

				
			

This adds your personality to the app, whether you use hearts, stars, emojis, or custom icons.

8. Output

The output is a sleek UI with a row of stars that users can tap to give feedback. It’s smooth, visually appealing, and easy to interact with.

9. Bonus Features to Enhance UX

Consider going beyond basic functionality. Here are a few bonus features to add polish:

  •  Add a Text Field for comments.

Allow users to explain their rating:

				
					TextField(
  decoration: InputDecoration(
    labelText: 'Leave a comment',
    border: OutlineInputBorder(),
  ),
  maxLines: 3,
),

				
			
  •  Integrate with Firebase Firestore or REST API to store and analyze user feedback.
  •  Use Animations for star glow or bounce.
  •  Vertical Layout: Change direction to Axis.vertical.

10. Real-World Use Cases

  • E-commerce apps: Let users rate products.
  • Service platforms: Ask users to rate after service completion.
  • Food delivery apps: Rate food quality, packaging, and delivery.
  • Learning apps: Rate course content or instructors.

Implementing a rating system in Flutter

Implementing a rating system in Flutter doesn’t have to be complicated. With the flutter_rating_bar package, it’s quick, elegant, and highly customizable. Whether you want simple star ratings or a full-blown feedback system with comments and analytics, this package provides a solid foundation.

This feature isn’t just eye candy, it’s a critical UX tool. It makes users feel heard and gives you valuable insights to improve your app.

So go ahead, add that rating screen. Your users (and your future self) will thank you!

Picture of Sushma Akula

Sushma Akula

I'm Sushma Akula, a Flutter Junior Developer passionate about building seamless, cross-platform mobile apps with intuitive UI/UX. I love solving real-world problems and exploring the dynamic world of mobile and open-source tech

Get a free quote