fix null safety

This commit is contained in:
2021-09-11 16:56:20 +06:30
parent a4d3777e8a
commit fe799ad820
32 changed files with 125 additions and 93 deletions

View File

@@ -32,9 +32,6 @@ class AuthFb {
try {
_authResult = await _fb.signInWithCredential(credential);
print("PhoneVerificationCompleted :$_authResult");
if (_authResult == null) {
throw SigninException("Sigin error!");
}
} catch (e) {
print("Exception:$e");
// throw e;
@@ -61,7 +58,8 @@ class AuthFb {
_verificationId = verificationId;
print("codeSent " + phoneNumber);
codeSentCompleted = true;
completer.complete(fcs.AuthResult(authStatus: AuthStatus.SMS_SENT));
if (!completer.isCompleted)
completer.complete(fcs.AuthResult(authStatus: AuthStatus.SMS_SENT));
};
final fb.PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
@@ -70,7 +68,8 @@ class AuthFb {
_verificationId = verificationId;
if (codeSentCompleted) {
completer.complete(fcs.AuthResult(authStatus: AuthStatus.SMS_SENT));
if (!completer.isCompleted)
completer.complete(fcs.AuthResult(authStatus: AuthStatus.SMS_SENT));
} else {
completer.completeError(SigninException("SMS code failed"));
}
@@ -92,11 +91,7 @@ class AuthFb {
final fb.AuthCredential credential = fb.PhoneAuthProvider.credential(
verificationId: _verificationId, smsCode: smsCode);
fb.UserCredential _authResult =
await _fb.signInWithCredential(credential);
if (_authResult == null) {
throw SigninException("Sigin error!");
}
await _fb.signInWithCredential(credential);
await _addUserToStream(refreshIdToken: true);
} on Exception catch (e) {
return Future.error(SigninException(e.toString()));
@@ -118,7 +113,7 @@ class AuthFb {
log.info("Claims:$claims");
if (claims == null) return;
String cid = claims["cid"];
String? cid = claims["cid"];
User? user;
if (cid != null && cid != "") {
user = await _getUserFromFirestore(cid);
@@ -129,7 +124,7 @@ class AuthFb {
}
// add privileges
String privileges = claims["pr"];
String? privileges = claims["pr"];
if (privileges != null && privileges != "") {
user.privileges = privileges.split(":").toList();
} else {
@@ -238,7 +233,7 @@ class AuthFb {
// get privilege from claim
fb.IdTokenResult idToken = await firebaseUser.getIdTokenResult(true);
String privileges = idToken.claims?["pr"] ?? '';
String? privileges = idToken.claims?["pr"] ?? '';
if (privileges != null && privileges != "") {
user.privileges = privileges.split(":").toList();
}
@@ -274,7 +269,7 @@ class AuthFb {
}
}
controller = StreamController<User>(
controller = StreamController<User?>(
onListen: _start, onPause: _stop, onResume: _start, onCancel: _stop);
return controller.stream;

View File

@@ -45,9 +45,13 @@ class MessagingFCM {
}
});
String? token = await _firebaseMessaging.getToken();
if (onSetupComplete != null && token != null) onSetupComplete(token);
log.info("Messaging Token:$token");
try {
String? token = await _firebaseMessaging.getToken();
if (onSetupComplete != null && token != null) onSetupComplete(token);
log.info("Messaging Token:$token");
} on Exception catch (e) {
log.shout("Unable to get messing token:$e");
}
}
Future<void> subscribeToTopic(String topic) {