简体   繁体   English

参数类型“字符串函数(字符串)”不能分配给参数类型“FutureOr”<string> 功能(电话号码)'</string>

[英]The argument type 'String Function(String)' can't be assigned to the parameter type 'FutureOr<String> Function(PhoneNumber)'

I'm getting the error The argument type我收到错误参数类型

'String Function(String)' can't be assigned to the parameter type 'FutureOr Function(PhoneNumber)' 'String Function(String)' 不能分配给参数类型'FutureOr Function(PhoneNumber)'

when I try to validate a phone number in my code.当我尝试验证代码中的电话号码时。 I am trying to use IntlPhoneField.validator to validate the phone number entered in the phonefield but each time it throws this error and I cannot see where the problem is.我正在尝试使用 IntlPhoneField.validator 来验证在电话字段中输入的电话号码,但每次它都会抛出此错误,我看不出问题出在哪里。 I am using flutter 3.1.0.我正在使用 flutter 3.1.0。 Kindly assist.请协助。 Here is my code.这是我的代码。

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl_phone_field/country_picker_dialog.dart';
import 'package:intl_phone_field/intl_phone_field.dart';
import 'package:intl_phone_field/phone_number.dart';

class PhoneFieldWidget extends StatelessWidget {
  const PhoneFieldWidget(
      {Key key,
      this.onSaved,
      this.onChanged,
      this.validator,
      this.initialValue,
      this.hintText,
      this.errorText,
      this.labelText,
      this.obscureText,
      this.suffixIcon,
      this.isFirst,
      this.isLast,
      this.style,
      this.textAlign,
      this.suffix,
      this.initialCountryCode,
      this.countries})
      : super(key: key);

  final FormFieldSetter<PhoneNumber> onSaved;
  final ValueChanged<PhoneNumber> onChanged;
  final FormFieldValidator<String> validator;
  final String initialValue;
  final String hintText;
  final String errorText;
  final TextAlign textAlign;
  final String labelText;
  final TextStyle style;
  final bool obscureText;
  final String initialCountryCode;
  final List<String> countries;
  final bool isFirst;
  final bool isLast;
  final Widget suffixIcon;
  final Widget suffix;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: 20, bottom: 14, left: 20, right: 20),
      margin: EdgeInsets.only(left: 20, right: 20, top: topMargin, bottom: bottomMargin),
      decoration: BoxDecoration(
          color: Get.theme.primaryColor,
          borderRadius: buildBorderRadius,
          boxShadow: [
            BoxShadow(color: Get.theme.focusColor.withOpacity(0.1), blurRadius: 10, offset: Offset(0, 5)),
          ],
          border: Border.all(color: Get.theme.focusColor.withOpacity(0.05))),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Text(
            labelText ?? "",
            style: Get.textTheme.bodyText1,
            textAlign: textAlign ?? TextAlign.start,
          ),
          IntlPhoneField(
              key: key,
              onSaved: onSaved,
              onChanged: onChanged,
              validator: validator,
              initialValue: initialValue ?? '',
              initialCountryCode: initialCountryCode ?? 'DE',
              showDropdownIcon: false,
              pickerDialogStyle: PickerDialogStyle(countryNameStyle: Get.textTheme.bodyText2),
              style: style ?? Get.textTheme.bodyText2,
              textAlign: textAlign ?? TextAlign.start,
              decoration: InputDecoration(
                hintText: hintText ?? '',
                hintStyle: Get.textTheme.caption,
                floatingLabelBehavior: FloatingLabelBehavior.never,
                contentPadding: EdgeInsets.all(0),
                border: OutlineInputBorder(borderSide: BorderSide.none),
                focusedBorder: OutlineInputBorder(borderSide: BorderSide.none),
                enabledBorder: OutlineInputBorder(borderSide: BorderSide.none),
                suffixIcon: suffixIcon,
                suffix: suffix,
                errorText: errorText,
              )),
        ],
      ),
    );
  }

The error points to this line.错误指向这一行。

在此处输入图像描述

The validator of IntlPhoneField is defined as below. IntlPhoneFieldvalidator定义如下。 Try尝试

 final FutureOr<String?> Function(PhoneNumber?)? validator;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决参数类型'Future<file> 功能(地图<string, dynamic> )' 不能分配给参数类型'FutureOr<file> 在 Flutter</file></string,></file> - How to solve The argument type 'Future<File> Function(Map<String, dynamic>)' can't be assigned to the parameter type 'FutureOr<File> in Flutter 错误:不能将参数类型“字符串函数(字符串)”分配给参数类型“字符串? 函数(字符串?)? - Error: The argument type 'String Function(String)' can't be assigned to the parameter type 'String? Function(String?)?' 无法将参数类型“String Function(String)”分配给参数类型“String”? 函数(字符串?)? - The argument type 'String Function(String)' can't be assigned to the parameter type 'String? Function(String?)?' 参数类型 'String? 函数(字符串)'不能分配给参数类型'字符串? 函数(字符串?)? - The argument type 'String? Function(String)' can't be assigned to the parameter type 'String? Function(String?)?' 验证器问题:参数类型“字符串? 函数(字符串)'不能分配给参数类型'字符串? 函数(字符串?)? - Validator issue: The argument type 'String? Function(String)' can't be assigned to the parameter type 'String? Function(String?)?' Null 相关错误 - 参数类型“字符串? 函数(字符串)'不能分配给参数类型'字符串? 函数(字符串?)? - Null Related Error - The argument type 'String? Function(String)' can't be assigned to the parameter type 'String? Function(String?)?' 参数类型“Future Function(int, String, String, String)”不能分配给参数类型“void Function(int, String?, String?, String?)? - argument type 'Future Function(int, String, String, String)' can't be assigned to the parameter type 'void Function(int, String?, String?, String?)? 参数类型“函数”不能分配给参数类型“字符串? 函数(字符串?)? - The argument type 'Function' can't be assigned to the parameter type 'String? Function(String?)?' flutter 参数类型“void Function(String)”不能分配给参数类型“void Function(String?)?” 在 flutter - flutter The argument type 'void Function(String)' can't be assigned to the parameter type 'void Function(String?)?' in flutter 参数类型&#39;Future<dynamic> 函数(字符串)”不能分配给参数类型“无效函数(字符串?)?” - The argument type 'Future<dynamic> Function(String)' can't be assigned to the parameter type 'void Function(String?)?'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM