feat : app version check in splash
This commit is contained in:
@@ -2,6 +2,8 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:rasadyar_app/data/model/app_info_model.dart';
|
||||
import 'package:rasadyar_app/presentation/routes/app_pages.dart';
|
||||
import 'package:rasadyar_auth/data/services/token_storage_service.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
@@ -15,8 +17,9 @@ class SplashLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
RxDouble percent = 0.0.obs;
|
||||
final RxnString _updateFilePath = RxnString();
|
||||
final platform = MethodChannel('apk_installer');
|
||||
|
||||
final Dio _dio = Dio();
|
||||
var tokenService = Get.find<TokenStorageService>();
|
||||
AppInfoModel? appInfoModel;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -146,26 +149,47 @@ class SplashLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
|
||||
hasUpdated.value = !hasUpdated.value;
|
||||
Future.delayed(const Duration(milliseconds: 250), () async {
|
||||
try {
|
||||
final isUpdateNeeded = await checkVersion();
|
||||
if (isUpdateNeeded) return;
|
||||
|
||||
//TODO
|
||||
/*Future.delayed(const Duration(seconds: 1), () async {
|
||||
var module = tokenService.appModule.value;
|
||||
Get.offAndToNamed(getTargetPage(module));
|
||||
});*/
|
||||
final module = tokenService.appModule.value;
|
||||
final target = getTargetPage(module);
|
||||
Get.offAndToNamed(target);
|
||||
} catch (e, st) {
|
||||
debugPrint("onReady error: $e\n$st");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
rotateController.dispose();
|
||||
scaleController.dispose();
|
||||
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
Future<bool> checkVersion() async {
|
||||
try {
|
||||
final info = await PackageInfo.fromPlatform();
|
||||
int version = info.version.versionNumber;
|
||||
var res = await _dio.get("https://rsibackend.rasadyaar.ir/app/apk-info/");
|
||||
|
||||
appInfoModel = AppInfoModel.fromJson(res.data);
|
||||
|
||||
if ((appInfoModel?.info.version.versionNumber ?? 0) > version) {
|
||||
hasUpdated.value = !hasUpdated.value;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fileDownload() async {
|
||||
onUpdateDownload.value = true;
|
||||
Dio dio = Dio();
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final filePath = "${dir.path}/app-release.apk";
|
||||
final file = File(filePath);
|
||||
@@ -178,8 +202,8 @@ class SplashLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
|
||||
while (attempts < retryCount && !success) {
|
||||
try {
|
||||
await dio.download(
|
||||
'https://everestacademy.ir/app/app-release.apk',
|
||||
await _dio.download(
|
||||
appInfoModel?.downloadLink ?? '',
|
||||
filePath,
|
||||
onReceiveProgress: (count, total) {
|
||||
if (total != -1 && total > 0) {
|
||||
|
||||
Reference in New Issue
Block a user