flutter_i18n 0.0.3 flutter_i18n: ^0.0.3 copied to clipboard
i18n made easy for Flutter. With flutter_i18n you can make your app international, using just a simple .json file!
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_i18n/flutter_i18n_delegate.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(),
localizationsDelegates: [
FlutterI18nDelegate(false),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar:
new AppBar(title: new Text(FlutterI18n.translate(context, "title"))),
body: new Builder(builder: (BuildContext context) {
return new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(FlutterI18n.translate(context, "label.main")),
new FlatButton(
onPressed: () {
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text(
FlutterI18n.translate(context, "toastMessage")),
));
},
child: new Text(
FlutterI18n.translate(context, "button.clickMe")))
],
),
);
}),
);
}
}