꿈꾸는 시스템 디자이너

Flutter Example - Request App Review | app_review plugin 본문

Tutorial/Flutter with App

Flutter Example - Request App Review | app_review plugin

독행소년 2019. 10. 17. 14:13

* About plugin

https://pub.dev/packages/app_review

 

app_review | Flutter Package

Request and Write Reviews and Open Store Listing for Android and iOS in Flutter.

pub.dev

 

https://pub.dev/packages/rating_dialog

 

rating_dialog | Flutter Package

A beautiful and customizable Star Rating Dialog package for Flutter

pub.dev

 

1. Add this to pubspec.yaml file

dependencies:
  app_review: ^1.0.0
  rating_dialog: ^1.0.0

 

2. Source Code

import 'package:flutter/material.dart';
import 'package:app_review/app_review.dart';
import 'package:rating_dialog/rating_dialog.dart';

ReviewAppDemoState pageState;

class ReviewAppDemo extends StatefulWidget {
  @override
  ReviewAppDemoState createState() {
    pageState = ReviewAppDemoState();
    return pageState;
  }
}

class ReviewAppDemoState extends State<ReviewAppDemo> {
  String appID = "";
  String output = "";

  @override
  initState() {
    super.initState();

    AppReview.getAppID.then((onValue) {
      setState(() {
        appID = onValue;
      });
      print("App ID" + appID);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Request App Review Demo")),
      body: Column(
        children: <Widget>[
          Card(
            child: ListTile(
              title: Text("App ID"),
              subtitle: Text(appID),
            ),
          ),
          Expanded(
            child: Center(
              child: RaisedButton.icon(
                color: Colors.blueAccent,
                textColor: Colors.white,
                icon: Icon(Icons.star),
                label: Text("Review App"),
                onPressed: () {
                  rateApp();
                },
              ),
            ),
          ),
        ],
      ),
    );
  }

  void rateApp() {
    showDialog(
      context: context,
      barrierDismissible: true, // set to false if you want to force a rating
      builder: (context) {
        return RatingDialog(
          icon: const FlutterLogo(size: 100, colors: Colors.blue),
          // set your own image/icon widget
          title: "The Rating Dialog",
          description:
              "Tap a star to set your rating. Add more description here if you want.",
          submitButton: "SUBMIT",
          //alternativeButton: "Contact us instead?",
          // optional
          //positiveComment: "We are so happy to hear :)",
          // optional
          //negativeComment: "We're sad to hear :(",
          // optional
          accentColor: Colors.blue,
          // optional
          onSubmitPressed: (int rating) {
            print("onSubmitPressed: rating = $rating");
            AppReview.writeReview;
          },
          onAlternativePressed: () {
            print("onAlternativePressed: do something");
          },
        );
      },
    );
  }
}

 

 

▶ Go to Table of Contents | 강의 목차로 이동


※ This example is also available in the Flutter Code Examples app. | 본 예제는 Flutter Code Examples 앱에서도 제공됩니다.

 

Flutter Code Examples - Google Play 앱

Are you a beginner at Flutter? Check out the various features of Flutter through the demo. Source code for all demos is also provided.

play.google.com

Comments