- Launching lib/main.dart on Android SDK built for x86 in debug mode... Initializing gradle... Resolving dependencies... Running 'gradlew assembleDebug'... Built build/app/outputs/apk/debug/app-debug.apk (30.7MB). Installing build/app/outputs/apk/app.apk... I/FlutterActivityDelegate(22888): onResume setting current activity to this E/flutter (22888): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception: E/flutter (22888): type '_InternalLinkedHashMap' is not a subtype of type 'Map' where E/flutter (22888): _InternalLinkedHashMap is from dart:collection E/flutter (22888): String is from dart:core E/flutter (22888):
- Map is from dart:core E/flutter (22888): String is from dart:core E/flutter (22888): String is from dart:core E/flutter (22888):
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
class DemoLocalizations {
DemoLocalizations(this.locale);
final Locale locale;
static DemoLocalizations of(BuildContext context) {
return Localizations.of<DemoLocalizations>(context, DemoLocalizations);
}
Map<String, String> _sentences;
Future<bool> load() async {
String data = await rootBundle.loadString('resources/lang/${this.locale.languageCode}.json');
this._sentences = json.decode(data);
return true;
}
String trans(String key) {
return this._sentences[key];
}
}
class DemoLocalizationsDelegate extends LocalizationsDelegate<DemoLocalizations> {
const DemoLocalizationsDelegate();
@override
bool isSupported(Locale locale) => ['tr', 'en'].contains(locale.languageCode);
@override
Future<DemoLocalizations> load(Locale locale) async {
DemoLocalizations localizations = new DemoLocalizations(locale);
await localizations.load();
print("Load ${locale.languageCode}");
return localizations;
}
@override
bool shouldReload(DemoLocalizationsDelegate old) => false;
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
supportedLocales: [
const Locale('tr', 'TR'),
const Locale('en', 'US')
],
localizationsDelegates: [
const DemoLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
localeResolutionCallback: (Locale locale, Iterable<Locale> supportedLocales) {
for (Locale supportedLocale in supportedLocales) {
if (supportedLocale.languageCode == locale.languageCode || supportedLocale.countryCode == locale.countryCode) {
return supportedLocale;
}
}
return supportedLocales.first;
},
title: 'Flutter Internationalization',
home: new MyPage(),
);
}
}
class MyPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new Text(
DemoLocalizations.of(context).trans('hello_world')
),
),
);
}
}
void main() {
runApp(new MyApp());
}
I am trying to build small demo app to test Flutter internationalisation. I found https://github.com/anilcancakir/flutter-internationalization and try to test it. I am getting error that is in blow.
--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Code:
typedef void LocaleChangeCallback(Locale locale);
class APPLIC {
// List of supported languages
final List<String> supportedLanguages = ['en','tr', 'el', 'ru'];
// Returns the list of supported Locales
Iterable<Locale> supportedLocales() => supportedLanguages.map<Locale>((lang) => new Locale(lang, ''));
// Function to be invoked when changing the working language
LocaleChangeCallback onLocaleChanged;
///
/// Internals
///
static final APPLIC _applic = new APPLIC._internal();
factory APPLIC(){
return _applic;
}
APPLIC._internal();
}
APPLIC applic = new
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: [
_localeOverrideDelegate,
const TranslationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: applic.supportedLocales(),
title: (Translations.of(context).text('app_title')),
home: new MyHomePage(title: (Translations.of(context).text('app_title'))),
);
}
}
And
// TODO: 4) _MyHomePageState Class
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
// TODO: implement initState
super.initState();
_localeOverrideDelegate = new SpecificLocalizationDelegate(null);
applic.onLocaleChanged = onLocaleChange;
this.getCurrencyJsonData();
}
onLocaleChange(Locale locale){
setState((){
_localeOverrideDelegate = new SpecificLocalizationDelegate(locale);
});
}
Future<String> getCurrencyJsonData() async {
var response = await http.get(
Uri.encodeFull("https://secure.***********”),
headers: {'Accept': 'application/json'});
setState(() {
var resBody = json.decode(response.body);
currencyData = resBody[“currency”];
});
return "Success!";
}
// TODO: BUILD WIDGET
@override
Widget build(BuildContext context) {
if (currencyData == null){
return new Center(
child: new CircularProgressIndicator(
backgroundColor: lightMainGreen,
)
);
} else {
return new Scaffold(
// APPBAR
appBar: new AppBar(
title: new Text(
(Translations.of(context).text('main_title')),
style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.w500),
),
//elevation: 1.0,
backgroundColor: midMainGreen,
actions: <Widget>[
……..
……..
……..