-
-
Notifications
You must be signed in to change notification settings - Fork 316
Description
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:
- Define a function with a nullable function parameter in the MobX store class.
- Run
build_runnerto generate the store class. - 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.