Skip to content

Instantly share code, notes, and snippets.

@ijoschek
Last active December 29, 2018 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijoschek/d856e56b3bf08f524f49bb5862380841 to your computer and use it in GitHub Desktop.
Save ijoschek/d856e56b3bf08f524f49bb5862380841 to your computer and use it in GitHub Desktop.
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