We are calling API and handling the exception.

class Failure with _$Failure  implements Exception  {
  
  factory Failure({
    required FetchError fetchError,
    required ServerError? errorCodeFromServer,
  }) = _Failure;
  

}

And, based on the exception type We are passing an error code when We are throwing Failure based on catching an error. Now, that error code is passed on to the bloc. And, in then UI screen We are trying to show the error message in bloc listener like this

        if (state.loginStatus == LoginStatus.error) {
          simpleSnackbarMessage(
            context,
            l10n.[state.error],
            MessageType.failed,
          );
        }

now, We have app_en.arb file in that I have all the possible error messages. But, when We are trying to access like l10n.[state.error], it show an error.

The getter '[' isn't defined for the type 'AppLocalizations'.

So, my question

how to define getter so, that based on error code I can show error message instead of having multiple if statement.

enter image description here

Thanks :pray:

0

There are 0 answers