podcoder/Flutter-Localization-Demo

How to implement in StatelessWidget?

Closed this issue · 1 comments

FlutterLocalization.dart is statefull widget hence setState can be avail.

What if we are using StatelessWidget?
Code as below

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      supportedLocales: [
        Locale('fr',),
        Locale('ln',),
      ],
      localizationsDelegates: [
        AppLocalizationsDelegate(),
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate
      ],
      localeResolutionCallback: (locale, supportedLocales) {
        for (var supportedLocale in supportedLocales) {
          if (supportedLocale.languageCode == locale.languageCode &&
              supportedLocale.countryCode == locale.countryCode) {
            return supportedLocale;
          }
        }
        return supportedLocales.first;
      },
      title: 'Flutter Demo',
      theme: ThemeData(
          primaryColor: Color(int.parse("0xff02B9DF")),
          primaryTextTheme: TextTheme(title: TextStyle(color: Colors.white)),
          primaryIconTheme: IconThemeData(color: Colors.white)),

      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

Could you tell me, why do you want to use StatelessWidget?