flutter_localization_tut
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