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

Time:02-17

I am anew in GetX I try show snacbar with firebase error When the email already used But I have error with null safety I do not know why

**The snack bar for check box work fine The error

Exception caught by widgets library ======================================================= The following _CastError was thrown building GetSnackBar(dirty, dependencies: [MediaQuery, _EffectiveTickerMode], state: GetSnackBarState#e73b7): Null check operator used on a null value

Sing Up function in auth control

 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,
      );
    }
  }                                

My SingUp screen

  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 ........................

CodePudding user response:

If you aren't, replace MaterialApp with GetMaterialApp in your main.dart or wherever you put it.

CodePudding user response:

its just add borderWidth: 100, to snack bar

  • Related