Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/inappreview #37

Merged
merged 4 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>nb</string>
<string>tr</string>
</array>
<key>CFBundleName</key>
<string>todo_app</string>
Expand Down
1 change: 1 addition & 0 deletions lib/Pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class HomePage extends StatefulWidget {

class _HomePageState extends State<HomePage> {
late int badgeValue;

@override
void initState() {
super.initState();
Expand Down
13 changes: 13 additions & 0 deletions lib/Pages/main_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:hexcolor/hexcolor.dart';
Expand All @@ -6,6 +8,7 @@ import 'package:provider/provider.dart';
import 'package:todo_app/Pages/profile_page.dart';
import 'package:todo_app/provider/todos_provider.dart';

import '../Review/review_service.dart';
import 'add_todo.dart';
import 'calendar_page.dart';
import 'dashboard_page.dart';
Expand All @@ -30,6 +33,7 @@ class _MainScreenState extends State<MainScreen> {
];

late int badgeValue;
final ReviewService _reviewService = ReviewService();

@override
void initState() {
Expand All @@ -45,6 +49,15 @@ class _MainScreenState extends State<MainScreen> {
DateTime.fromMillisecondsSinceEpoch(Todo.dateMilliseconds).year ==
DateTime.now().year;
}).length;

// App Review
Timer(const Duration(seconds: 2), () {
_reviewService.isSecondTimeOpen().then((secondOpen) {
if (secondOpen) {
_reviewService.showRating();
}
});
});
}

final PageStorageBucket bucket = PageStorageBucket();
Expand Down
64 changes: 64 additions & 0 deletions lib/Review/review_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'package:in_app_review/in_app_review.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:todo_app/provider/shared_prefences_helper.dart';

const KEY = 'FIRST_TIME_OPEN';
const COUNTER = 'OPEN_COUNTER';

class ReviewService {
late SharedPreferences _sharedPreferences;
late int openCounter;

final InAppReview _inAppReview = InAppReview.instance;
Future<bool> isSecondTimeOpen() async {
_sharedPreferences = await SharedPreferencesHelper.instance;
openCounter = _sharedPreferences.getInt(COUNTER) ?? 1;
try {
dynamic isSecondTime = _sharedPreferences.getBool(KEY);
if (openCounter == 3) {
_sharedPreferences.setBool(KEY, true);
openCounter += 1;
_sharedPreferences.setInt(COUNTER, openCounter);
return true;
} else if (openCounter == 15) {
_sharedPreferences.setBool(KEY, true);
openCounter += 1;
_sharedPreferences.setInt(COUNTER, openCounter);
return true;
} else if (openCounter == 150) {
_sharedPreferences.setBool(KEY, true);
openCounter += 1;
_sharedPreferences.setInt(COUNTER, openCounter);
return true;
} else if (openCounter == 400) {
_sharedPreferences.setBool(KEY, true);
openCounter += 1;
_sharedPreferences.setInt(COUNTER, openCounter);
return true;
} else {
_sharedPreferences.setBool(KEY, false);
openCounter += 1;
_sharedPreferences.setInt(COUNTER, openCounter);
return false;
}
} catch (e) {
return false;
}
}

Future<bool> showRating() async {
try {
final available = await _inAppReview.isAvailable();
if (available) {
_inAppReview.requestReview();
} else {
_inAppReview.openStoreListing(
appStoreId: 'com.yagizdokumaci.todomoon',
);
}
return true;
} catch (e) {
return false;
}
}
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies:
adaptive_dialog: ^1.4.0
easy_localization: ^3.0.0
flutter_app_badger: ^1.4.0
in_app_review: ^2.0.4

dev_dependencies:
flutter_test:
Expand Down