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

Added in_app_updater package #354

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion lib/app/modules/splash/controllers/splash_controller.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// ignore_for_file: depend_on_referenced_packages
// ignore_for_file: body_might_complete_normally_catch_error, depend_on_referenced_packages

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 @@ -19,6 +21,7 @@ class SplashController extends GetxController {
@override
void onInit() async {
super.onInit();
await checkForUpdate();
initBaseDir().then((_) {
_checkProfiles();
profilesMap.value = _profiles.profilesMap();
Expand Down Expand Up @@ -102,4 +105,27 @@ class SplashController extends GetxController {
Get.offNamed(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());
}
}
}
Loading