From 01d454dccec7835b65d0fe718b0f61b8a3c92130 Mon Sep 17 00:00:00 2001 From: PGAN-MIS Date: Thu, 7 Sep 2023 13:54:47 +0800 Subject: [PATCH] fixed retain username and password in error login state --- lib/bloc/user/user_bloc.dart | 19 ++++++++++++------- lib/bloc/user/user_event.dart | 6 ++++-- lib/screens/profile/profile.dart | 2 +- lib/screens/unit2/basic-info/basic-info.dart | 19 +++++++++---------- lib/screens/unit2/login/login.dart | 10 +++++----- lib/sevices/roles/pass_check_services.dart | 6 ------ lib/utils/app_router.dart | 2 +- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/bloc/user/user_bloc.dart b/lib/bloc/user/user_bloc.dart index 3d0e250..3c80c9c 100644 --- a/lib/bloc/user/user_bloc.dart +++ b/lib/bloc/user/user_bloc.dart @@ -15,13 +15,14 @@ import '../../utils/scanner.dart'; import '../../utils/text_container.dart'; part 'user_event.dart'; part 'user_state.dart'; - class UserBloc extends Bloc { UserData? _userData; VersionInfo? _versionInfo; String? _apkVersion; bool save = false; String? uuid; + String? username; + String? password; List establishmentPointPersonAssignedAreas = []; UserBloc() : super(UserInitial()) { //// this event is called when opening the app to check if @@ -37,8 +38,8 @@ class UserBloc extends Bloc { String apkVersion = await getAppVersion(); _apkVersion = apkVersion; final String? saved = CREDENTIALS?.get('saved'); - final String? username = CREDENTIALS?.get('username'); - final String? password = CREDENTIALS?.get('password'); + username = CREDENTIALS?.get('username'); + password = CREDENTIALS?.get('password'); if (saved != null) { save = true; add(UserLogin(username: username, password: password)); @@ -46,8 +47,8 @@ class UserBloc extends Bloc { emit(VersionLoaded( versionInfo: _versionInfo, apkVersion: _apkVersion, - username: null, - password: null)); + username: event.username, + password: event.password)); } } catch (e) { emit(UserError( @@ -57,14 +58,18 @@ class UserBloc extends Bloc { }); ////Loading the current version of the app on((event, emit) { + username = event.username; + password = event.password; emit(VersionLoaded( versionInfo: _versionInfo, apkVersion: _apkVersion, - username: event.username, - password: event.password)); + username: username, + password: password)); }); ////userlogin on((event, emit) async { + username = event.username; + password = event.password; try { Map response = await AuthService.instance .webLogin(username: event.username, password: event.password); diff --git a/lib/bloc/user/user_event.dart b/lib/bloc/user/user_event.dart index 002410e..be22335 100644 --- a/lib/bloc/user/user_event.dart +++ b/lib/bloc/user/user_event.dart @@ -6,9 +6,11 @@ abstract class UserEvent extends Equatable { } class GetApkVersion extends UserEvent { - GetApkVersion(); + final String username; + final String password; + GetApkVersion({required this.password, required this.username}); @override - List get props => []; + List get props => [username,password]; } class UserLogin extends UserEvent { diff --git a/lib/screens/profile/profile.dart b/lib/screens/profile/profile.dart index ec1a721..9037fee 100644 --- a/lib/screens/profile/profile.dart +++ b/lib/screens/profile/profile.dart @@ -70,7 +70,7 @@ class ProfileInfo extends StatelessWidget { profileId = state.userData!.user!.login!.user!.profileId; token = state.userData!.user!.login!.token!; profile = state.userData!.employeeInfo!.profile!; - + return BlocConsumer( listener: ( context, diff --git a/lib/screens/unit2/basic-info/basic-info.dart b/lib/screens/unit2/basic-info/basic-info.dart index 9b1544b..85d6213 100644 --- a/lib/screens/unit2/basic-info/basic-info.dart +++ b/lib/screens/unit2/basic-info/basic-info.dart @@ -58,8 +58,8 @@ class BasicInfo extends StatelessWidget { width: 160, height: 160, decoration: BoxDecoration( - border: - Border.all(color: Colors.black26, width: 3), + border: Border.all( + color: Colors.black26, width: 3), shape: BoxShape.circle, image: DecorationImage( image: imageProvider, @@ -70,19 +70,18 @@ class BasicInfo extends StatelessWidget { const CircularProgressIndicator(), errorWidget: (context, url, error) => Container( - width: 160, + width: 160, height: 160, - decoration: BoxDecoration( - border: - Border.all(color: Colors.white, width: 3), + decoration: BoxDecoration( + border: Border.all( + color: Colors.white, width: 3), shape: BoxShape.circle, - ), - child: SvgPicture.asset( - 'assets/svgs/male.svg', + child: SvgPicture.asset( + 'assets/svgs/male.svg', + ), ), ), - ), ], ), ), diff --git a/lib/screens/unit2/login/login.dart b/lib/screens/unit2/login/login.dart index d828c89..a6f51ac 100644 --- a/lib/screens/unit2/login/login.dart +++ b/lib/screens/unit2/login/login.dart @@ -46,8 +46,9 @@ class _UniT2LoginState extends State { backgroundColor: Colors.black87, indicatorWidget: const SpinKitFadingCircle(color: Colors.white), child: BlocConsumer(listener: (context, state) { - print(state); - if (state is UserLoggedIn || state is UuidLoaded || state is LoginErrorState) { + if (state is UserLoggedIn || + state is UuidLoaded || + state is LoginErrorState) { final progress = ProgressHUD.of(context); progress!.dismiss(); } @@ -94,7 +95,6 @@ class _UniT2LoginState extends State { })); } }, builder: (context, state) { - print(state); if (state is VersionLoaded) { return Builder(builder: (context) { if (state.versionInfo!.version != state.apkVersion) { @@ -355,7 +355,7 @@ class _UniT2LoginState extends State { onpressed: () { BlocProvider.of( NavigationService.navigatorKey.currentContext!) - .add(GetApkVersion()); + .add(LoadVersion(username: username, password: password)); return MaterialPageRoute(builder: (_) { return const UniT2Login(); }); @@ -374,7 +374,7 @@ class _UniT2LoginState extends State { onpressed: () { BlocProvider.of( NavigationService.navigatorKey.currentContext!) - .add(GetApkVersion()); + .add(LoadVersion(username: username, password: password)); return MaterialPageRoute(builder: (_) { return const UniT2Login(); }); diff --git a/lib/sevices/roles/pass_check_services.dart b/lib/sevices/roles/pass_check_services.dart index c74704f..b0a66e4 100644 --- a/lib/sevices/roles/pass_check_services.dart +++ b/lib/sevices/roles/pass_check_services.dart @@ -184,7 +184,6 @@ class PassCheckServices { if (otherInputs) { if (roleid == 41 || roleid == 13 || roleid == 17 || roleid == 22) { if (io == "i") { - print("1"); body = { "station_id": stationId, "temperature": temp, @@ -193,7 +192,6 @@ class PassCheckServices { "io": io }; } else { - print("2"); body = { "station_id": stationId, "destination": destination, @@ -203,7 +201,6 @@ class PassCheckServices { }; } } else { - print("3"); if (io == "i") { body = { "cp_id": cpId, @@ -213,7 +210,6 @@ class PassCheckServices { "io": io }; } else { - print("4"); body = { "cp_id": cpId, "destination": destination, @@ -224,7 +220,6 @@ class PassCheckServices { } } } else { - print("5"); if (roleid == 41 || roleid == 13 || roleid == 17 || roleid == 22) { body = { "station_id": stationId, @@ -233,7 +228,6 @@ class PassCheckServices { "io": io }; } else { - print("6"); body = { "cp_id": cpId, "temperature": temp, diff --git a/lib/utils/app_router.dart b/lib/utils/app_router.dart index 8b11ea5..f2c9b3b 100644 --- a/lib/utils/app_router.dart +++ b/lib/utils/app_router.dart @@ -27,7 +27,7 @@ class AppRouter { case '/': BlocProvider.of( NavigationService.navigatorKey.currentContext!) - .add(GetApkVersion()); + .add(GetApkVersion(username: "",password: "")); return MaterialPageRoute(builder: (_) { return const UniT2Login(); });