Skip to content

Instantly share code, notes, and snippets.

@HansMuller
Last active October 27, 2020 05:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HansMuller/57c569cf99997a6530eb05f64906042f to your computer and use it in GitHub Desktop.
Save HansMuller/57c569cf99997a6530eb05f64906042f to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'l10n/app_localizations.dart'; // L10N
class AppLocale extends StatelessWidget {
const AppLocale({ Key key, this.locale, this.child }) : super(key: key);
final Locale locale;
final Widget child;
@override
Widget build(BuildContext context) {
return Localizations.override(
locale: locale,
context: context,
child: child,
);
}
}
class HelloWorld extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(child: Text(AppLocalizations.of(context).helloWorld)); // L10N
}
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates, // L10N
supportedLocales: AppLocalizations.supportedLocales, // L10N
home: AppLocale(
locale: const Locale('es'),
child: Scaffold(
body: Center(
child: HelloWorld(),
),
),
),
);
}
}
void main() {
runApp(App());
}
@Megidd
Copy link

Megidd commented Oct 27, 2020

Can you take a look at this:

flutter/gallery#359

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment