Last active
October 27, 2020 05:50
-
-
Save HansMuller/57c569cf99997a6530eb05f64906042f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you take a look at this:
flutter/gallery#359