add package info plus and getApkVersion function

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
rodolfobacuinjr 2023-01-24 09:36:51 +08:00
parent 2e13113cbe
commit 9aea59e5a2
8 changed files with 50 additions and 15 deletions

View File

@ -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<UserEvent, UserState> {
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(),

View File

@ -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<Object> get props => [versionInfo!];
}

View File

@ -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<Update> createState() => _UpdateState();
@ -58,16 +60,16 @@ class _UpdateState extends State<Update> {
color: Colors.black,
),
children: <TextSpan>[
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(

View File

@ -0,0 +1,13 @@
import 'package:package_info_plus/package_info_plus.dart';
Future<String> getAppVersion() async{
String appVersion;
try{
PackageInfo packageInfo = await PackageInfo.fromPlatform();
appVersion = packageInfo.version;
}catch(e){
throw(e.toString());
}
return appVersion;
}

View File

@ -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<UniT2Login> {
}, 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<UniT2Login> {
),
),
);
}else{
return Update(apkVersion: state.apkVersion!,currenVersion: state.versionInfo!.version!,);
}
});
}
if (state is UserError) {

View File

@ -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"))

View File

@ -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:

View File

@ -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: