flutter - 如何等待 firebase verifyPhoneNumber 回调?
问题描述
我正在尝试使用干净的架构转换我的应用程序。我正在关注 Reso Coder 的教程。我的问题是如何在数据源脚本中等待 firebaseverifyPhoneNumber
回调?它将在回调触发之前返回到 repositoryImplimentation 脚本。我也是新来的集团。
ServerException
这是一个示例脚本,当用户输入无效的电话号码格式时必须返回一个。
mobile_auth_datasource.dart
abstract class MobileAuthenticationDatasource {
Future<void> verifyPhoneNumber(Params params);
}
class MobileAuthenticationDatasourceImpl
extends MobileAuthenticationDatasource {
String _verificationCode = "";
MobileAuthenticationDatasourceImpl({this.firebaseAuth});
@override
Future<void> verifyPhoneNumber(Params params) async {
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: params.phoneNumber,
timeout: Duration(seconds: 0),
verificationCompleted: (authCredential) =>
_verificationComplete(authCredential),
// if there is an exception, get the exception message and set it to the return value
verificationFailed: (authException) =>
_verificationFailed(authException),
codeAutoRetrievalTimeout: (verificationId) =>
_codeAutoRetrievalTimeout(verificationId),
// called when the SMS code is sent
codeSent: (verificationId, [code]) =>
_smsCodeSent(verificationId, [code]));
}
String _verificationFailed(AuthException authException) {
print(authException.message);
throw ServerException(message: 'Unexpected Error Occur');
//return authException.message;
}
}
mobile_auth_repository_impl.dart
class MobileAuthenticationRepositoryImpl
implements MobileAuthenticationRepository {
final MobileAuthenticationDatasource localDataSource;
final NetworkInfo networkInfo;
MobileAuthenticationRepositoryImpl({this.localDataSource, this.networkInfo});
@override
Future<Either<Failure, MobileAuthenticationEntity>> verifyPhoneNumber(
Params params) async {
try {
await localDataSource.verifyPhoneNumber(params);
return Right(null);
} on ServerException catch (e) {
return Left(ServerFailure(message: e.message));
} on SocketException {
return Left(NetworkFailure());
}
}
}
解决方案
推荐阅读
- api - 爱普生收据缓冲打印问题
- java - Java sql批量从db中选择
- wordpress - 来自 Kubernetes 中 pod 容器内进程的文件所有权和权限
- html - 如何在 li 中定位按钮?
- javascript - 如何过滤数组中哪些元素具有嵌套数组?
- javascript - 如何使用 ploty 显示来自端点的数据?
- reactjs - React App 在 Github Pages 上呈现空白页面
- c++ - 如何使用 OpenGL 使用自定义调色板重新映射数据
- python - 有没有更简洁的方法将熊猫索引转换为布尔掩码?
- firebase - 如何获取 Flutter firebase currentUser 数据?