diff --git a/lib/app/modules/splash/controllers/splash_controller.dart b/lib/app/modules/splash/controllers/splash_controller.dart index 05d7d5a0..7b80d05b 100644 --- a/lib/app/modules/splash/controllers/splash_controller.dart +++ b/lib/app/modules/splash/controllers/splash_controller.dart @@ -1,6 +1,10 @@ +// ignore_for_file: body_might_complete_normally_catch_error + import 'dart:io'; +import 'package:flutter/foundation.dart'; import 'package:get/get.dart'; +import 'package:in_app_update/in_app_update.dart'; import 'package:path_provider/path_provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:taskwarrior/app/models/storage.dart'; @@ -17,6 +21,7 @@ class SplashController extends GetxController { @override void onInit() async { super.onInit(); + checkForUpdate(); initBaseDir().then((_) { _checkProfiles(); profilesMap.value = _profiles.profilesMap(); @@ -100,4 +105,27 @@ class SplashController extends GetxController { Get.toNamed(Routes.ONBOARDING); } } + + Future checkForUpdate() async { + try { + AppUpdateInfo updateInfo = await InAppUpdate.checkForUpdate(); + if (updateInfo.updateAvailability == UpdateAvailability.updateAvailable) { + if (updateInfo.immediateUpdateAllowed) { + InAppUpdate.performImmediateUpdate().catchError((e) { + debugPrint(e.toString()); + }); + } else if (updateInfo.flexibleUpdateAllowed) { + InAppUpdate.startFlexibleUpdate().then((_) { + InAppUpdate.completeFlexibleUpdate().catchError((e) { + debugPrint(e.toString()); + }); + }).catchError((e) { + debugPrint(e.toString()); + }); + } + } + } catch (e) { + debugPrint(e.toString()); + } + } } diff --git a/pubspec.lock b/pubspec.lock index c8a884d7..b6a07880 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -640,6 +640,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.6.0" + in_app_update: + dependency: "direct main" + description: + name: in_app_update + sha256: "489572accaa55b51518b2d64676ca8c3c6d4c989fa53cf718001882237691a3c" + url: "https://pub.dev" + source: hosted + version: "4.2.3" intl: dependency: "direct main" description: