Instantly share code, notes, and snippets.

@ijoschek /.\lib\main.dart Secret
Last active Dec 29, 2018

Embed
What would you like to do?
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