【问题标题】:How to get country list in a dropdown, need only county list and country code如何在下拉列表中获取国家列表,只需要县列表和国家代码
【发布时间】:2022-08-22 22:43:10
【问题描述】:

I need like this -> click the image

如何在 Flutter 的下拉列表中获取国家列表,我只需要县列表和国家代码。

    标签: flutter


    【解决方案1】:

    这将为您提供带有国家代码的国家国旗下拉列表。 您可以找到国家代码列表here

    class dropdown extends StatelessWidget {
      
    
    const dropdown({
        Key? key,
        required this.locale,
      }) : super(key: key);
    
      final Locale? locale;
    
      @override
      Widget build(BuildContext context) {
        _getFlag(String code) {
          switch (code) {
    
        case 'es':
          return "??";
        case 'de':
          return "??";
        case 'fr':
          return "??";
        case 'nl':
          return "??";
        case 'zh':
          return "??";
        default:
          return "??";
      }
    }
    
    return Padding(
        padding: const EdgeInsets.all(8.0),
        child: DropdownButtonHideUnderline(
            child: DropdownButton(
          icon: const Icon(
            Icons.language,
            color: kPrimaryColor,
          ),
          items: I10n.all.map((locale) {
            final flag = _getFlag(locale.languageCode);
            return DropdownMenuItem(
              child: Center(
                  child: Text(
                flag,
                style: const TextStyle(fontSize: 20),
              )),
              value: locale,
              onTap: () {
                final provider =
                    Provider.of<LocaleProvider>(context, listen: false);
                provider.setLocale(locale);
              },
            );
          }).toList(),
          onChanged: (_) {},
        )));
    

    } }

    【讨论】:

      【解决方案2】:

      如果您还没有找到解决方案,请参考这个country_state_city 包。这可能是一个很大的帮助。

      【讨论】:

        猜你喜欢
        • 2013-02-27
        • 2011-02-27
        • 1970-01-01
        • 2022-01-16
        • 2011-01-20
        • 1970-01-01
        • 1970-01-01
        • 2010-11-22
        • 1970-01-01
        相关资源
        最近更新 更多