Skip to content

Commit

Permalink
Added in_app_updater package
Browse files Browse the repository at this point in the history
  • Loading branch information
BrawlerXull committed Jul 4, 2024
1 parent 3d8aaa6 commit 1e8a64a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/app/modules/splash/controllers/splash_controller.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -17,6 +21,7 @@ class SplashController extends GetxController {
@override
void onInit() async {
super.onInit();
checkForUpdate();
initBaseDir().then((_) {
_checkProfiles();
profilesMap.value = _profiles.profilesMap();
Expand Down Expand Up @@ -100,4 +105,27 @@ class SplashController extends GetxController {
Get.toNamed(Routes.ONBOARDING);
}
}

Future<void> 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());
}
}
}
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1e8a64a

Please sign in to comment.