localized 2.0.3 localized: ^2.0.3 copied to clipboard
String extensions for different localizations and a translation utility without additional efforts.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:localized/localized.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final locales = [
Locale('de', 'DE'),
Locale('en', 'EN'),
Locale('ru', 'RU'),
];
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
supportedLocales: locales,
localizationsDelegates: [
LocalizationService.delegate(locales: locales),
],
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('title'.localized(context)),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'amount_of_clicks'.localized(context),
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'increase'.localized(context),
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}