Home > Blockchain >  I can't get the country code in Flutter. Everything is either us or en
I can't get the country code in Flutter. Everything is either us or en

Time:01-07

I can't get the country code in Flutter. Everything is either us or en. It shows up as us or en even if I change the device's region or language. I want to show the language and region registered on the user's device.


  @override
  Widget build(BuildContext context) {
    Locale locale = Localizations.localeOf(context);
    String? localeCode = locale.countryCode;
    String? languageCode = locale.languageCode;

    return Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: [
          HomeScreen(localeCode, languageCode),
        ],
      ),
    );
  }
class PomodoroPage extends StatefulWidget {
  PomodoroPage(this.localeCode, this.languageCode);
  final String? localeCode;
  final String? languageCode;
  @override
  _PomodoroPageState createState() => _PomodoroPageState();
}


CodePudding user response:

import 'dart:io';

String localeName = Platform.localeName;

  • Related