Skip to content

Commit 1e8a64a

Browse files
committed
Added in_app_updater package
1 parent 3d8aaa6 commit 1e8a64a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/app/modules/splash/controllers/splash_controller.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
// ignore_for_file: body_might_complete_normally_catch_error
2+
13
import 'dart:io';
24

5+
import 'package:flutter/foundation.dart';
36
import 'package:get/get.dart';
7+
import 'package:in_app_update/in_app_update.dart';
48
import 'package:path_provider/path_provider.dart';
59
import 'package:shared_preferences/shared_preferences.dart';
610
import 'package:taskwarrior/app/models/storage.dart';
@@ -17,6 +21,7 @@ class SplashController extends GetxController {
1721
@override
1822
void onInit() async {
1923
super.onInit();
24+
checkForUpdate();
2025
initBaseDir().then((_) {
2126
_checkProfiles();
2227
profilesMap.value = _profiles.profilesMap();
@@ -100,4 +105,27 @@ class SplashController extends GetxController {
100105
Get.toNamed(Routes.ONBOARDING);
101106
}
102107
}
108+
109+
Future<void> checkForUpdate() async {
110+
try {
111+
AppUpdateInfo updateInfo = await InAppUpdate.checkForUpdate();
112+
if (updateInfo.updateAvailability == UpdateAvailability.updateAvailable) {
113+
if (updateInfo.immediateUpdateAllowed) {
114+
InAppUpdate.performImmediateUpdate().catchError((e) {
115+
debugPrint(e.toString());
116+
});
117+
} else if (updateInfo.flexibleUpdateAllowed) {
118+
InAppUpdate.startFlexibleUpdate().then((_) {
119+
InAppUpdate.completeFlexibleUpdate().catchError((e) {
120+
debugPrint(e.toString());
121+
});
122+
}).catchError((e) {
123+
debugPrint(e.toString());
124+
});
125+
}
126+
}
127+
} catch (e) {
128+
debugPrint(e.toString());
129+
}
130+
}
103131
}

pubspec.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,14 @@ packages:
640640
url: "https://pub.dev"
641641
source: hosted
642642
version: "4.6.0"
643+
in_app_update:
644+
dependency: "direct main"
645+
description:
646+
name: in_app_update
647+
sha256: "489572accaa55b51518b2d64676ca8c3c6d4c989fa53cf718001882237691a3c"
648+
url: "https://pub.dev"
649+
source: hosted
650+
version: "4.2.3"
643651
intl:
644652
dependency: "direct main"
645653
description:

0 commit comments

Comments
 (0)