I'm using ARB files along with code generation for my internalization solution for my flutter app. Everything seems to be work as expecting, but I do have one problem. I can't get the options in the drop down lists and my bottom bar to switch languages.
Here is my locale.dart file
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'dart:async';
import 'package:manchester_maps/l10n/messages_all.dart';
class AppLocalizations {
static Future<AppLocalizations> load(Locale locale) {
final String name =
locale.countryCode.isEmpty ? locale.languageCode : locale.toString();
final String localeName = Intl.canonicalizedLocale(name);
return initializeMessages(localeName).then((bool _) {
Intl.defaultLocale = localeName;
return AppLocalizations();
});
}
static AppLocalizations of(BuildContext context) {
return Localizations.of<AppLocalizations>(context, AppLocalizations);
}
String get title {
return Intl.message(
'Manchester Maps',
name: 'title',
desc: 'The name of the application',
);
}
String get pageTitleMyPlaces {
return Intl.message('My Places',
name: 'pageTitleMyPlaces', desc: 'The My Places Title');
}
String get pageTitleSafetyInfo {
return Intl.message('Safety Info',
name: 'pageTitleSafetyInfo', desc: 'The Safety Info Title');
}
String get pageTitleSettings {
return Intl.message('Settings',
name: 'pageTitleSettings', desc: 'The Safety Info Title');
}
String get drawerResidences {
return Intl.message('Residences',
name: 'drawerResidences',
desc: 'The Residences option on the sliding nav bar');
}
...
...
...
class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
const AppLocalizationsDelegate();
@override
bool isSupported(Locale locale) {
return ['en', 'es', 'fr', 'hi', 'ar', 'ru', 'zh', 'ja']
.contains(locale.languageCode);
}
@override
Future<AppLocalizations> load(Locale locale) {
return AppLocalizations.load(locale);
}
@override
bool shouldReload(AppLocalizationsDelegate old) {
return false;
}
}
I have a number of Lists (see below) and this is where I am having issues.
In the code below, I have an error with the context.
class _SettingsFormState extends State<SettingsForm> {
// TODO: Change this to retrieve data from local database
bool _allowTilt = true;
bool _enableRotate = true;
bool _enableZoom = true;
bool _showTraffic = false;
bool _showCompass = true;
// Properties for Theme Timing. This denotes whether the theme switches
// from day to night automatically at sunset and sunrise times
List<String> _themeTiming = [**AppLocalizations.of(context).settingsDDLThemeDay**, 'Night', 'Auto'];
String _selectedThemeTiming;
// List of Day Themes
List<String> _dayTheme = [
'Standard',
'Retro',
'Simple Bright',
'Map Posters',
'Bentley',
'Clean Cut'
];
String _selectedDayTheme;
// List of Night Themea
List<String> _nightTheme = [
'Night',
'Simple Night',
'Dark',
'Midnight Commander',
'Aubergine',
'Cobalt'
];
String _selectedNightTheme;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
...
...
...
Any help with this is appreciated as it is driving me nuts.