change button language
This commit is contained in:
parent
1c21f59420
commit
4f41aff572
4
covas_mobile/l10n.yaml
Normal file
4
covas_mobile/l10n.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
arb-dir: lib/l10n
|
||||
template-arb-file: app_en.arb
|
||||
output-localization-file: app_localizations.dart
|
||||
output-class: AppLocalizations
|
@ -13,6 +13,9 @@ import '../pages/LoginDemo.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart'; // Import dotenv
|
||||
import 'package:encrypt_shared_preferences/provider.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
import '../locale_provider.dart';
|
||||
|
||||
class MyDrawer extends StatelessWidget with ShowAlertDialog {
|
||||
Future<void> logout(BuildContext context) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
@ -135,6 +138,42 @@ class MyDrawer extends StatelessWidget with ShowAlertDialog {
|
||||
builder: (_) => EditProfile())); // Close the drawer
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.language),
|
||||
title: Text('Language'),
|
||||
onTap: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
title: Text('Select Language'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: Icon(Icons.flag),
|
||||
title: Text('Français'),
|
||||
onTap: () {
|
||||
Provider.of<LocaleProvider>(context, listen: false)
|
||||
.setLocale(const Locale('fr'));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.flag_outlined),
|
||||
title: Text('English'),
|
||||
onTap: () {
|
||||
Provider.of<LocaleProvider>(context, listen: false)
|
||||
.setLocale(const Locale('en'));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
ListTile(
|
||||
leading: Icon(Icons.info),
|
||||
title: Text('About'),
|
||||
|
4
covas_mobile/lib/l10n/app_en.arb
Normal file
4
covas_mobile/lib/l10n/app_en.arb
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"@@locale": "en",
|
||||
"menu_list": "Event list menu"
|
||||
}
|
4
covas_mobile/lib/l10n/app_fr.arb
Normal file
4
covas_mobile/lib/l10n/app_fr.arb
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"@@locale": "fr",
|
||||
"menu_list": "Liste d'évènement"
|
||||
}
|
21
covas_mobile/lib/locale_provider.dart
Normal file
21
covas_mobile/lib/locale_provider.dart
Normal file
@ -0,0 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LocaleProvider with ChangeNotifier {
|
||||
Locale _locale = const Locale('en');
|
||||
|
||||
Locale get locale => _locale;
|
||||
|
||||
void setLocale(Locale locale) {
|
||||
if (!L10n.all.contains(locale)) return;
|
||||
|
||||
_locale = locale;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
class L10n {
|
||||
static final all = [
|
||||
const Locale('en'),
|
||||
const Locale('fr'),
|
||||
];
|
||||
}
|
@ -1,12 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'pages/LoginDemo.dart';
|
||||
import 'locale_provider.dart'; // <-- à adapter selon ton arborescence
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await MobileAds.instance.initialize();
|
||||
|
||||
runApp(MyApp());
|
||||
runApp(
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => LocaleProvider(),
|
||||
child: MyApp(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
|
@ -20,6 +20,9 @@ import '../classes/ad_helper.dart';
|
||||
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
||||
import '../classes/auth_service.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../locale_provider.dart'; // Créé plus loin
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@ -27,7 +30,10 @@ void main() async {
|
||||
await MobileAds.instance.initialize();
|
||||
await initializeDateFormatting("fr_FR", null);
|
||||
|
||||
runApp(const MyApp());
|
||||
runApp(ChangeNotifierProvider(
|
||||
create: (_) => LocaleProvider(),
|
||||
child: const MyApp(),
|
||||
));
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@ -35,16 +41,17 @@ class MyApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localeProvider = Provider.of<LocaleProvider>(context);
|
||||
return MaterialApp(
|
||||
localizationsDelegates: [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: [
|
||||
const Locale('fr', 'FR'),
|
||||
],
|
||||
home: const ListItemMenu(),
|
||||
supportedLocales: [const Locale('fr', 'FR'), const Locale('en')],
|
||||
locale: localeProvider.locale,
|
||||
home: Builder(builder: (context) => ListItemMenu()),
|
||||
debugShowCheckedModeBanner: false,
|
||||
);
|
||||
}
|
||||
@ -608,9 +615,11 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
final localeProvider = Provider.of<LocaleProvider>(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Item list menu"),
|
||||
title: Text(loc?.menu_list ?? "Item list menu"),
|
||||
backgroundColor: Colors.blue,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
|
@ -565,6 +565,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.6"
|
||||
nested:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: nested
|
||||
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
path:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -701,6 +709,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.9.1"
|
||||
provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: provider
|
||||
sha256: "4abbd070a04e9ddc287673bf5a030c7ca8b685ff70218720abab8b092f53dd84"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.5"
|
||||
shared_preferences:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -55,6 +55,7 @@ dependencies:
|
||||
mapbox_gl: ^0.16.0
|
||||
google_mobile_ads: ^5.3.1
|
||||
encrypt_shared_preferences: ^0.8.8
|
||||
provider: ^6.1.2 # ou la dernière version
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Loading…
x
Reference in New Issue
Block a user