|
| 1 | +import "package:flutter/material.dart"; |
| 2 | +import "package:mujslcm/pages/redirects.dart"; |
| 3 | +import "package:package_info_plus/package_info_plus.dart"; |
| 4 | +import 'package:url_launcher/url_launcher.dart'; |
| 5 | +import "util.dart"; |
| 6 | + |
| 7 | +Future<String> getAppVersion() async { |
| 8 | + PackageInfo packageInfo = await PackageInfo.fromPlatform(); |
| 9 | + return packageInfo.version; |
| 10 | +} |
| 11 | + |
| 12 | +Future<void> _launchURL(String url) async { |
| 13 | + final uri = Uri.parse(url); |
| 14 | + if (await canLaunchUrl(uri)) { |
| 15 | + await launchUrl(uri, mode: LaunchMode.externalApplication); |
| 16 | + } else { |
| 17 | + throw 'Could not launch $url'; |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +Future<Object?> check_update(context) async { |
| 22 | + final appversion = await getAppVersion(); |
| 23 | + final response = await get(repolink, headers); |
| 24 | + if ("v$appversion" != response.data["tag_name"]) { |
| 25 | + return showDialog( |
| 26 | + context: context, |
| 27 | + builder: (BuildContext context) => Dialog( |
| 28 | + backgroundColor: const Color(0xFF232531), |
| 29 | + child: Padding( |
| 30 | + padding: const EdgeInsets.all(8), |
| 31 | + child: Column( |
| 32 | + mainAxisSize: MainAxisSize.min, |
| 33 | + mainAxisAlignment: MainAxisAlignment.center, |
| 34 | + children: <Widget>[ |
| 35 | + const Padding( |
| 36 | + padding: EdgeInsets.all(8.0), |
| 37 | + child: Text( |
| 38 | + "New Update", |
| 39 | + style: TextStyle(color: Colors.white, fontSize: 20), |
| 40 | + ), |
| 41 | + ), |
| 42 | + const SizedBox(height: 10), |
| 43 | + Padding( |
| 44 | + padding: const EdgeInsets.all(8.0), |
| 45 | + child: Text( |
| 46 | + "Version ${response.data["tag_name"]} is out check out", |
| 47 | + style: |
| 48 | + const TextStyle(color: Colors.white, fontSize: 15), |
| 49 | + ), |
| 50 | + ), |
| 51 | + const SizedBox(height: 15), |
| 52 | + Align( |
| 53 | + alignment: Alignment.bottomRight, |
| 54 | + child: TextButton( |
| 55 | + onPressed: () { |
| 56 | + _launchURL( |
| 57 | + "https://github.com/DK10WS/SLCM_APP/releases/"); |
| 58 | + }, |
| 59 | + child: const Text('Download', |
| 60 | + style: TextStyle( |
| 61 | + color: Color(0xFFD5E7B5), fontSize: 15)), |
| 62 | + ), |
| 63 | + ) |
| 64 | + ], |
| 65 | + ), |
| 66 | + ), |
| 67 | + )); |
| 68 | + } |
| 69 | + return null; |
| 70 | +} |
0 commit comments