We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flutter: FormatException: Unexpected character (at character 36) {"language":"nl_NL","theme":"dark"}}
I think there is a problem with this package... it adds an extra } and then it crashes all the time.
Here is the code i use:
import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; main() async { await GetStorage.init(); runApp(MyApp()); } class SwigTranslations extends Translations { @override Map<String, Map<String, String>> get keys => { 'nl_NL': { 'title': 'Hello World %s NL', }, 'en_UK': { 'title': 'Hello World %s US', }, }; } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return GetMaterialApp( theme: ThemeData.light().copyWith(primaryColor: Colors.green), darkTheme: ThemeData.dark().copyWith(primaryColor: Colors.purple), translations: SwigTranslations(), home: MyHomePage(), ); } } class MyHomePage extends StatefulWidget { MyHomePage({Key key}) : super(key: key); @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { final box = GetStorage(); changeCurrentLanguage() { String currentLanguage = box.read('language') ?? 'nl_NL'; Get.updateLocale(Locale( currentLanguage.substring(0, 2), currentLanguage.substring(3, 5))); } changeCurrentTheme() async { if (box.read('theme') == 'dark') { Get.changeThemeMode(ThemeMode.light); box.write('theme', 'light'); } else { Get.changeThemeMode(ThemeMode.dark); box.write('theme', 'dark'); } } @override void initState() { changeCurrentTheme(); changeCurrentLanguage(); super.initState(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("title".trArgs(['John'])), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text(box.read('language') ?? 'Empty'), Text("title".trArgs(['John'])), Text("title".tr), RaisedButton( child: Text('Change locale to English'), onPressed: () { setState(() { box.write('language', 'en_UK'); changeCurrentLanguage(); }); // Get.updateLocale(Locale('en', 'UK')); }, ), RaisedButton( child: Text('Change locale to Netherlands'), onPressed: () { setState(() { box.write('language', 'nl_NL'); changeCurrentLanguage(); changeCurrentTheme(); }); // Get.updateLocale(Locale('en', 'UK')); }, ), ], ), ), // This trailing comma makes auto-formatting nicer for build methods. ); } }
The text was updated successfully, but these errors were encountered:
@JobMoll Same here. did you find a fix ?
Sorry, something went wrong.
No branches or pull requests
flutter: FormatException: Unexpected character (at character 36)
{"language":"nl_NL","theme":"dark"}}
I think there is a problem with this package... it adds an extra } and then it crashes all the time.
Here is the code i use:
The text was updated successfully, but these errors were encountered: