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,
Related
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.
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.
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'),
);
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.
When I try to localize a string in a TabBarView I get this error:
NoSuchMethodError: The method 'translate' was called on null. Receiver: null. Tried calling: translate("username).
I use this line of code to translate a key to a localized string:
AppLocalizations.of(context).translate('username')
This works great in all the other screens of my app except this one. Does anyone know why it's not working and how to solve it?
Some things I already tried:
pass the context of the main screen (the screen that holds all the TabBarViews)
wrap every ListTile in a Builder
wrap the ListView in a Builder
Code:
class AccountScreen extends StatelessWidget {
final String username;
final String email;
final int points;
AccountScreen(this.username, this.email, this.points);
#override
Widget build(BuildContext context) {
return Container(
child: Padding(
padding: EdgeInsets.all(10),
child: ListView(
children: <Widget>[
ListTile(
title: Text(AppLocalizations.of(context).translate('username')),
subtitle: Text(username),
),
ListTile(
title:
Text(AppLocalizations.of(context).translate('email_address')),
subtitle: Text(email),
),
ListTile(
title: Text(AppLocalizations.of(context).translate('points')),
subtitle: Text('$points'),
),
],
),
),
);
}
}
I found same problem. But in my case is using MaterialApp without localizationsDelegates. (I mean all file not only main.dart).
So i add localizationsDelegates on every MaterialApp in all widget.
e.g.
MaterialApp(
localizationsDelegates: [
MainLocalizationsDelegate.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
home: DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
brightness: Brightness.light,
bottom: TabBar(
tabs: [
Tab(text: MainLocalizations.of(context).food),
Tab(text: MainLocalizations.of(context).car),
],
),
),
body: TabBarView(
children: [
TabA(),
TabB(),
],
),
),
),
);
The problem was that there were multiple MaterialApp widgets inside the app that were causing some conflicts regarding the localisation process. Removing the Redundant MaterialApp widgets fixed the issue.