Skip to content

Nullable function parameter not retained in generated code after build_runner execution. #1041

@rajan-singla

Description

@rajan-singla

Description:

Hi there,

I've encountered an issue when using build_runner to generate code for my MobX store class. Specifically, the function signature in my MobX store class doesn’t match the expected syntax after code generation.

Scenario:

In my MobX store class, I defined a function as follows:

dart

@action
Future<void> onSubmitCollectionButtonClick({bool Function()? checkPaymentFailedOrSuccess}) async {}

However, after running build_runner to generate the store class, the generated code looks like this:

dart

@override
Future<void> onSubmitCollectionButtonClick(
    {bool Function() checkPaymentFailedOrSuccess}) {
  return _$onSubmitCollectionButtonClickAsyncAction.run(() => super
      .onSubmitCollectionButtonClick(
          checkPaymentFailedOrSuccess: checkPaymentFailedOrSuccess));
}

As you can see, the checkPaymentFailedOrSuccess parameter’s type in the generated code is missing the nullable ?. The generated function signature is:

dart

Future<void> onSubmitCollectionButtonClick({bool Function() checkPaymentFailedOrSuccess})

However, the expected function signature should be:

dart

Future<void> onSubmitCollectionButtonClick({bool Function()? checkPaymentFailedOrSuccess})

Steps to Reproduce:

  1. Define a function with a nullable function parameter in the MobX store class.
  2. Run build_runner to generate the store class.
  3. Observe that the nullable ? is not retained in the generated code.

Expected Behavior:

The nullable ? should be retained in the function signature after code generation, as per the original declaration.

Additional Information:

I’ve tried upgrading the dependencies (mobx, mobx_codegen, and build_runner), but the issue persists.

Has anyone encountered a similar issue? Is there a known workaround or solution to ensure the nullable function type is preserved in the generated code?

Thanks for your help! Looking forward to your insights.

Best,
Rajan Singla.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions