fcm_localization

Last updated:

0 purchases

fcm_localization Image
fcm_localization Images
Add to Cart

Description:

fcm localization

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} ",
},
};
}
copied to clipboard

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"))),
);
}
copied to clipboard

to get saved locale

// with default
var locale= await FCMLocalization.getSavedLocale(Locale("ar"));
//without default
var locale= await FCMLocalization.getSavedLocale();
copied to clipboard

any time you change your app locale you have to save it

FCMLocalization.setLocale(Locale("ar"))
copied to clipboard

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"

}
copied to clipboard
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

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.