-
-
Save ijoschek/d856e56b3bf08f524f49bb5862380841 to your computer and use it in GitHub Desktop.
flutter_localization_tut
This file contains 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 'localizations.dart'; //import your localizations.dart | |
import 'package:flutter_localizations/flutter_localizations.dart'; //import this | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
onGenerateTitle: (BuildContext context) => | |
AppLocalizations.of(context).title(), | |
localizationsDelegates: [ | |
const AppLocalizationsDelegate(), | |
GlobalMaterialLocalizations.delegate, | |
GlobalWidgetsLocalizations.delegate, | |
], | |
supportedLocales: [ | |
const Locale('en', ''), | |
const Locale('de', ''), | |
const Locale('ru', ''), | |
], | |
//... | |
); | |
} | |
} | |
//... | |
class _MyHomePageState extends State<MyHomePage> { | |
//... | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(AppLocalizations.of(context).title()), //change this | |
), | |
//... | |
children: <Widget>[ | |
Text(AppLocalizations.of(context).text(_counter)), //add this | |
], | |
//... | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment