App Review Implementation In Flutter

Introduction

 
In this article, we will learn how to implement an app review feature in a Flutter app. To add the review feature in Flutter applications, we will use app_review plugin. In Android, the app review will redirect you to Google Play Store and in iOS, it will open a popup for you to write the app review. So, let’s start implementing it.
 
Output
 
App Review Implementation In Flutter
 

Methods

  1. AppReview.getAppID: This method will return the application id
  2. AppReview.storeListing: This method is for Android app review and it will redirect the user to Google Play Store for reviewing the app.
  3. AppReview.requestReview: This method is for the iOS app and it will open a popup to review the app.
Plugin Required
 
app_review: ^1.0.0
 

Steps

 
Step 1
 
The first and most basic step is to create a new application in Flutter. If you are a beginner, then you can check my blog Create your first app in Flutter. I have created an app named as “flutter_app_review”.
 
Step 2
 
Now, we will configure intro_views_flutter plugin in pubspec.yaml file.
  1. dependencies:  
  2.  flutter:  
  3.    sdk: flutter  
  4.  cupertino_icons: ^0.1.2  
  5.  app_review: ^1.0.0  
Step 3
 
Now, we will implement the app review functionality for Android and iOS both. All the above-explained methods will be implemented in the main.dart file. Following is the programming implementation for that.
  1. import 'package:flutter/material.dart';  
  2. import 'package:app_review/app_review.dart';  
  3.    
  4. void main() => runApp(MyApp());  
  5.    
  6. class MyApp extends StatelessWidget {  
  7.  @override  
  8.  Widget build(BuildContext context) {  
  9.    return MaterialApp(  
  10.      theme: ThemeData(  
  11.        primarySwatch: Colors.blue,  
  12.      ),  
  13.      home: MyHomePage(),  
  14.    );  
  15.  }  
  16. }  
  17.    
  18. class MyHomePage extends StatefulWidget {  
  19.  @override  
  20.  _MyHomePageState createState() => _MyHomePageState();  
  21. }  
  22.    
  23. class _MyHomePageState extends State<MyHomePage> {  
  24.  String appID = "";  
  25.  String output = "";  
  26.  @override  
  27.  void initState() {  
  28.    super.initState();  
  29.    AppReview.getAppID.then((onValue) {  
  30.      setState(() {  
  31.        appID = onValue;  
  32.      });  
  33.      print("App ID" + appID);  
  34.    });  
  35.  }  
  36.    
  37.  @override  
  38.  Widget build(BuildContext context) {  
  39.    return Scaffold(  
  40.      appBar: AppBar(  
  41.        title: Text('Flutter App Review'),  
  42.      ),  
  43.      body: SingleChildScrollView(  
  44.        child: new ListBody(  
  45.          children: <Widget>[  
  46.            new Container(  
  47.              height: 40.0,  
  48.            ),  
  49.            new ListTile(  
  50.              leading: new Icon(Icons.info),  
  51.              title: new Text('App ID'),  
  52.              subtitle: new Text(appID),  
  53.              onTap: () {  
  54.                AppReview.getAppID.then((onValue) {  
  55.                  setState(() {  
  56.                    output = onValue;  
  57.                  });  
  58.                  print(onValue);  
  59.                });  
  60.              },  
  61.            ),  
  62.            new Divider(  
  63.              height: 20.0,  
  64.            ),  
  65.            new ListTile(  
  66.              leading: new Icon(  
  67.                Icons.shop,  
  68.              ),  
  69.              title: new Text('View Store Page'),  
  70.              onTap: () {  
  71.                AppReview.storeListing.then((onValue) {  
  72.                  setState(() {  
  73.                    output = onValue;  
  74.                  });  
  75.                  print(onValue);  
  76.                });  
  77.              },  
  78.            ),  
  79.            new Divider(  
  80.              height: 20.0,  
  81.            ),  
  82.            new ListTile(  
  83.              leading: new Icon(  
  84.                Icons.star,  
  85.              ),  
  86.              title: new Text('Request Review'),  
  87.              onTap: () {  
  88.                AppReview.requestReview.then((onValue) {  
  89.                  setState(() {  
  90.                    output = onValue;  
  91.                  });  
  92.                  print(onValue);  
  93.                });  
  94.              },  
  95.            ),  
  96.            new Divider(  
  97.              height: 20.0,  
  98.            ),  
  99.            new ListTile(  
  100.              leading: new Icon(  
  101.                Icons.note_add,  
  102.              ),  
  103.              title: new Text('Write a New Review'),  
  104.              onTap: () {  
  105.                AppReview.writeReview.then((onValue) {  
  106.                  setState(() {  
  107.                    output = onValue;  
  108.                  });  
  109.                  print(onValue);  
  110.                });  
  111.              },  
  112.            ),  
  113.            new Divider(  
  114.              height: 20.0,  
  115.            ),  
  116.            new ListTile(  
  117.              title: new Text(output),  
  118.            ),  
  119.          ],  
  120.        ),  
  121.      ),  
  122.    );  
  123.  }  
  124. }  
Hooray…. Run the app and test it on an emulator/simulator or a device.
 

Conclusion

 
We have learned how to implement the app review feature in a Flutter application.
 


Similar Articles