changement de langue ok sur drawer

This commit is contained in:
Valentin CZERYBA 2025-07-02 22:35:53 +02:00
parent e2195e6500
commit 75b443758a
4 changed files with 38 additions and 14 deletions

View File

@ -15,6 +15,7 @@ import 'package:encrypt_shared_preferences/provider.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../locale_provider.dart'; import '../locale_provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class MyDrawer extends StatelessWidget with ShowAlertDialog { class MyDrawer extends StatelessWidget with ShowAlertDialog {
Future<void> logout(BuildContext context) async { Future<void> logout(BuildContext context) async {
@ -90,6 +91,8 @@ class MyDrawer extends StatelessWidget with ShowAlertDialog {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final loc = AppLocalizations.of(context);
final localeProvider = Provider.of<LocaleProvider>(context);
return Drawer( return Drawer(
child: ListView( child: ListView(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
@ -110,7 +113,7 @@ class MyDrawer extends StatelessWidget with ShowAlertDialog {
// Drawer Items // Drawer Items
ListTile( ListTile(
leading: Icon(Icons.home), leading: Icon(Icons.home),
title: Text('Home'), title: Text(loc?.home ?? "Home"),
onTap: () { onTap: () {
Navigator.pushReplacement( Navigator.pushReplacement(
context, MaterialPageRoute(builder: (_) => ListItemMenu())); context, MaterialPageRoute(builder: (_) => ListItemMenu()));
@ -120,7 +123,7 @@ class MyDrawer extends StatelessWidget with ShowAlertDialog {
), ),
ListTile( ListTile(
leading: Icon(Icons.settings), leading: Icon(Icons.settings),
title: Text('Settings'), title: Text(loc?.settings ?? 'Settings'),
onTap: () { onTap: () {
Navigator.pushReplacement( Navigator.pushReplacement(
context, context,
@ -130,7 +133,7 @@ class MyDrawer extends StatelessWidget with ShowAlertDialog {
), ),
ListTile( ListTile(
leading: Icon(Icons.account_circle), leading: Icon(Icons.account_circle),
title: Text('Update profile'), title: Text(loc?.update_profile ?? 'Update profile'),
onTap: () { onTap: () {
Navigator.pushReplacement( Navigator.pushReplacement(
context, context,
@ -140,18 +143,18 @@ class MyDrawer extends StatelessWidget with ShowAlertDialog {
), ),
ListTile( ListTile(
leading: Icon(Icons.language), leading: Icon(Icons.language),
title: Text('Language'), title: Text(loc?.language ?? 'Language'),
onTap: () { onTap: () {
showDialog( showDialog(
context: context, context: context,
builder: (_) => AlertDialog( builder: (_) => AlertDialog(
title: Text('Select Language'), title: Text(loc?.select_language ?? 'Select Language'),
content: Column( content: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
ListTile( ListTile(
leading: Icon(Icons.flag), leading: Icon(Icons.flag),
title: Text('Français'), title: Text(loc?.french ?? 'Français'),
onTap: () { onTap: () {
Provider.of<LocaleProvider>(context, listen: false) Provider.of<LocaleProvider>(context, listen: false)
.setLocale(const Locale('fr')); .setLocale(const Locale('fr'));
@ -160,7 +163,7 @@ class MyDrawer extends StatelessWidget with ShowAlertDialog {
), ),
ListTile( ListTile(
leading: Icon(Icons.flag_outlined), leading: Icon(Icons.flag_outlined),
title: Text('English'), title: Text(loc?.english ?? 'English'),
onTap: () { onTap: () {
Provider.of<LocaleProvider>(context, listen: false) Provider.of<LocaleProvider>(context, listen: false)
.setLocale(const Locale('en')); .setLocale(const Locale('en'));
@ -176,15 +179,15 @@ class MyDrawer extends StatelessWidget with ShowAlertDialog {
ListTile( ListTile(
leading: Icon(Icons.info), leading: Icon(Icons.info),
title: Text('About'), title: Text(loc?.about ?? 'About'),
onTap: () { onTap: () {
showAlertDialog( showAlertDialog(context, loc?.about ?? 'About',
context, 'About', "Version 0.0.1"); // Close the drawer "Version 0.0.1"); // Close the drawer
}, },
), ),
ListTile( ListTile(
leading: Icon(Icons.logout), leading: Icon(Icons.logout),
title: Text('Log out'), title: Text(loc?.log_out ?? 'Log out'),
onTap: () async { onTap: () async {
logout(context); logout(context);
// Close the drawer // Close the drawer

View File

@ -1,4 +1,13 @@
{ {
"@@locale": "en", "@@locale": "en",
"menu_list": "Event list menu" "menu_list": "Event list menu",
"language": "Language",
"home": "Home",
"settings": "Settings",
"update_profile": "Update profile",
"about": "About",
"log_out": "Log out",
"french": "French",
"english": "English",
"select_language": "Select language"
} }

View File

@ -1,4 +1,13 @@
{ {
"@@locale": "fr", "@@locale": "fr",
"menu_list": "Liste d'évènement" "menu_list": "Liste d'évènement",
"language": "Langue",
"home": "Accueil",
"settings": "Paramètres",
"update_profile": "Modifier profil",
"about": "À propos",
"log_out": "Se déconnecter",
"french": "Français",
"english": "Anglais",
"select_language": "Selectionne la langue"
} }

View File

@ -864,8 +864,11 @@ class _MyHomePageState extends State<ListItemMenu> {
final startDate = DateTime.parse(post.startDate!); final startDate = DateTime.parse(post.startDate!);
//final date = DateFormat.yMd().format(startDate); //final date = DateFormat.yMd().format(startDate);
//final time = DateFormat.Hm().format(startDate); //final time = DateFormat.Hm().format(startDate);
final locale =
Provider.of<LocaleProvider>(context).locale?.toString() ??
'en_US';
final dateLongue = final dateLongue =
DateFormat('EEEE d MMMM y', 'fr_FR').format(startDate); DateFormat('EEEE d MMMM y', locale).format(startDate);
return ListTile( return ListTile(
title: Text('${post.name!}'), title: Text('${post.name!}'),
subtitle: Text('${post.place!}\n${dateLongue}'), subtitle: Text('${post.place!}\n${dateLongue}'),