form_bloc icon indicating copy to clipboard operation
form_bloc copied to clipboard

Issue with "Wizard" style form

Open ArneSaknussemm89 opened this issue 4 years ago • 2 comments

So I'm attempting to create an "onboarding" process and decided to use the "Wizard" style pattern. However, I keep getting this error when calling the submit method on the bloc.

[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: Unhandled error Failed assertion: boolean expression must not be null occurred in bloc UserLoginFormBloc.
#0      FormBlocState.notValidStep (package:form_bloc/src/blocs/form/form_state.dart:66:28)
#1      FormBloc._onSubmitFormBloc (package:form_bloc/src/blocs/form/form_bloc.dart:421:40)
<asynchronous suspension>
#2      FormBloc.mapEventToState (package:form_bloc/src/blocs/form/form_bloc.dart:168:14)
<asynchronous suspension>
#3      Bloc._bindEventsToStates.<anonymous closure> (package:bloc/src/bloc.dart:252:20)
#4      Stream.asyncExpand.onListen.<anonymous closure> (dart:async/stream.dart:579:30)
#5      _rootRunUnary (dart:async/zone.dart:1192:38)
#6      _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#7      _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
#8      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#9      _DelayedData.perform (dart:async/stream_impl.dart:594:14)

My constructor is using addFieldBlocs with the step set. I've got steps from 0 - 6 and each one has a field bloc associated with it. The flow I'm trying to achieve is first the email is checked for an existing account and then I show certain fields depending on whether you are logging in or creating a new account. I.e.

I've started digging into the issue, but I'm not totally understanding the _isValidByStep map and how it gets filled out. Seems like one of the indexes is a null value. But I don't know how that's happening.

Example of how I'm setting up the field blocs:

/// Step 0 is verifying email
    addFieldBlocs(
      step: 0,
      fieldBlocs: [
        email,
      ],
    );

    /// Step 1 is when you have an existing account so you
    /// need to login.
    addFieldBlocs(
      step: 1,
      fieldBlocs: [
        email,
        password,
      ],
    );

    /// Step 2 is going to fill out a new account form.
    addFieldBlocs(
      step: 2,
      fieldBlocs: [
        email,
        firstName,
        lastName,
        phone,
        password,
      ],
    );
    ... and so on

Any guidance here would be awesome.

ArneSaknussemm89 avatar Jun 02 '20 20:06 ArneSaknussemm89

So it looks like because on of my "steps" has a dynamically loaded field bloc, the _isValidByStep map did not contain the numeric index of that step.

I'm thinking maybe this:

        if (!_isValidByStep[i]) {
          invalidSteps.add(i);
        }

becomes

        if (_isValidByStep.containsKey(i) && !_isValidByStep[i]) {
          invalidSteps.add(i);
        }

ArneSaknussemm89 avatar Jun 02 '20 21:06 ArneSaknussemm89

@GiancarloCode @ArneSaknussemm89 Have you found the cause of the issue?

tkhatibi avatar Jul 22 '20 10:07 tkhatibi