fcm_localization 1.0.2 copy "fcm_localization: ^1.0.2" to clipboard
fcm_localization: ^1.0.2 copied to clipboard

Package that depends on fcm_config package to localize firbasemessaging notifications

Init #

  • you have to create class for localization
 class MyTranslationMessages extends TranslationMessages {
   @override
   String get defaultLocale => "ar";
 
   @override
   Map<String, Map<String, String>> get messages => {
         "ar": {
           "new_offer": "عرض جديد",
           "new_offer_body":
               "لديك عرض جديد علي طلبك رقم {order_id} في تصنيف {category_name_ar} ",
         },
         "en": {
           "new_offer": "New offer",
           "new_offer_body":
               "You have a new offer on your request number {order_id} on  {category_name_en} ",
         },
       };
 }
  • you have to init fcm_config then init this
   void main() async {
     // Init fcm_config
     await FCMConfig().init();
      // Init fcm_localizations
     await FCMLocalization.init(MyTranslationMessages());
   
     runApp(
       // here you can get our saved locale
       MyHomePage(locale: await FCMLocalization.getSavedLocale(Locale("ar"))),
     );
   }
  • to get saved locale
  // with default
  var locale=  await FCMLocalization.getSavedLocale(Locale("ar"));
  //without default
  var locale=  await FCMLocalization.getSavedLocale();
  • any time you change your app locale you have to save it
 FCMLocalization.setLocale(Locale("ar"))
  • when you send notification from your backend or any way you have to do next:

1- you have to send data only 2- data must contain title_loc_key and body_loc_key

3- any argument in your messages must be in the root of your data

  {

      "to": "...",
      "data": {
          "title_loc_key": "new_offer",
          "body_loc_key": "new_offer_body",
          "category_name_ar": "سيارات",
          "category_name_en": "Cars",
          "order_id": "77676"
      },
      "priority": "high"

  }

notes #

  • this package will ignore any notification with notification object
  • when we can not find the message with your locale we will display from default
4
likes
100
points
150
downloads

Publisher

verified publishernew-step-apps.com

Weekly Downloads

Package that depends on fcm_config package to localize firbasemessaging notifications

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

fcm_config, flutter, shared_preferences

More

Packages that depend on fcm_localization