From 9aea59e5a2ff984bbcde6155f9bc548da090678d Mon Sep 17 00:00:00 2001 From: rodolfobacuinjr Date: Tue, 24 Jan 2023 09:36:51 +0800 Subject: [PATCH] add package info plus and getApkVersion function --- unit2/lib/bloc/bloc/user_bloc.dart | 4 +++- unit2/lib/bloc/bloc/user_state.dart | 3 ++- .../unit2/login/components/update_required.dart | 12 +++++++----- .../unit2/login/functions/get_app_version.dart | 13 +++++++++++++ unit2/lib/screens/unit2/login/login.dart | 16 ++++++++-------- .../Flutter/GeneratedPluginRegistrant.swift | 2 ++ unit2/pubspec.lock | 14 ++++++++++++++ unit2/pubspec.yaml | 1 + 8 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 unit2/lib/screens/unit2/login/functions/get_app_version.dart diff --git a/unit2/lib/bloc/bloc/user_bloc.dart b/unit2/lib/bloc/bloc/user_bloc.dart index 00b0336..71dd9eb 100644 --- a/unit2/lib/bloc/bloc/user_bloc.dart +++ b/unit2/lib/bloc/bloc/user_bloc.dart @@ -3,6 +3,7 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:unit2/model/login_data/user_info/user_data.dart'; import 'package:unit2/model/login_data/version_info.dart'; +import 'package:unit2/screens/unit2/login/functions/get_app_version.dart'; import 'package:unit2/sevices/login_service/auth_service.dart'; import '../../utils/scanner.dart'; @@ -21,7 +22,8 @@ class UserBloc extends Bloc { emit(SplashScreen()); VersionInfo versionInfo = await AuthService.instance.getVersionInfo(); _versionInfo = versionInfo; - emit(VersionLoaded(versionInfo: _versionInfo)); + String apkVersion = await getAppVersion(); + emit(VersionLoaded(versionInfo: _versionInfo,apkVersion: apkVersion)); } catch (e) { emit(UserError( message: e.toString(), diff --git a/unit2/lib/bloc/bloc/user_state.dart b/unit2/lib/bloc/bloc/user_state.dart index 2c5b56b..551c9e2 100644 --- a/unit2/lib/bloc/bloc/user_state.dart +++ b/unit2/lib/bloc/bloc/user_state.dart @@ -37,7 +37,8 @@ class UserLoggedIn extends UserState{ class VersionLoaded extends UserState { final VersionInfo? versionInfo; - VersionLoaded({this.versionInfo}); + final String? apkVersion; + VersionLoaded({this.versionInfo,this.apkVersion}); @override List get props => [versionInfo!]; } diff --git a/unit2/lib/screens/unit2/login/components/update_required.dart b/unit2/lib/screens/unit2/login/components/update_required.dart index b1b33d5..e0ca1e9 100644 --- a/unit2/lib/screens/unit2/login/components/update_required.dart +++ b/unit2/lib/screens/unit2/login/components/update_required.dart @@ -6,7 +6,9 @@ import 'package:unit2/theme-data.dart/btn-style.dart'; import '../../../../theme-data.dart/colors.dart'; class Update extends StatefulWidget { - const Update({super.key}); + final String apkVersion; + final String currenVersion; + const Update({super.key,required this.apkVersion,required this.currenVersion}); @override State createState() => _UpdateState(); @@ -58,16 +60,16 @@ class _UpdateState extends State { color: Colors.black, ), children: [ - const TextSpan( - text: "mobileVersion", - style: TextStyle( + TextSpan( + text: widget.apkVersion, + style: const TextStyle( color: primary, fontWeight: FontWeight.bold)), const TextSpan( text: " did not match with the latest version ", style: TextStyle(color: Colors.black)), TextSpan( text: - "widget.currentVersion.data.version".toString(), + widget.currenVersion, style: const TextStyle( color: primary, fontWeight: FontWeight.bold)), const TextSpan( diff --git a/unit2/lib/screens/unit2/login/functions/get_app_version.dart b/unit2/lib/screens/unit2/login/functions/get_app_version.dart new file mode 100644 index 0000000..7ebd85b --- /dev/null +++ b/unit2/lib/screens/unit2/login/functions/get_app_version.dart @@ -0,0 +1,13 @@ +import 'package:package_info_plus/package_info_plus.dart'; + +Future getAppVersion() async{ + String appVersion; + try{ +PackageInfo packageInfo = await PackageInfo.fromPlatform(); +appVersion = packageInfo.version; + }catch(e){ + throw(e.toString()); + } + return appVersion; + +} \ No newline at end of file diff --git a/unit2/lib/screens/unit2/login/login.dart b/unit2/lib/screens/unit2/login/login.dart index 3149ade..e3e7e3a 100644 --- a/unit2/lib/screens/unit2/login/login.dart +++ b/unit2/lib/screens/unit2/login/login.dart @@ -4,17 +4,12 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart'; import 'package:fluttericon/font_awesome5_icons.dart'; -import 'package:fluttertoast/fluttertoast.dart'; import 'package:form_builder_validators/form_builder_validators.dart'; - import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:unit2/bloc/bloc/user_bloc.dart'; -import 'package:unit2/model/login_data/user_info/user_data.dart'; -import 'package:unit2/screens/unit2/login/qr_login.dart'; +import 'package:unit2/screens/unit2/login/components/update_required.dart'; import 'package:unit2/utils/text_container.dart'; import 'package:unit2/widgets/error_state.dart'; - -import '../../../utils/scanner.dart'; import '../../../widgets/splash_screen.dart'; import '../../../widgets/wave.dart'; import '../../../utils/global.dart'; @@ -53,10 +48,11 @@ class _UniT2LoginState extends State { }, builder: (context, state) { if (state is VersionLoaded) { return Builder(builder: (context) { - return SizedBox( + if(state.versionInfo!.version == state.apkVersion){ + return SizedBox( child: SingleChildScrollView( child: Stack( - alignment: Alignment.center, + alignment: Alignment.center, children: [ Positioned( bottom: 0, @@ -273,6 +269,10 @@ class _UniT2LoginState extends State { ), ), ); + }else{ + return Update(apkVersion: state.apkVersion!,currenVersion: state.versionInfo!.version!,); + } + }); } if (state is UserError) { diff --git a/unit2/macos/Flutter/GeneratedPluginRegistrant.swift b/unit2/macos/Flutter/GeneratedPluginRegistrant.swift index e9cf192..46d0540 100644 --- a/unit2/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/unit2/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,11 +5,13 @@ import FlutterMacOS import Foundation +import package_info_plus import path_provider_macos import shared_preferences_macos import sqflite func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) diff --git a/unit2/pubspec.lock b/unit2/pubspec.lock index f387d29..c278856 100644 --- a/unit2/pubspec.lock +++ b/unit2/pubspec.lock @@ -406,6 +406,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.2" + package_info_plus: + dependency: "direct main" + description: + name: package_info_plus + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" + package_info_plus_platform_interface: + dependency: transitive + description: + name: package_info_plus_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" path: dependency: transitive description: diff --git a/unit2/pubspec.yaml b/unit2/pubspec.yaml index 3d40e54..720e69c 100644 --- a/unit2/pubspec.yaml +++ b/unit2/pubspec.yaml @@ -60,6 +60,7 @@ dependencies: system_info2: ^2.0.4 flutter_bloc: ^8.0.0 equatable: ^2.0.5 + package_info_plus: ^3.0.2 dev_dependencies: flutter_test: