这是我的实现。我收到非常混乱的错误消息。
如何处理错误消息以使其更清晰或捕获它们并提供我自己的?
class AuthGateUI extends StatelessWidget {
const AuthGateUI({super.key});
@override
Widget build(BuildContext context) {
return StreamBuilder<User?>(
stream: FirebaseAuth.instance.authStateChanges(),
initialData: FirebaseAuth.instance.currentUser,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return SignInScreen(
providers: [
EmailAuthProvider(),
GoogleProvider(
clientId: 'XXX',
scopes: ['email', 'profile'],
iOSPreferPlist: true,
),
],
footerBuilder: (context, action) => _AuthFooter(),
);
}
return const CustomizeUI(userFirstTime: true);
},
);
}
}
我厌倦了一些事情,比如检查快照是否有错误,但这不起作用
现在有一种方法可以自定义任何错误消息。
API文档:
示例:
ErrorText.localizeError = (BuildContext context, FirebaseAuthException e) {
// I'm assuming this should be the code, but it might be different
if (e.code == -47) return 'Custom message goes here';
final defaultLabels = FirebaseUILocalizations.labelsOf(context);
return localizedErrorText(e.code, defaultLabels);
}