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

outdated

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
0
pub points
0%
popularity

Publisher

verified publishernew-step-apps.com

Package that depends on fcm_config package to localize firbasemessaging notifications

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

fcm_config, flutter, shared_preferences

More

Packages that depend on fcm_localization