Home > Mobile >  Can I change locale on Stateful widget?
Can I change locale on Stateful widget?

Time:10-28

I tried to change calendar language from English to Korean. I think I don't have any errors while I type this code. But my locale isn't changed. Don't know why it didn't work.

this is my code. I already changed 'pubspec.yaml'

import 'package:flutter_localizations/flutter_localizations.dart'; // library

Widget build(BuildContext context) { 
return  MaterialApp(
  localizationsDelegates: [
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
  ],
  supportedLocales: [
    const Locale('ko', 'KR'),
  ],
  home: buildHomePage(),
);

Future<void> _selectrequestDate(BuildContext context) async {
final DateTime? pickedDate = await showDatePicker(
    context: context,
    initialDate: requestDate,
    firstDate: DateTime(2015),
    lastDate: DateTime(2050));
if (pickedDate != null && pickedDate != requestDate)
  setState(() {
    requestDate = pickedDate;
  });

How can I fix this problem? If I try this on new project, it works well.

CodePudding user response:

You can try with easy_localization packages, because on the lastest version the packages provides startLocale which overides device locale.

  • Related