In my app I am calling an external api which returns a json. I am able to verify that the json is correct as I have double checked with postman. After making the api call I have a custom log action which generically logs a string. I am using it to track down any error in the data.
As you can see from the picture there are two logData actions. The first one, log the json body received from the server
This action produce the following text on the console
flutter: Message {typeDiscriminator: StampsHolderBalanceResponse, product: xxxxxxxxx, stamps: 0, awards: 0, redeemedAwards: 0}
The second action tries to convert the json path into a datatype and the back to json for logging purposes. This is the datatype
And this is the logData configuration
When the second logData is called the console logs the following error:
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: Null check operator used on a null value
#0 logData (package:mypackage/actions/actions.dart:24:9)
#1 BalanceBModel.getBalance (package:mypackage/pages/home/components/balance_b/balance_b_model.dart:199:29)
<asynchronous suspension>
#2 _BalanceBWidgetState.initState.<anonymous closure> (package:mypackage/pages/home/components/balance_b/balance_b_widget.dart:44:7)
<asynchronous suspension>
For instance, this is the generated code for the action:
stampsBalanceResponse = await AccountsAPIGroup.getBalanceCall.call(
apiBaseUrl: FFDevEnvironmentValues().ApiBaseUrl,
apiVersion: FFDevEnvironmentValues().ApiVersion,
tenantId: currentUserData?.programId,
accessToken: currentAuthenticationToken,
accountId: currentUserData?.accountId,
);
if ((stampsBalanceResponse?.succeeded ?? true)) {
logFirebaseEvent('GetBalance_action_block');
await action_blocks.logData(
context,
text: getJsonField(
(stampsBalanceResponse?.jsonBody ?? ''),
r'''$.result''',
).toString().toString(),
);
logFirebaseEvent('GetBalance_action_block');
await action_blocks.logData(
context,
text: (StampsHolderBalanceStruct.maybeFromMap(getJsonField(
(stampsBalanceResponse?.jsonBody ?? ''),
r'''$.result''',
).toString())
?.toMap())
?.toString(),
);
}