From efa8c37a88aea89446acaf0f7fab77dcfb9032f8 Mon Sep 17 00:00:00 2001 From: Felipe Date: Sat, 28 Oct 2023 16:04:44 -0500 Subject: [PATCH] version --- lib/src/models/setting_model.dart | 9 +++ lib/src/screens/service.dart | 75 +++++++++++++++++++ macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 16 ++++ pubspec.yaml | 3 +- 5 files changed, 104 insertions(+), 1 deletion(-) diff --git a/lib/src/models/setting_model.dart b/lib/src/models/setting_model.dart index 86b11f7..5d1a002 100644 --- a/lib/src/models/setting_model.dart +++ b/lib/src/models/setting_model.dart @@ -67,4 +67,13 @@ class SettingModel { return SettingModel(false, false, '', '', '', '', '', '', '', '', ''); } } + + @override + String toString() { + return 'SettingModel { domicilios: $domicilios, tarifas: $tarifas, ' + 'titulo: $titulo, parrafo: $parrafo, numero: $numero, ' + 'email: $email, dias: $dias, horas: $horas, ' + 'version: $version, politicasPrivacidad: $proliticasPrivacidad, ' + 'terminosCondiciones: $terminosCondiciones }'; + } } diff --git a/lib/src/screens/service.dart b/lib/src/screens/service.dart index 56222d7..f955299 100644 --- a/lib/src/screens/service.dart +++ b/lib/src/screens/service.dart @@ -13,6 +13,7 @@ import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:prosappco/src/authentication/authentication_repository.dart'; import 'package:prosappco/src/components/drawer_menu.dart'; import 'package:prosappco/src/models/event_model.dart'; +import 'package:prosappco/src/models/setting_model.dart'; import 'package:prosappco/src/models/user_model.dart'; import 'package:prosappco/src/screens/professional.dart'; import 'package:intl/intl.dart'; @@ -23,6 +24,8 @@ import 'package:prosappco/src/screens/service_type.dart'; import 'package:prosappco/src/screens/ubicacion.dart'; import 'package:http/http.dart' as http; import 'package:prosappco/src/components/network_utility.dart'; +import 'package:package_info_plus/package_info_plus.dart'; +import 'package:url_launcher/url_launcher.dart'; class ServiceScreen extends StatefulWidget { const ServiceScreen({super.key}); @@ -32,6 +35,10 @@ class ServiceScreen extends StatefulWidget { } class _ServiceScreenState extends State { + late String appVersion; + final Uri _url = Uri.parse( + 'https://play.google.com/store/apps/details?id=com.prosapp.prosapp'); + void _saveToken() async { FirebaseMessaging messaging = FirebaseMessaging.instance; @@ -239,10 +246,78 @@ class _ServiceScreenState extends State { }); } + Future _getAppVersion() async { + PackageInfo packageInfo = await PackageInfo.fromPlatform(); + String version = packageInfo.version; + + setState(() { + appVersion = version; + print('Version de app $appVersion - version de firebase $settings'); + }); + + if (settings != null) { + _checkForUpdate(settings); + } + } + + void _checkForUpdate(String? settings) { + if (appVersion != settings) { + showDialog( + context: context, + builder: (context) { + return WillPopScope( + onWillPop: () async { + return false; + }, + child: Center( + child: AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16.0), + ), + title: const Text( + "Debes Actualizar la Aplicación", + style: TextStyle(fontWeight: FontWeight.bold), + ), + content: const Text( + "Tienes una versión desactualizada de nuestra aplicación. Te recomendamos actualizarla para disfrutar de las últimas características y mejoras.", + ), + actions: [ + TextButton( + child: const Text( + "Actualizar", + style: + TextStyle(fontWeight: FontWeight.w600, fontSize: 20), + ), + onPressed: () { + launchUrl(_url); + }, + ), + ], + ), + ), + ); + }, + ); + } + } + + String? settings; + @override void initState() { super.initState(); + _getAppVersion(); + + if (settings == null) { + SettingModel.getSettings().then( + (SettingModel value) => setState(() { + settings = value.version; + _getAppVersion(); // Llama a _getAppVersion una vez que settings se haya cargado + }), + ); + } + if (_ciudad == '...') { AuthenticationRepository.instance .getCity(uid.toString()) diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 3584be3..fe2e8f9 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -15,6 +15,7 @@ import firebase_messaging import firebase_storage import flutter_local_notifications import geolocator_apple +import package_info_plus import path_provider_foundation import shared_preferences_foundation import url_launcher_macos @@ -30,6 +31,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTFirebaseStoragePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseStoragePlugin")) FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin")) + FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) diff --git a/pubspec.lock b/pubspec.lock index 6fa6f4f..dbf9985 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -872,6 +872,22 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.0" + package_info_plus: + dependency: "direct main" + description: + name: package_info_plus + sha256: "7e76fad405b3e4016cd39d08f455a4eb5199723cf594cd1b8916d47140d93017" + url: "https://pub.dev" + source: hosted + version: "4.2.0" + package_info_plus_platform_interface: + dependency: transitive + description: + name: package_info_plus_platform_interface + sha256: "9bc8ba46813a4cc42c66ab781470711781940780fd8beddd0c3da62506d3a6c6" + url: "https://pub.dev" + source: hosted + version: "2.0.1" page_transition: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 0952bc4..d0d2e04 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,7 +42,8 @@ dependencies: firebase_core: ^2.13.1 file_picker: ^5.3.2 google_sign_in: ^6.1.4 - provider: + provider: ^6.0.5 + package_info_plus: ^4.2.0 get: font_awesome_flutter: ^10.4.0 flutter_otp_text_field: