How To Create Smooth Star Rating Using Flutter Android App

admin_img Posted By Bajarangi soft , Posted On 05-11-2020

A Star rating with touch and swipe rate enabled Read only and adjustable rating, Web Support Supports replacing default star icons with desired IconData Supports half rate and full rate (1.0 or 0.5) Swipe for incrementing/decrementing rate amount Change star body and boundary colors independently Control size of the star rating Set your desired total Star count Supports click-to-rate Spacing between stars

How To Create Smooth Star Rating Using Flutter Android App

Smooth Star Rating
Step 1:  
We cannot directly remove the time stamp from Smooth Star Rating but using the intl.dart package we can easily filter the date stamp from time stamp. So open your flutter project’s pubspec.yaml in code

dependencies:
  flutter:
    sdk: flutter
  smooth_star_rating: ^1.1.1

Step 2: After done saving the pubspec.yaml file, Open your flutter project root folder in Command Prompt or Terminal and execute flutter pub get command. 

flutter pub get

Step 3: Open your project’s main.dart file and import material.dart and   smooth_star_rating: ^1.1.1. dart package.
import 'package:smooth_star_rating/smooth_star_rating.dart'; 

Complete Code For Smooth Star Rating In Flutter
main.dart

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

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  var rating = 3.0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Rating bar demo',
      theme: ThemeData(
        primarySwatch: Colors.red,
      ),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        backgroundColor: Colors.black,
        appBar: AppBar(
          title: Text('Smooth Star Rating'),
        ),
        body: Center(
            child: Column(
              children: [
                SizedBox(height: 40,),
                _heading('Smoothe Rating Bar'),
                SmoothStarRating(
                  rating: rating,
                  isReadOnly: false,
                  size: 35,
                  filledIconData: Icons.favorite,
                  halfFilledIconData: Icons.favorite,
                  defaultIconData: Icons.favorite_border,
                  starCount: 8,
                  allowHalfRating: true,
                  spacing: 2.0,
                  onRated: (value) {
                    print("rating value -> $value");
                    // print("rating value dd -> ${value.truncate()}");
                  },
                ),
              ],
            )),
      ),
    );
  }
  Widget _heading(String text) => Column(
    children: [
      Text(
        text,
        style: TextStyle(
          fontWeight: FontWeight.w300,
          fontSize: 24.0,
          color: Colors.white
        ),
      ),
      SizedBox(
        height: 20.0,
      ),
    ],
  );
}

Related Post