【问题标题】:Flutter : The argument type 'void Function(Country)' can't be assigned to the parameter type 'void Function(Country?)?'Flutter:无法将参数类型“void Function(Country)”分配给参数类型“void Function(Country?)?”
【发布时间】:2021-11-06 08:52:50
【问题描述】:

我在使用 country_currency_pickers 时遇到了一个错误,我想这是因为该函数应该变成空安全,但我不知道该怎么做。提前感谢您的帮助!

Widget _buildDropdownItem(Country country) => Container(
    child: Row(
      children: <Widget>[
        CountryPickerUtils.getDefaultFlagImage(country),
        SizedBox(
          width: 8.0,
        ),
        Text("+${country.phoneCode}(${country.isoCode})"),
      ],
    ),
  );
                            CurrencyPickerDropdown(
                            itemBuilder: _buildCurrencyDropdownItem,
                            initialValue: 'INR',
                            onValuePicked: (Country countryvalue) {
                              print("${country.name}");
                            },
                          )

【问题讨论】:

  • 函数_buildCurrencyDropdownItem在哪里?

标签: flutter dart dart-null-safety


【解决方案1】:

只需替换这个

onValuePicked: (Country countryvalue) {
    print("${country.name}");
},

onValuePicked: (Country? countryvalue) {
    print("${country.name}");
},

【讨论】:

  • 我已经尝试过了,但它无论如何都会在红色 _buildDropdownItem 和函数 onValuePicked 下划线并出现此错误
猜你喜欢
  • 2021-09-01
  • 2021-09-01
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 2021-10-22
  • 2021-02-12
  • 1970-01-01
  • 2020-05-15
相关资源
最近更新 更多