How to change initial language of flutter app? - flutter

I am trying to create Arabic flutter app and the default language of flutter app is English , I want the app to start with Arabic language , So how can I achieve this ?

return MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('en'),
const Locale('ar'),
],
locale: const Locale('ar'),
);

Related

Changing SyncFusion Flutter calendar language

I am trying to include SyncFusion Flutter calendar in my Flutter app.
I need to change the locale for the calendar.
I have included following code just inside the MaterialApp widget
child: MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
SfGlobalLocalizations.delegate,
],
supportedLocales: [
const Locale('en'),
const Locale('zh'),
const Locale('he'),
const Locale('ru'),
const Locale('fr', 'BE'),
const Locale('fr', 'CA'),
const Locale('ja'),
const Locale('de'),
const Locale('hi'),
const Locale('ar'),
],
locale: const Locale('zh'),
I have also included:
import 'package:syncfusion_localizations/syncfusion_localizations.dart';
But both lines below are marked as error:
Undefined name 'GlobalMaterialLocalizations
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,

How I can set the default language in flutter using easy localization?

I'm trying to set the Arabic 'ar' the default language for my app, but it still launch in English.
Here's my code in the runApp in main.dart
runApp(
EasyLocalization(
supportedLocales: [
Locale('en'),
Locale('ar'),
],
fallbackLocale: Locale('en'),
assetLoader: CodegenLoader(),
path: 'assets/translations',
startLocale: Locale('ar'),
child: MyApp(),
),
);
You can read this, step by step :
https://blog.logrocket.com/internationalizing-app-flutter-easy-localization/
It is well explained.

easy_localization restart the whole app every time I using hot reload

I am using easy_localization for translations in my Flutter app. everything is fine but while developing every time I use hot reload the whole app is restarted.
The console shows that easy_localization is reinitialized when hot reload:
and this is my code:
runApp(
ProviderScope(
overrides: [
prefsProvider.overrideWithValue(prefs),
],
child: EasyLocalization(
supportedLocales: const [Locale('en')],
path: 'assets/translations',
fallbackLocale: const Locale('en', 'US'),
child: const RavenApp(),
saveLocale: true,
),
),
);
Note: I tried to remove EasyLocalization and the issue despaired.

Flutter get current time zone / code name is always en_US

I have a problem with my app...I can not get the correct current Locale of my app.
This:
print(Localizations.localeOf(context));
is always giving me:
en_US
but I am actually in Germany. I tried it on both Android and iPhone Simulator as well as on a real device. It is always giving me "en_US" :(
I create my MaterialApp like this:
MaterialApp(
title: 'ProjectX',
theme: ThemeData(
primarySwatch: ColorService.createMaterialColor(AppColors.secondary),
backgroundColor: AppColors.white,
scaffoldBackgroundColor: AppColors.white,
visualDensity: VisualDensity.adaptivePlatformDensity,
fontFamily: AppTextStyles.mainFont,
),
initialRoute: isOnline
? showOnboarding
? '/onboarding'
: '/'
: '/offline',
onGenerateRoute: AppRouter.generateRoute,
locale: Locale('de', 'DE'),
localizationsDelegates: [
AppLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
],
),
Is this a known bug? What am I missing here?
Add supportedLocales named argument to MaterialApp as stated in Internationalization documentation.
MaterialApp(
title: 'ProjectX',
theme: ThemeData(
primarySwatch: ColorService.createMaterialColor(AppColors.secondary),
backgroundColor: AppColors.white,
scaffoldBackgroundColor: AppColors.white,
visualDensity: VisualDensity.adaptivePlatformDensity,
fontFamily: AppTextStyles.mainFont,
),
initialRoute: isOnline
? showOnboarding
? '/onboarding'
: '/'
: '/offline',
onGenerateRoute: AppRouter.generateRoute,
locale: Locale('de', 'DE'),
supportedLocales: [Locale('de', 'DE')],
localizationsDelegates: [
AppLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
],
),
Is german the current language of the device?
In Locale, I think that it gets from keyboard language.
Like: if my keyboard language is US English, the locale will get en_US, even though I live in Brazil.

Flutter Widgets don't get overridden accent color

I have a dynamic theme in my app.
I set the theme using the following code:
final ThemeData base = ThemeData(brightness: Brightness.light, fontFamily: 'Simpler');
return base.copyWith(
primaryColor: AppColors.appColor,
accentColor: AppColors.secondaryColor,
accentColorBrightness: Brightness.light,
accentIconTheme: IconThemeData(color: Colors.black)
);
This is set as the theme in my app
child: MaterialApp(
title: Provider.of<AppConfig>(context).appName,
locale: selectedLocale.locale,
theme: currentTheme.data,
initialRoute: '/',
onGenerateRoute: routes,
localizationsDelegates: [
AppLocalizationsDelegate(),
FallbackCupertinoLocalisationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
Locale('en', 'US'),
],
),
The docs show that widgets such as a fab or a switch should be default be set to the themes accent color but for some reason the color the widgets get is the system default light blue accent color.
When I debug and check to see the accent color in the Theme.of(context) I see that the color is correct...
If I specificaly add the color change to the custom theme such as
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: AppColors.secondaryColor,
foregroundColor: Colors.black,
),
The color is set as it should but I don't think that I should override all the properties in the ThemeData, it just dose'nt make sense.