From c27394c57c5baffb5fa8da9476cb9a0fee0e113d Mon Sep 17 00:00:00 2001 From: SimonIT Date: Wed, 6 Nov 2019 21:04:47 +0100 Subject: [PATCH] request app review after 5 launches --- lib/main.dart | 40 ++++++++++++++++++++++++++++++++++++++++ pubspec.lock | 14 ++++++++++++++ pubspec.yaml | 1 + 3 files changed, 55 insertions(+) diff --git a/lib/main.dart b/lib/main.dart index 4d2c8f6..407f8fe 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:app_review/app_review.dart'; import 'package:duration/duration.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; @@ -107,6 +108,44 @@ class _TimeTrackerState extends State { SharedPreferences.getInstance().then((SharedPreferences prefs) { this.prefs = prefs; this.highlightBreaks = prefs.getBool("highlightBreaks") ?? false; + int appLaunches = prefs.getInt("appLaunches") ?? 0; + if (appLaunches > 4) { + Future.delayed( + const Duration(seconds: 10), + () => showCupertinoDialog( + context: context, + builder: (BuildContext context) => CupertinoAlertDialog( + title: const Text("Dir gefällt der TimeTracker?"), + content: const Text("Dann zeig es mir!"), + actions: [ + CupertinoDialogAction( + isDefaultAction: true, + child: const Text("Ich lasse ein Bewertung da ⭐"), + onPressed: () { + Navigator.of(context, rootNavigator: true).pop("Rate"); + AppReview.writeReview; + }, + ), + CupertinoDialogAction( + child: const Text("Ich kaufe dir etwas 🛒"), + onPressed: () { + Navigator.of(context, rootNavigator: true).pop("Buy"); + _tabController.index = 3; + }, + ), + CupertinoDialogAction( + child: const Text("Alles erledigt 🎉"), + onPressed: () { + Navigator.of(context, rootNavigator: true).pop("Cancel"); + prefs.setInt("appLaunches", -1); + }, + ), + ], + ), + )); + } else if (appLaunches > -1) { + prefs.setInt("appLaunches", ++appLaunches); + } }); } @@ -692,6 +731,7 @@ class _TimeTrackerState extends State { cs.addAll([ CSHeader("Weitere Infos"), + CSLink("Im Store Anzeigen", () => AppReview.storeListing), CSLink("Quelltext", () => launch("https://github.com/SimonIT/timetracker")), CSLink("Kontakt", () => launch("mailto:simonit.orig@gmail.com")), CSLink( diff --git a/pubspec.lock b/pubspec.lock index ad0808e..f131bad 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -15,6 +15,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.2.1" + app_review: + dependency: "direct main" + description: + name: app_review + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" archive: dependency: transitive description: @@ -396,6 +403,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + package_info: + dependency: transitive + description: + name: package_info + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.0+10" package_resolver: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index e5c489b..80fcc0a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,6 +23,7 @@ dependencies: flutter_cupertino_settings: ^0.2.0 url_launcher: ^5.2.2 in_app_purchase: ^0.2.2+2 + app_review: ^1.0.0 dev_dependencies: flutter_test: