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';
|
||||
part 'user_event.dart';
|
||||
part 'user_state.dart';
|
||||
|
||||
class UserBloc extends Bloc<UserEvent, UserState> {
|
||||
UserData? _userData;
|
||||
VersionInfo? _versionInfo;
|
||||
String? _apkVersion;
|
||||
bool save = false;
|
||||
String? uuid;
|
||||
String? username;
|
||||
String? password;
|
||||
List<AssignedArea> establishmentPointPersonAssignedAreas = [];
|
||||
UserBloc() : super(UserInitial()) {
|
||||
//// 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();
|
||||
_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<UserEvent, UserState> {
|
|||
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<UserEvent, UserState> {
|
|||
});
|
||||
////Loading the current version of the app
|
||||
on<LoadVersion>((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<UserLogin>((event, emit) async {
|
||||
username = event.username;
|
||||
password = event.password;
|
||||
try {
|
||||
Map<dynamic, dynamic> response = await AuthService.instance
|
||||
.webLogin(username: event.username, password: event.password);
|
||||
|
|
|
@ -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<Object> get props => [];
|
||||
List<Object> get props => [username,password];
|
||||
}
|
||||
|
||||
class UserLogin extends UserEvent {
|
||||
|
|
|
@ -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',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
@ -46,8 +46,9 @@ class _UniT2LoginState extends State<UniT2Login> {
|
|||
backgroundColor: Colors.black87,
|
||||
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
|
||||
child: BlocConsumer<UserBloc, UserState>(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<UniT2Login> {
|
|||
}));
|
||||
}
|
||||
}, 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<UniT2Login> {
|
|||
onpressed: () {
|
||||
BlocProvider.of<UserBloc>(
|
||||
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<UniT2Login> {
|
|||
onpressed: () {
|
||||
BlocProvider.of<UserBloc>(
|
||||
NavigationService.navigatorKey.currentContext!)
|
||||
.add(GetApkVersion());
|
||||
.add(LoadVersion(username: username, password: password));
|
||||
return MaterialPageRoute(builder: (_) {
|
||||
return const UniT2Login();
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -27,7 +27,7 @@ class AppRouter {
|
|||
case '/':
|
||||
BlocProvider.of<UserBloc>(
|
||||
NavigationService.navigatorKey.currentContext!)
|
||||
.add(GetApkVersion());
|
||||
.add(GetApkVersion(username: "",password: ""));
|
||||
return MaterialPageRoute(builder: (_) {
|
||||
return const UniT2Login();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue