I need to login to home page using firebase login with bloc pattern. LoginBloc is giving null inside the BlocBuilder.
Expected behavior
I expected to open the loginForm.but got an error getter 'isFormValid' 'isEmailValid' and 'isPasswordValid' was called on null
class _LoginFormState extends State<LoginForm> {
final _formKey = GlobalKey<FormState>();
bool _passwordVisible = false;
bool _autoValidate = false;
final TextEditingController _emailController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
bool get isPopulated =>
_emailController.text.isNotEmpty && _passwordController.text.isNotEmpty;
bool isLoginButtonEnabled(LoginState state) {
return state.isFormValid && isPopulated && !state.isSubmitting;
}
the error caused by login button
RaisedButton(
disabledColor: Colors.blueGrey,
shape: StadiumBorder(),
padding: EdgeInsets.all(0),
onPressed: isLoginButtonEnabled(state)
? _onFormSubmitted
: null)
which is on
child: BlocBuilder<LoginBloc, LoginState>(
builder: (BuildContext context, LoginState state) {
return Stack(
children: [
////
RaisedButton()
)})
screenshot
โโโโโโโโ Exception caught by widgets library โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The following NoSuchMethodError was thrown building BlocBuilder
The getter 'isFormValid' was called on null.
Receiver: null
Tried calling: isFormValid
The relevant error-causing widget was:
BlocBuilder
When the exception was thrown, this was the stack:
Hi @Getahun20 ๐
Thanks for opening an issue!
Looks like the issue is the bloc's initial state is being set to null at https://github.com/ezra126/bekloh_user/blob/c819e773038c71026e62b813a26ee41513ff8970/lib/bloc/loginbloc/login_bloc.dart#L20.
If you update your bloc like so it should resolve the error:
LoginBloc({
@required UserRepository userRepository,
}) : assert(userRepository != null),
_userRepository = userRepository, super(LoginState.empty()); // pass the initial state to super instead
// REMOVE THE FOLLOWING LINE
LoginState get initialState => LoginState.empty();
Hope that helps! ๐
yah it works thank u very much
Most helpful comment
yah it works thank u very much