如何定义getter,基于错误代码,我可以显示错误消息,而不是拥有多个if` if`语句
我们称API并处理例外。
class Failure with _$Failure implements Exception {
factory Failure({
required FetchError fetchError,
required ServerError? errorCodeFromServer,
}) = _Failure;
}
并且,基于异常类型,我们在基于捕获错误的情况下丢弃故障时传递了错误代码。现在,该错误代码已传递到集团。而且,在当时的UI屏幕中,我们正在尝试在Bloc侦听器中显示错误消息
if (state.loginStatus == LoginStatus.error) {
simpleSnackbarMessage(
context,
l10n.[state.error],
MessageType.failed,
);
}
,我们有app_en.arb
文件,因为我拥有所有可能的错误消息。但是,当我们试图访问l10n。[state.error],
显示出错误。
The getter '[' isn't defined for the type 'AppLocalizations'.
因此,我的问题
如何定义getter,因此,基于错误代码,我可以显示错误消息,而不是拥有语句的多个。
谢谢:祈祷:
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.
Thanks :pray:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论