Handling firebase authentication errors Flutter

I’m trying to handle firebase authentication errors such as wrong password etc But when I enter wrong password the app freezes and I get an exception but I want to display it in snackbar

The error i get

Exception has occurred.
PlatformException (PlatformException(firebase_auth, com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The password is invalid or the user does not have a password., {code: wrong-password, additionalData: {}, message: The password is invalid or the user does not have a password.}, null))

THE LOGIN SCREEN

Form(
          key: _key,
          child: ListView(
            children: [
              GestureDetector(
                  onTap: () {
                    Navigator.of(context).pushReplacement(MaterialPageRoute(
                        builder: (context) => RegisterView()));
                  },
                  child: Text(
                    'Sign Up',
                    textAlign: TextAlign.right,
                    style: TextStyle(
                        fontSize: 20,
                        fontWeight: FontWeight.bold,
                        color: kPrimaryColor),
                  )),
              CustomText(text: 'Log in '),
              Padding(
                padding: const EdgeInsets.only(top: 40),
                child: TextFormField(
                  keyboardType: TextInputType.emailAddress,
                  decoration: InputDecoration(
                      hintText: 'Email',
                      prefixIcon: Icon(
                        Icons.email,
                      )),
                  controller: _emailController,
                  validator: (value) {
                    if (value.isEmpty) {
                      return 'Some fields required';
                    } else if (!kRegExp.hasMatch(value)) {
                      return 'please make sure your email is valid';
                    }
                    return null;
                  },
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(top: 15, bottom: 15),
                child: TextFormField(
                  keyboardType: TextInputType.number,
                  obscureText: model.isObsecure,
                  decoration: InputDecoration(
                      hintText: 'Password',
                      prefixIcon: Icon(
                        Icons.lock,
                      ),
                      suffixIcon: IconButton(
                          icon: Icon(Icons.remove_red_eye),
                          onPressed: () {
                            model.onClicked();
                          })),
                  controller: _passwordController,
                  validator: (value) {
                    if (value.isEmpty) {
                      return 'Some fields required';
                    } else if (value.length < 6) {
                      return 'The password has to be 6 characters long';
                    }
                    return null;
                  },
                ),
              ),
              Padding(
                padding: const EdgeInsets.all(20),
                child: model.isLoading
                    ? Center(
                        child: CircularProgressIndicator(),
                      )
                    : CustomButton(
                        'Login',
                        () async {
                          if (_key.currentState.validate()) {
                            try {
                              bool _result =
                                  await model.signInwithemailandpassword(
                                      _emailController.text.trim(),
                                      _passwordController.text.trim());

                              if (_result == true) {
                                Navigator.of(context).push(MaterialPageRoute(
                                    builder: (context) => HomeView()));
                              } else {
                                ScaffoldMessenger.of(context).showSnackBar(
                                    SnackBar(
                                        content: Text(
                                            'Errorrrrrrrrrrrrrrrrrrrrrrr')));
                              }
                            } catch (e) {
                              ScaffoldMessenger.of(context)
                                  .showSnackBar(SnackBar(content: Text(e)));
                            }
                          }
                        },
                      ),
             

              ),
            ],
          ),
        ),

And here the authentication method

Future<bool> signInwithemailandpassword(String email, String password) async {
    _isLoading = true;
    notifyListeners();
    try {
      UserCredential result = await _firebaseAuth.signInWithEmailAndPassword(
          email: email, password: password);
      User user = result.user;
      result.credential.token.sign;
      _isLoading = false;
      notifyListeners();
      return true;
    } catch (e) {
      _isLoading = false;
      notifyListeners();
      print(e.toString());
      return false;
    }
  }

i tried to catch firebase auth exception and tried to assign the error value to a variable i created and check if the variable equal null or not but nothing worked