fixed retain username and password in error login state
parent
8e52b7dcea
commit
01d454dcce
|
@ -15,13 +15,14 @@ import '../../utils/scanner.dart';
|
||||||
import '../../utils/text_container.dart';
|
import '../../utils/text_container.dart';
|
||||||
part 'user_event.dart';
|
part 'user_event.dart';
|
||||||
part 'user_state.dart';
|
part 'user_state.dart';
|
||||||
|
|
||||||
class UserBloc extends Bloc<UserEvent, UserState> {
|
class UserBloc extends Bloc<UserEvent, UserState> {
|
||||||
UserData? _userData;
|
UserData? _userData;
|
||||||
VersionInfo? _versionInfo;
|
VersionInfo? _versionInfo;
|
||||||
String? _apkVersion;
|
String? _apkVersion;
|
||||||
bool save = false;
|
bool save = false;
|
||||||
String? uuid;
|
String? uuid;
|
||||||
|
String? username;
|
||||||
|
String? password;
|
||||||
List<AssignedArea> establishmentPointPersonAssignedAreas = [];
|
List<AssignedArea> establishmentPointPersonAssignedAreas = [];
|
||||||
UserBloc() : super(UserInitial()) {
|
UserBloc() : super(UserInitial()) {
|
||||||
//// this event is called when opening the app to check if
|
//// this event is called when opening the app to check if
|
||||||
|
@ -37,8 +38,8 @@ class UserBloc extends Bloc<UserEvent, UserState> {
|
||||||
String apkVersion = await getAppVersion();
|
String apkVersion = await getAppVersion();
|
||||||
_apkVersion = apkVersion;
|
_apkVersion = apkVersion;
|
||||||
final String? saved = CREDENTIALS?.get('saved');
|
final String? saved = CREDENTIALS?.get('saved');
|
||||||
final String? username = CREDENTIALS?.get('username');
|
username = CREDENTIALS?.get('username');
|
||||||
final String? password = CREDENTIALS?.get('password');
|
password = CREDENTIALS?.get('password');
|
||||||
if (saved != null) {
|
if (saved != null) {
|
||||||
save = true;
|
save = true;
|
||||||
add(UserLogin(username: username, password: password));
|
add(UserLogin(username: username, password: password));
|
||||||
|
@ -46,8 +47,8 @@ class UserBloc extends Bloc<UserEvent, UserState> {
|
||||||
emit(VersionLoaded(
|
emit(VersionLoaded(
|
||||||
versionInfo: _versionInfo,
|
versionInfo: _versionInfo,
|
||||||
apkVersion: _apkVersion,
|
apkVersion: _apkVersion,
|
||||||
username: null,
|
username: event.username,
|
||||||
password: null));
|
password: event.password));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(UserError(
|
emit(UserError(
|
||||||
|
@ -57,14 +58,18 @@ class UserBloc extends Bloc<UserEvent, UserState> {
|
||||||
});
|
});
|
||||||
////Loading the current version of the app
|
////Loading the current version of the app
|
||||||
on<LoadVersion>((event, emit) {
|
on<LoadVersion>((event, emit) {
|
||||||
|
username = event.username;
|
||||||
|
password = event.password;
|
||||||
emit(VersionLoaded(
|
emit(VersionLoaded(
|
||||||
versionInfo: _versionInfo,
|
versionInfo: _versionInfo,
|
||||||
apkVersion: _apkVersion,
|
apkVersion: _apkVersion,
|
||||||
username: event.username,
|
username: username,
|
||||||
password: event.password));
|
password: password));
|
||||||
});
|
});
|
||||||
////userlogin
|
////userlogin
|
||||||
on<UserLogin>((event, emit) async {
|
on<UserLogin>((event, emit) async {
|
||||||
|
username = event.username;
|
||||||
|
password = event.password;
|
||||||
try {
|
try {
|
||||||
Map<dynamic, dynamic> response = await AuthService.instance
|
Map<dynamic, dynamic> response = await AuthService.instance
|
||||||
.webLogin(username: event.username, password: event.password);
|
.webLogin(username: event.username, password: event.password);
|
||||||
|
|
|
@ -6,9 +6,11 @@ abstract class UserEvent extends Equatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
class GetApkVersion extends UserEvent {
|
class GetApkVersion extends UserEvent {
|
||||||
GetApkVersion();
|
final String username;
|
||||||
|
final String password;
|
||||||
|
GetApkVersion({required this.password, required this.username});
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [];
|
List<Object> get props => [username,password];
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserLogin extends UserEvent {
|
class UserLogin extends UserEvent {
|
||||||
|
|
|
@ -58,8 +58,8 @@ class BasicInfo extends StatelessWidget {
|
||||||
width: 160,
|
width: 160,
|
||||||
height: 160,
|
height: 160,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border:
|
border: Border.all(
|
||||||
Border.all(color: Colors.black26, width: 3),
|
color: Colors.black26, width: 3),
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
image: DecorationImage(
|
image: DecorationImage(
|
||||||
image: imageProvider,
|
image: imageProvider,
|
||||||
|
@ -73,10 +73,9 @@ class BasicInfo extends StatelessWidget {
|
||||||
width: 160,
|
width: 160,
|
||||||
height: 160,
|
height: 160,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border:
|
border: Border.all(
|
||||||
Border.all(color: Colors.white, width: 3),
|
color: Colors.white, width: 3),
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
|
|
||||||
),
|
),
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
'assets/svgs/male.svg',
|
'assets/svgs/male.svg',
|
||||||
|
|
|
@ -46,8 +46,9 @@ class _UniT2LoginState extends State<UniT2Login> {
|
||||||
backgroundColor: Colors.black87,
|
backgroundColor: Colors.black87,
|
||||||
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
|
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
|
||||||
child: BlocConsumer<UserBloc, UserState>(listener: (context, state) {
|
child: BlocConsumer<UserBloc, UserState>(listener: (context, state) {
|
||||||
print(state);
|
if (state is UserLoggedIn ||
|
||||||
if (state is UserLoggedIn || state is UuidLoaded || state is LoginErrorState) {
|
state is UuidLoaded ||
|
||||||
|
state is LoginErrorState) {
|
||||||
final progress = ProgressHUD.of(context);
|
final progress = ProgressHUD.of(context);
|
||||||
progress!.dismiss();
|
progress!.dismiss();
|
||||||
}
|
}
|
||||||
|
@ -94,7 +95,6 @@ class _UniT2LoginState extends State<UniT2Login> {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}, builder: (context, state) {
|
}, builder: (context, state) {
|
||||||
print(state);
|
|
||||||
if (state is VersionLoaded) {
|
if (state is VersionLoaded) {
|
||||||
return Builder(builder: (context) {
|
return Builder(builder: (context) {
|
||||||
if (state.versionInfo!.version != state.apkVersion) {
|
if (state.versionInfo!.version != state.apkVersion) {
|
||||||
|
@ -355,7 +355,7 @@ class _UniT2LoginState extends State<UniT2Login> {
|
||||||
onpressed: () {
|
onpressed: () {
|
||||||
BlocProvider.of<UserBloc>(
|
BlocProvider.of<UserBloc>(
|
||||||
NavigationService.navigatorKey.currentContext!)
|
NavigationService.navigatorKey.currentContext!)
|
||||||
.add(GetApkVersion());
|
.add(LoadVersion(username: username, password: password));
|
||||||
return MaterialPageRoute(builder: (_) {
|
return MaterialPageRoute(builder: (_) {
|
||||||
return const UniT2Login();
|
return const UniT2Login();
|
||||||
});
|
});
|
||||||
|
@ -374,7 +374,7 @@ class _UniT2LoginState extends State<UniT2Login> {
|
||||||
onpressed: () {
|
onpressed: () {
|
||||||
BlocProvider.of<UserBloc>(
|
BlocProvider.of<UserBloc>(
|
||||||
NavigationService.navigatorKey.currentContext!)
|
NavigationService.navigatorKey.currentContext!)
|
||||||
.add(GetApkVersion());
|
.add(LoadVersion(username: username, password: password));
|
||||||
return MaterialPageRoute(builder: (_) {
|
return MaterialPageRoute(builder: (_) {
|
||||||
return const UniT2Login();
|
return const UniT2Login();
|
||||||
});
|
});
|
||||||
|
|
|
@ -184,7 +184,6 @@ class PassCheckServices {
|
||||||
if (otherInputs) {
|
if (otherInputs) {
|
||||||
if (roleid == 41 || roleid == 13 || roleid == 17 || roleid == 22) {
|
if (roleid == 41 || roleid == 13 || roleid == 17 || roleid == 22) {
|
||||||
if (io == "i") {
|
if (io == "i") {
|
||||||
print("1");
|
|
||||||
body = {
|
body = {
|
||||||
"station_id": stationId,
|
"station_id": stationId,
|
||||||
"temperature": temp,
|
"temperature": temp,
|
||||||
|
@ -193,7 +192,6 @@ class PassCheckServices {
|
||||||
"io": io
|
"io": io
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
print("2");
|
|
||||||
body = {
|
body = {
|
||||||
"station_id": stationId,
|
"station_id": stationId,
|
||||||
"destination": destination,
|
"destination": destination,
|
||||||
|
@ -203,7 +201,6 @@ class PassCheckServices {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print("3");
|
|
||||||
if (io == "i") {
|
if (io == "i") {
|
||||||
body = {
|
body = {
|
||||||
"cp_id": cpId,
|
"cp_id": cpId,
|
||||||
|
@ -213,7 +210,6 @@ class PassCheckServices {
|
||||||
"io": io
|
"io": io
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
print("4");
|
|
||||||
body = {
|
body = {
|
||||||
"cp_id": cpId,
|
"cp_id": cpId,
|
||||||
"destination": destination,
|
"destination": destination,
|
||||||
|
@ -224,7 +220,6 @@ class PassCheckServices {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print("5");
|
|
||||||
if (roleid == 41 || roleid == 13 || roleid == 17 || roleid == 22) {
|
if (roleid == 41 || roleid == 13 || roleid == 17 || roleid == 22) {
|
||||||
body = {
|
body = {
|
||||||
"station_id": stationId,
|
"station_id": stationId,
|
||||||
|
@ -233,7 +228,6 @@ class PassCheckServices {
|
||||||
"io": io
|
"io": io
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
print("6");
|
|
||||||
body = {
|
body = {
|
||||||
"cp_id": cpId,
|
"cp_id": cpId,
|
||||||
"temperature": temp,
|
"temperature": temp,
|
||||||
|
|
|
@ -27,7 +27,7 @@ class AppRouter {
|
||||||
case '/':
|
case '/':
|
||||||
BlocProvider.of<UserBloc>(
|
BlocProvider.of<UserBloc>(
|
||||||
NavigationService.navigatorKey.currentContext!)
|
NavigationService.navigatorKey.currentContext!)
|
||||||
.add(GetApkVersion());
|
.add(GetApkVersion(username: "",password: ""));
|
||||||
return MaterialPageRoute(builder: (_) {
|
return MaterialPageRoute(builder: (_) {
|
||||||
return const UniT2Login();
|
return const UniT2Login();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue