I'm creating a PopupMenuButton
to change the language of the app locally but I don't know how to load a different language.
This is the Widget that I'm creating to change the language and I want to set the app language to the value of the PopupMenu item.
import 'package:flutter/material.dart';
import '../generated/l10n.dart';
class ChangeLanguage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PopupMenuButton(
offset: const Offset(0, 40),
onSelected: (value) {
//set language to value
print(L.current);
print(Localizations.localeOf(context).toString());
},
itemBuilder: (BuildContext context) => [
PopupMenuItem(
value: "de",
child: Text(
"Deutsch",
style: Theme.of(context).textTheme.bodyText2,
)),
PopupMenuItem(
value: "en",
child: Text(
"English",
style: Theme.of(context).textTheme.bodyText2,
)),
],
);
}
}
I have implemented flutter_localizations and intl in the main.dart file like this:
localizationsDelegates: [
L.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: L.delegate.supportedLocales,
The supported languages are en
and de
and generated with the intl package.