Last active
September 4, 2018 11:13
-
-
Save rohan20/4fd4d0fc7709dd758abbe7f5cd7c63c7 to your computer and use it in GitHub Desktop.
flutter-localizations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_localizations/flutter_localizations.dart'; | |
import 'package:your_app_package/services/localization/app_translations_delegate.dart'; | |
import 'package:your_app_package/screens/home_page.dart'; | |
import 'application.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
AppTranslationsDelegate _newLocaleDelegate; | |
@override | |
void initState() { | |
super.initState(); | |
_newLocaleDelegate = AppTranslationsDelegate(newLocale: null); | |
application.onLocaleChanged = onLocaleChange; | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: HomePage(), | |
localizationsDelegates: [ | |
_newLocaleDelegate, | |
const AppTranslationsDelegate(), | |
//provides localised strings | |
GlobalMaterialLocalizations.delegate, | |
//provides RTL support | |
GlobalWidgetsLocalizations.delegate, | |
], | |
supportedLocales: application.supportedLocales(), | |
); | |
} | |
void onLocaleChange(Locale locale) { | |
setState(() { | |
_newLocaleDelegate = AppTranslationsDelegate(newLocale: locale); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment