我尝试使用 getx 显示 snackbar 从 firebase 向用户显示错误

I try display snackbar with getx show error from firebase to user

我是GetX的新成员 我尝试用 firebase 错误显示 snacbar 当电子邮件已被使用时 但是我有空安全错误我不知道为什么

**复选框的小吃店工作正常 错误

小部件库捕获异常======================================== =============== 以下 _CastError 被抛出构建 GetSnackBar(脏,依赖项:[MediaQuery,_EffectiveTickerMode],状态:GetSnackBarState#e73b7): 用于空值的空检查运算符

认证控制中的注册功能

 void signUpUsingFirebase({
    required String name,
    required String email,
    required String password,
  }) async {
    try {
      await auth.createUserWithEmailAndPassword(
          email: email, password: password);
      update();
    } on PlatformException catch (error) { String title = error.code;
     String message = '';
     if (error.code == 'weak-password') {
       message = 'The password provided is too weak.';
     } else if (error.code == 'email-already-in-use') {
       message = 'The account already exists for that email.';
     } else {
       message = error.message.toString();
     }
     Get.snackbar(
       title ,
       message,
       snackPosition: SnackPosition.BOTTOM,
       borderColor: Colors.green,
       colorText: Colors.white,
     );

    }
       catch (e) {
      Get.snackbar(
        'Error!',
       e.toString(),
        snackPosition: SnackPosition.BOTTOM,
        borderColor: Colors.green,
        colorText: Colors.white,
      );
    }
  }                                

我的 SingUp 屏幕

  SignUpScreen({Key? key}) : super(key: key);
  final fromKey = GlobalKey<FormState>();
  final TextEditingController namecontroller = TextEditingController();
  final TextEditingController emailcontroller = TextEditingController();
  final TextEditingController passwordcontroller = TextEditingController();
  final controller = Get.find<AuthController>();
  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Scaffold(
      appBar: AppBar(
        backgroundColor: Get.isDarkMode ? Colors.white : darkGreyClr,
        elevation: 0,
      ),
      backgroundColor: Get.isDarkMode ? Colors.white : darkGreyClr,
      body: SingleChildScrollView(
        child: Column(
          children: [
            SizedBox(
              width: double.infinity,
              height: MediaQuery.of(context).size.height / 1.3,
              child: Padding(
                padding: EdgeInsets.only(left: 25, right: 25, top: 40),
                child: Form(
                  key: fromKey,
                  child: Column(
                    children: [
                      Row(
                        children: [
                          TextUtils(
                              text: 'Sing',
                              fontSize: 28,
                              fontWeight: FontWeight.w500,
                              color: Get.isDarkMode ? Colors.white : pinkClr,
                              underLine: TextDecoration.none),
                          const SizedBox(
                            width: 3,
                          ),
                          TextUtils(
                              text: 'Up',
                              fontSize: 28,
                              fontWeight: FontWeight.w500,
                              color: Get.isDarkMode ? Colors.white : pinkClr,
                              underLine: TextDecoration.none),
                        ],
                      ),
                      const SizedBox(
                        height: 50,
                      ),
                      AuthTextFormField(
                        controller: namecontroller,
                        obscureText: false,
                        validator: (value) {
                          if (value.toString().length <= 2 ||
                              !RegExp(validationName).hasMatch(value)) {
                            return "Enter valid name";
                          } else {
                            return null;
                          }
                        },
                        prefixIcon: Get.isDarkMode
                            ? Image.asset('assets/images/user.png')
                            : Icon(
                                Icons.person,
                                color: pinkClr,
                                size: 30,
                              ),
                        suffixIcon: const Text(''),
                        hintText: 'User Name',
                      ),
                      const SizedBox(
                        height: 20,
                      ),
                      AuthTextFormField(
                        controller: emailcontroller,
                        obscureText: false,
                        validator: (value) {
                          if (!RegExp(validationEmail).hasMatch(value)) {
                            return "Enter valid email";
                          } else {
                            return null;
                          }
                        },
                        prefixIcon: Get.isDarkMode
                            ? Image.asset('assets/images/email.png')
                            : Icon(
                                Icons.email,
                                size: 30,
                                color: pinkClr,
                              ),
                        suffixIcon: const Text(''),
                        hintText: 'Email',
                      ),
                     const SizedBox(
                        height: 20,
                      ),
                      GetBuilder<AuthController>(builder: (_) {
                        return AuthTextFormField(
                          controller: passwordcontroller,
                          obscureText:controller.isVibility? false:true,
                          validator: (value) {
                            if (value.toString().length < 6) {
                              return "enter vaild password";
                            } else {
                              return null;
                            }
                          },
                          prefixIcon: Get.isDarkMode
                              ? Image.asset('assets/images/lock.png')
                              : Icon(
                                  Icons.lock,
                                  size: 30,
                                  color: pinkClr,
                                ),
                          suffixIcon: IconButton(
                            onPressed: () {
                              controller.visibility();
                            },
                            icon:controller.isVibility?const Icon(
                              Icons.visibility_off,
                              color: Colors.black,
                            ):const Icon(
                              Icons.visibility,
                              color: Colors.black,
                            ),
                          ),
                          hintText: 'Password',
                        );
                      }),
                      const SizedBox(
                        height: 50,
                      ),
                      CheckWidget(),
                     const SizedBox(
                        height: 50,
                      ),
                     GetBuilder<AuthController>(builder:(_){
                       return  AuthButtton(
                       onpressed: () {
                         if (controller.isCheckBox == false) {
                           Get.snackbar(
                             "Check Box",
                             "Please, Accept terms & conditions",
                             snackPosition: SnackPosition.BOTTOM,
                             backgroundColor: Colors.green,
                             colorText: Colors.white,
                           );
                         }else if (fromKey.currentState!.validate()) {
                           String name = namecontroller.text.trim();
                           String email = emailcontroller.text.trim();
                           String password = passwordcontroller.text;
                           controller.signUpUsingFirebase(
                             name: name,
                             email: email,
                             password: password,
                           );

                           controller.isCheckBox = true;
                         }

                       },
                       text: 'SING UP',
                     );
                       },

                     ),
                    ],
                  ),
                ),
              ),
            ),
            ContainerUnder(
              text: 'Already have an Account? ',
              onPressed: () {Get.offNamed(Routes.loginScreen);},
              textType: "Log in",
            ),
          ],
        ),
      ),
    ));
  }
}```
Please help with auth erorr when the email is already used ........................

如果不是,请将 MaterialApp 替换为 GetMaterialAppmain.dart 或任何地方。

只是 添加边框宽度:100, 去小吃店