Flutter 后台消息国际化
在我的 flutter 应用程序中,我想翻译推送通知正文中的一些文本。
用于前台通知。没有问题。
对于背景通知,我使用:
void main() {
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(MyApp());
}
并且 _firebaseMessagingBackgroundHandler
必须是顶级函数。
那么,由于我这里没有上下文,如何使用我著名的 AppLocalizations.of(context).cancel,
?
In my flutter app, i want to translate some text in the push notification body.
For foreground notifications. there is no problem.
For backgroud notifiactions i use :
void main() {
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(MyApp());
}
And _firebaseMessagingBackgroundHandler
must be a top-level function.
So, how can i use my famous AppLocalizations.of(context).cancel,
since I don't have a context here ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于
_firebaseMessagingBackgroundHandler
是一个顶级函数 - 您可以将context
作为可选参数传递。这样您就可以访问上下文。Since
_firebaseMessagingBackgroundHandler
is a top-level function- you can passcontext
as an optional parameter. So that you can access the context.我遇到了同样的问题,这是我的解决方案:
基本上我使用了基于平台的
locale
而不是context
的本地化。我想知道为什么没有人建议这个,它对我有用。
I faced the same problem and here's my solution:
Basically I used the localizations based on the platform's
locale
instead of thecontext
.I wonder why no one suggested this, it works for me.
在 MyApp 中创建变量 static
Exp:
在 MyApp 的构建函数中
In MyApp create variable static
Exp:
in build function of MyApp
这可能是最简单的解决方案。
This is probably the simplest solution.