refactor login status alert and message
parent
f1ed33a6c0
commit
54aa42ec21
|
@ -29,28 +29,38 @@ class UserBloc extends Bloc<UserEvent, UserState> {
|
|||
_versionInfo = versionInfo;
|
||||
String apkVersion = await getAppVersion();
|
||||
_apkVersion = apkVersion;
|
||||
emit(VersionLoaded(versionInfo: _versionInfo,apkVersion: _apkVersion));
|
||||
emit(VersionLoaded(versionInfo: _versionInfo, apkVersion: _apkVersion));
|
||||
} catch (e) {
|
||||
emit(UserError(
|
||||
message: e.toString(),
|
||||
));
|
||||
}
|
||||
});
|
||||
//Loading the current version of the app
|
||||
on<LoadVersion>((event, emit) {
|
||||
emit(VersionLoaded(versionInfo: _versionInfo,apkVersion: _apkVersion));
|
||||
emit(VersionLoaded(versionInfo: _versionInfo, apkVersion: _apkVersion));
|
||||
});
|
||||
|
||||
on<UserLogin>((event, emit) async {
|
||||
try {
|
||||
UserData? userData = await AuthService.instance
|
||||
Map<dynamic, dynamic> response = await AuthService.instance
|
||||
.webLogin(username: event.username, password: event.password);
|
||||
_userData = userData;
|
||||
emit(UserLoggedIn(userData: _userData));
|
||||
if (response['status'] == true) {
|
||||
UserData userData = UserData.fromJson(response['data']);
|
||||
emit(UserLoggedIn(
|
||||
userData: userData,
|
||||
success: true,
|
||||
message: response['message']));
|
||||
}else{
|
||||
emit(UserLoggedIn(
|
||||
userData: null,
|
||||
success: false,
|
||||
message: response['message']));
|
||||
}
|
||||
} on TimeoutException catch (_) {
|
||||
emit(InternetTimeout(message: timeoutError));
|
||||
}on SocketException catch (_){
|
||||
emit(InternetTimeout(message:timeoutError));
|
||||
}on Error catch(_){
|
||||
emit(InvalidCredentials(message: "Invalid username or password"));
|
||||
} on SocketException catch (_) {
|
||||
emit(InternetTimeout(message: timeoutError));
|
||||
}
|
||||
});
|
||||
on<UuidLogin>((event, emit) async {
|
||||
|
@ -61,9 +71,9 @@ class UserBloc extends Bloc<UserEvent, UserState> {
|
|||
emit(UserLoggedIn(userData: _userData));
|
||||
} on TimeoutException catch (_) {
|
||||
emit(InternetTimeout(message: timeoutError));
|
||||
}on SocketException catch (_){
|
||||
emit(InternetTimeout(message:timeoutError));
|
||||
}on Error catch(_){
|
||||
} on SocketException catch (_) {
|
||||
emit(InternetTimeout(message: timeoutError));
|
||||
} on Error catch (_) {
|
||||
emit(InvalidCredentials(message: "Invalid username or password"));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -32,7 +32,9 @@ class UserError extends UserState {
|
|||
}
|
||||
class UserLoggedIn extends UserState{
|
||||
final UserData? userData;
|
||||
UserLoggedIn({this.userData});
|
||||
final String? message;
|
||||
final bool? success;
|
||||
UserLoggedIn({this.userData,this.message,this.success});
|
||||
}
|
||||
|
||||
class VersionLoaded extends UserState {
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:flutter_spinkit/flutter_spinkit.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/screens/unit2/login/components/update_required.dart';
|
||||
|
@ -42,19 +43,23 @@ class _UniT2LoginState extends State<UniT2Login> {
|
|||
backgroundColor: Colors.black87,
|
||||
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
|
||||
child: BlocConsumer<UserBloc, UserState>(listener: (context, state) {
|
||||
if (state is UserLoggedIn ||
|
||||
state is UuidLoaded ||
|
||||
state is UserError ||
|
||||
state is InternetTimeout) {
|
||||
if (state is UserLoggedIn || state is UuidLoaded) {
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.dismiss();
|
||||
Navigator.pushReplacementNamed(context, '/module-screen');
|
||||
|
||||
}
|
||||
if (state is InvalidCredentials) {
|
||||
if (state is UserLoggedIn) {
|
||||
if (state.success == true) {
|
||||
Fluttertoast.showToast(msg: state.message!,toastLength: Toast.LENGTH_LONG,gravity: ToastGravity.CENTER);
|
||||
Navigator.pushReplacementNamed(context, '/module-screen');
|
||||
} else {
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.dismiss();
|
||||
errorAlert(context, "Error Login", state.message, () {});
|
||||
errorAlert(context, "Error Login", state.message, () {
|
||||
context.read<UserBloc>().add(LoadVersion());
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
}
|
||||
}
|
||||
}, builder: (context, state) {
|
||||
if (state is VersionLoaded) {
|
||||
|
@ -223,7 +228,8 @@ class _UniT2LoginState extends State<UniT2Login> {
|
|||
|
||||
BlocProvider.of<UserBloc>(context)
|
||||
.add(UserLogin(
|
||||
username: "rjvincentlopeplopez",
|
||||
username:
|
||||
"rjvincentlopeplopez",
|
||||
password: "shesthequ33n",
|
||||
// username: _formKey
|
||||
// .currentState!
|
||||
|
|
|
@ -33,23 +33,27 @@ class AuthService {
|
|||
return versionInfo;
|
||||
}
|
||||
|
||||
Future<UserData> webLogin({String? username, String? password})async{
|
||||
Future<Map<dynamic,dynamic>> webLogin({String? username, String? password})async{
|
||||
Map <String,String> body ={'username':username!,'password':password!};
|
||||
Map<String, String> baseHeaders = {
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
Map<dynamic,dynamic> responseStatus = {};
|
||||
String path = Url.instance.authentication();
|
||||
UserData? userData;
|
||||
try{
|
||||
http.Response response = await Request.instance.postRequest(path: path,param: {},headers: baseHeaders,body: body);
|
||||
if(response.statusCode == 200){
|
||||
|
||||
Map data = jsonDecode(response.body);
|
||||
userData = UserData.fromJson(data['data']);
|
||||
}
|
||||
|
||||
responseStatus = data;
|
||||
|
||||
|
||||
return responseStatus;
|
||||
}catch(e){
|
||||
throw (e.toString());
|
||||
}
|
||||
return userData!;
|
||||
|
||||
}
|
||||
Future<UserData> qrLogin({String? uuid, String? password})async{
|
||||
Map <String,String> body ={'uuid':uuid!,'password':password!};
|
||||
|
|
|
@ -61,3 +61,15 @@ successAlert(context, title, description,Function() func) {
|
|||
btnOk: SizedBox(height: 50,child: ElevatedButton(style: mainBtnStyle(success2, Colors.transparent, success), onPressed: func, child: const Text("OK")), )
|
||||
).show();
|
||||
}
|
||||
okAlert(context,title,description){
|
||||
AwesomeDialog(
|
||||
width: blockSizeHorizontal * 90,
|
||||
context: context,
|
||||
dialogType: DialogType.error,
|
||||
animType: AnimType.scale,
|
||||
headerAnimationLoop: false,
|
||||
title: title,
|
||||
desc: description,
|
||||
btnOkOnPress: () {},
|
||||
).show();
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ class Url {
|
|||
static Url get instance => _instance;
|
||||
|
||||
String host() {
|
||||
return '192.168.10.221:3003';
|
||||
// return 'agusandelnorte.gov.ph';
|
||||
// return '192.168.10.221:3003';
|
||||
return 'agusandelnorte.gov.ph';
|
||||
// return "192.168.10.219:3000";
|
||||
// return "devweb.agusandelnorte.gov.ph";
|
||||
// return 'devapi.agusandelnorte.gov.ph:3004';
|
||||
|
|
Loading…
Reference in New Issue