7/6/2
This commit is contained in:
67
lib/controller/functions/package_info.dart
Normal file
67
lib/controller/functions/package_info.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../../constant/info.dart';
|
||||
|
||||
Future<void> checkForUpdate(BuildContext context) async {
|
||||
final packageInfo = await PackageInfo.fromPlatform();
|
||||
final currentVersion = packageInfo.buildNumber;
|
||||
print('currentVersion is : $currentVersion');
|
||||
// Fetch the latest version from your server
|
||||
String latestVersion = await getPackageInfo();
|
||||
|
||||
if (latestVersion.isNotEmpty && latestVersion != currentVersion) {
|
||||
showUpdateDialog(context);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getPackageInfo() async {
|
||||
final response = await CRUD().get(link: AppLink.packageInfo, payload: {
|
||||
"platform": Platform.isAndroid ? 'android' : 'ios',
|
||||
"appName": AppInformation.appName,
|
||||
});
|
||||
|
||||
if (response != 'failure') {
|
||||
return jsonDecode(response)['message'][0]['version'];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
void showUpdateDialog(BuildContext context) {
|
||||
final String storeUrl = Platform.isAndroid
|
||||
? 'https://play.google.com/store/apps/details?id=com.mobileapp.store.ride'
|
||||
: 'https://apps.apple.com/ae/app/sefer/id6458734951';
|
||||
showCupertinoDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return CupertinoAlertDialog(
|
||||
title: Text('Update Available'.tr),
|
||||
content: Text(
|
||||
'A new version of the app is available. Please update to the latest version.'
|
||||
.tr,
|
||||
),
|
||||
actions: <Widget>[
|
||||
CupertinoDialogAction(
|
||||
child: Text('Update'.tr),
|
||||
onPressed: () async {
|
||||
if (await canLaunchUrl(Uri.parse(storeUrl))) {
|
||||
await launchUrl(Uri.parse(storeUrl));
|
||||
} else {
|
||||
print('Could not launch $storeUrl');
|
||||
}
|
||||
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:SEFER/views/auth/login_page.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../main.dart';
|
||||
@@ -15,10 +16,23 @@ class SplashScreenController extends GetxController
|
||||
late Animation<double> zoomInAnimation;
|
||||
late Animation<double> zoomOutAnimation;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
String packageInfo = '';
|
||||
late String version = '1.5.48';
|
||||
Future<void> checkForUpdate() async {
|
||||
final packageInfo = await PackageInfo.fromPlatform();
|
||||
final currentVersion = packageInfo.buildNumber;
|
||||
final version1 = packageInfo.version;
|
||||
print('currentVersion is : $currentVersion');
|
||||
// Fetch the latest version from your server
|
||||
version = version1.toString();
|
||||
print('version: ${version}');
|
||||
update();
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
checkForUpdate();
|
||||
animationController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(seconds: 4),
|
||||
|
||||
@@ -4,6 +4,13 @@ class MyTranslation extends Translations {
|
||||
@override
|
||||
Map<String, Map<String, String>> get keys => {
|
||||
"ar": {
|
||||
"Update Available": "تحديث متوفر",
|
||||
"A new version of the app is available. Please update to the latest version.":
|
||||
"تتوفر نسخة جديدة من التطبيق. يرجى التحديث إلى أحدث إصدار.",
|
||||
"We use location to get accurate and nearest passengers for you":
|
||||
"نستخدم الموقع للحصول على أقرب الركاب وأكثرهم دقة لك",
|
||||
"This ride is already applied by another driver.":
|
||||
"هذه الرحلة قام بقبولها سائق آخر بالفعل.",
|
||||
"We use your precise location to find the nearest available driver and provide accurate pickup and dropoff information. You can manage this in Settings.":
|
||||
"نستخدم موقعك الدقيق للعثور على أقرب سائق متاح وتوفير معلومات دقيقة عن مكان الاستلام والوجهة. يمكنك إدارة ذلك في الإعدادات.",
|
||||
'message From Driver': 'رسالة من السائق',
|
||||
@@ -733,7 +740,7 @@ iOS [https://getapp.cc/app/6458734951]
|
||||
"حَتَّى لَو مَفِيش كَارت SIM, مَاتِخَافْش! تُقَدِّر تِكَلِّم سِوَاقَك بِمَنْتَهَى البَسَاطَة عَن طَرِيق التَّطْبِيق بِتَاعِنَا. احنَا بِنَسْتَخْدِم تِكْنُولُوجْيَا حَدِيثَة عَشَان نِحافِظ عَلَى خَصُوصِيَّتَك",
|
||||
"This ride type allows changes, but the price may increase":
|
||||
"ده نوع الرحلات بيسمح بالتغيير بس السعر ممكن يزيد",
|
||||
"message From passenger": "رسالة من الراكب",
|
||||
|
||||
"Select one message": "اختر رسالة",
|
||||
"My location is correct. You can search for me using the navigation app":
|
||||
"المَكَان اللِّي أنا فِيه صَحِيح، مُمْكِن تُدَوِّر عَليَّا مِن خِلَال تَطْبِيق المُلاحَة",
|
||||
|
||||
Reference in New Issue
Block a user