Created
May 17, 2023 19:35
-
-
Save risaddex/a9cdb04903cf7b251be452a9d8defd34 to your computer and use it in GitHub Desktop.
Exemplo de como trocar o local em uma aplicação flutter manualmente.
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_gen/gen_l10n/app_localizations.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:guedder/shared/util/loc.dart'; | |
void main() { | |
WidgetsFlutterBinding.ensureInitialized(); | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatefulWidget { | |
const MyApp({super.key}); | |
@override | |
State<MyApp> createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
Locale localSelecionado = const Locale('pt', 'BR'); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData(colorSchemeSeed: Colors.green), | |
title: 'Material App', | |
home: Scaffold( | |
appBar: AppBar( | |
title: Builder(builder: (ctx) { | |
return Text(ctx.loc.hello_title); | |
}), | |
), | |
body: Center( | |
child: Builder( | |
builder: (ctx) { | |
return Column( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
DropdownButton<Locale>( | |
value: localSelecionado, | |
items: [ | |
DropdownMenuItem( | |
value: Locale('pt'), | |
child: Text('Português'), | |
), | |
], | |
onChanged: (novoLocal) { | |
setState(() { | |
localSelecionado = novoLocal ?? localSelecionado; | |
}); | |
}, | |
), | |
Text(ctx.loc.hello_world) | |
], | |
); | |
}, | |
), | |
), | |
), | |
localizationsDelegates: AppLocalizations.localizationsDelegates, | |
supportedLocales: AppLocalizations.supportedLocales, | |
locale: localSelecionado, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment