toErrorMessage method
This function convert error to arabic & english error message
if you are set language in main just pass context.
if you need to set custom language just pass lang parameter.
if you aren't passing any parms function will get default language of device.
Implementation
String toErrorMessage({BuildContext? context, AppLanguage? lang}) {
// if user set custom language
if (lang != null) {
return _mapMessage(lang == AppLanguage.ar);
}
// if user set language in main
if (context != null) {
final locale = Localizations.localeOf(context);
return _mapMessage(locale.languageCode == 'ar');
}
// get language device
final deviceLocale = WidgetsBinding.instance.platformDispatcher.locale;
return _mapMessage(deviceLocale.languageCode == 'ar');
}