81 lines
2.5 KiB
Dart
81 lines
2.5 KiB
Dart
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:get/get.dart';
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
import '../../constant/box_name.dart';
|
|
import '../../constant/info.dart';
|
|
import '../../main.dart';
|
|
|
|
Future<void> checkForUpdate(BuildContext context) async {
|
|
final packageInfo = await PackageInfo.fromPlatform();
|
|
final currentVersion = packageInfo.buildNumber;
|
|
final version = packageInfo.version;
|
|
print('currentVersion is : $currentVersion');
|
|
// Fetch the latest version from your server
|
|
String latestVersion = box.read(BoxName.package);
|
|
box.write(BoxName.packagInfo, version);
|
|
|
|
if (latestVersion.isNotEmpty && latestVersion != currentVersion) {
|
|
showUpdateDialog(context);
|
|
}
|
|
}
|
|
|
|
checkForBounusInvitation() {
|
|
if (box.read(BoxName.inviteCode) != null) {}
|
|
}
|
|
|
|
// 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();
|
|
},
|
|
),
|
|
CupertinoDialogAction(
|
|
child: Text('Cancel'.tr),
|
|
onPressed: () async {
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|