有没有办法自定义 Firebase 身份验证在 Flutter 应用程序中提供的登录/注册链接?

问题描述 投票:0回答:1

我正在使用 Firebase 身份验证包来允许在我的 Flutter 应用程序中登录/登录。您可以看到附加的两个屏幕:一个是 SignInScreen(),另一个是 RegisterScreen。但是,在这两个应用程序上,生成的链接都是“使用手机登录”。链接按预期工作,这只是我想更改的文本。

或者 - 如果 Firebase 将电话注册和电话注册视为同一件事,并且我不会以不同的方式处理事情,那么有没有办法在短信验证后得知用户是新用户?

谢谢!

Registration Screen Sign In Screen

尚未尝试任何方法来解决此问题,因为我找不到如何在线更改此问题的示例。

import 'package:arcadious/home.dart';
import 'package:firebase_auth/firebase_auth.dart' hide PhoneAuthProvider;
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
import 'package:flutter/material.dart';

class AuthGate extends StatelessWidget {
  const AuthGate({super.key});

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<User?>(
      stream: FirebaseAuth.instance.authStateChanges(),
      builder: (context, snapshot) {
        if (!snapshot.hasData) {
          return SignInScreen(
            showAuthActionSwitch: false,
            providers: [
              PhoneAuthProvider(),
            ],
            subtitleBuilder: (context, action) {
              return Padding(
                padding: const EdgeInsets.symmetric(vertical: 8.0),
                child:
                    Column(mainAxisSize: MainAxisSize.max, children: <Widget>[
                  Container(
                    margin: const EdgeInsets.only(bottom: 20.0),
                    child: const Text(
                      "SIGN IN TO ARCADIOUS",
                      textAlign: TextAlign.left,
                      style: TextStyle(
                        fontFamily: 'Outfit',
                        fontWeight: FontWeight.w700,
                        color: Colors.white,
                        fontSize: 36,
                      ),
                    ),
                  ),
                  const Text(
                    "Arcadious is the home of video games, old and new. Search a complete list of games, view media and build your collection. Play on your phone, legally, with added features such as achievements, multiplayer and controller support. Thank you for helping test the app!",
                    textAlign: TextAlign.left,
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 16,
                    ),
                  ),
                ]),
              );
            },
            footerBuilder: (context, action) {
              return Padding(
                  padding: const EdgeInsets.only(top: 16),
                  child:
                      Column(mainAxisSize: MainAxisSize.max, children: <Widget>[
                    Container(
                      margin: const EdgeInsets.only(bottom: 20.0),
                      child: ElevatedButton(
                          style: ElevatedButton.styleFrom(
                            minimumSize: const Size.fromHeight(
                                40), // fromHeight use double.infinity as width and 40 is the height
                          ),
                          child: const Text(
                            'REGISTER A NEW ACCOUNT',
                            style:
                                TextStyle(fontSize: 18.0, fontFamily: 'Outfit'),
                          ),
                          onPressed: () {
                            Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) => RegisterScreen(
                                        showAuthActionSwitch: false,
                                        providers: [
                                          PhoneAuthProvider(),
                                        ],
                                        subtitleBuilder: (context, action) {
                                          return Padding(
                                            padding: const EdgeInsets.symmetric(
                                                vertical: 8.0),
                                            child: Column(
                                                mainAxisSize: MainAxisSize.max,
                                                children: <Widget>[
                                                  Container(
                                                    margin:
                                                        const EdgeInsets.only(
                                                            bottom: 20.0),
                                                    child: const Text(
                                                      "REGISTER FOR A NEW ARCADIOUS ACCOUNT",
                                                      textAlign: TextAlign.left,
                                                      style: TextStyle(
                                                        fontFamily: 'Outfit',
                                                        fontWeight:
                                                            FontWeight.w700,
                                                        color: Colors.white,
                                                        fontSize: 36,
                                                      ),
                                                    ),
                                                  ),
                                                  const Text(
                                                    "Arcadious is the home of video games, old and new. Search a complete list of games, view media and build your collection. Play on your phone, legally, with added features such as achievements, multiplayer and controller support. Tap the confusingly-worded 'Sign in with phone' below to get started!",
                                                    textAlign: TextAlign.left,
                                                    style: TextStyle(
                                                      color: Colors.white,
                                                      fontSize: 16,
                                                    ),
                                                  ),
                                                ]),
                                          );
                                        },
                                        footerBuilder: (context, action) {
                                          return Padding(
                                              padding: const EdgeInsets.only(
                                                  top: 16),
                                              child: Column(
                                                  mainAxisSize:
                                                      MainAxisSize.max,
                                                  children: <Widget>[
                                                    Container(
                                                      margin:
                                                          const EdgeInsets.only(
                                                              bottom: 20.0),
                                                      child: ElevatedButton(
                                                          style: ElevatedButton
                                                              .styleFrom(
                                                            minimumSize: const Size
                                                                .fromHeight(
                                                                40), // fromHeight use double.infinity as width and 40 is the height
                                                          ),
                                                          child: const Text(
                                                            'SIGN IN INSTEAD',
                                                            style: TextStyle(
                                                                fontSize: 18.0,
                                                                fontFamily:
                                                                    'Outfit'),
                                                          ),
                                                          onPressed: () {
                                                            Navigator.pop(context);
                                                          }),
                                                    ),
                                                    const Text(
                                                      'By registering a new account or by signing in, you agree to our Terms & Conditions, as well as our Privacy Policy.',
                                                      style: TextStyle(
                                                        color: Colors.grey,
                                                        fontSize: 12,
                                                      ),
                                                    ),
                                                  ]));
                                        },
                                      )),
                            );
                          }),
                    ),
                    const Text(
                      'By registering a new account or by signing in, you agree to our Terms & Conditions, as well as our Privacy Policy.',
                      style: TextStyle(
                        color: Colors.grey,
                        fontSize: 12,
                      ),
                    ),
                  ]));
            },
          );
        }

        return const HomeScreen();
      },
    );
  }
}
flutter firebase
1个回答
0
投票

我认为“问题”是您正在使用 firebase 函数来创建登录屏幕,因此您无法完全控制您所写的内容。 您应该编写自己的页面(如果您想自定义所有内容),而不是使用类 SignInScreen

您可以使用此代码使您的按钮使用谷歌登录(因此,在按钮的 onTap() 中调用此函数,可能会显示一些加载动画,直到您得到未来的结果),并自定义页面如你所愿

Future<dynamic> signInWithGoogle() async {
    try {
      final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();

      final GoogleSignInAuthentication? googleAuth =
          await googleUser?.authentication;

      final credential = GoogleAuthProvider.credential(
        accessToken: googleAuth?.accessToken,
        idToken: googleAuth?.idToken,
      );

      return await FirebaseAuth.instance.signInWithCredential(credential);
    } on Exception catch (e) {
      print('exception->$e');
    }
  }
© www.soinside.com 2019 - 2024. All rights reserved.