小编AhW*_*gih的帖子

Flutter 从本地化 JSON 文件解析数组

我正在尝试将城市名称数组添加到我的本地化 json 文件中,但在将其转换为字符串后无法将其解码回数组。

en-US.json

{
  "title" : "My account",
  "name" : "John",
  "cities" : ["Paris", "Lyon", "Nice"]
}
Run Code Online (Sandbox Code Playgroud)

应用程序本地化.dart

class AppLocalizations {
  final Locale locale;

  AppLocalizations(this.locale);

  static AppLocalizations of(BuildContext context) {
    return Localizations.of<AppLocalizations>(context, AppLocalizations);
  }

  static const LocalizationsDelegate<AppLocalizations> delegate =
      _AppLocalizationsDelegate();

  Map<String, String> _localizationStrings;

  Future<bool> load() async {
    String jsonString = await rootBundle.loadString(
        'assets/translations/${locale.languageCode}-${locale.countryCode}.json');

    Map<String, dynamic> jsonMap = json.decode(jsonString);

    _localizationStrings = jsonMap.map((key, value) {
      return MapEntry(key, value.toString());
    });
    return true;
  }

  Future<void> setLocale(Locale locale) async {
    final SharedPreferences _prefs = …
Run Code Online (Sandbox Code Playgroud)

arrays json dart flutter

6
推荐指数
1
解决办法
2523
查看次数

Flutter如何访问FCM backgroundHandler静态方法中的provider.of(context)?

我已经成功设置了后台通知并使用邮递员对其进行了测试,一切都很好。

现在我需要在我的backgroundHandler 中访问Provider.of(context),它必须是没有上下文的静态方法。

我需要做的就是根据后台通知中的数据执行操作。

这是我初始化 FCM 的代码(我在启动屏幕中执行此操作)

Future<void> initFcm() async {

_firebaseMessaging.configure(
  onBackgroundMessage: myBackgroundMessageHandler,
  onMessage: (msg) async {
    print('this is ONMESSAGE $msg');
  },
  onLaunch: (msg) async {
    print('ON LAUNCH');
  },
  onResume: (msg) async {
    print('ON RESUME');
  },
);

// For testing purposes print the Firebase Messaging token
 deviceToken = await _firebaseMessaging.getToken();
 print("FirebaseMessaging token: $deviceToken");
}


static Future<dynamic> myBackgroundMessageHandler(
  Map<String, dynamic> message) async {
print(message);

if (message.containsKey('data')) {
  // Handle data message
  final dynamic data = message['data'];
   final orderId = data['order_id']; …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-provider

6
推荐指数
0
解决办法
659
查看次数

未收到 Flutter FCM IOS 静默(仅数据)通知

我正在使用数据通知来更新我的应用程序状态,它在 Android 上运行良好,但我无法在 IOS 上接收任何数据消息,甚至没有触发 onMessage 侦听器。

我正在使用这些:

firebase_core:^0.7.0

firebase_auth:^0.20.1

firebase_messaging:^8.0.0-dev.15

firebase_analytics:^7.0.0

我正在使用 POSTMAN 来测试它,它在 Android 上运行没有问题,但只是没有收到发送到 IOS 的数据消息。

带有通知字段的通知在前台、后台和终止时完美运行,问题仅在于仅数据消息。

任何帮助表示赞赏。

在此处输入图片说明

任何帮助表示赞赏。

push-notification ios flutter firebase-cloud-messaging

1
推荐指数
1
解决办法
477
查看次数