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

Karios

I'm getting the error The argument type

'String Function(String)' can't be assigned to the parameter type '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. I am using 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.

enter image description here

Yeasin Sheikh

The validator of IntlPhoneField is defined as below. Try

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Dart: The argument type 'String' can't be assigned to the parameter type 'FutureOr<String>

Dart - The argument type 'String' can't be assigned to the parameter type 'String'

The argument type String? can't be assigned to the parameter type String

The argument type 'String' can't be assigned to the parameter type 'String'

The argument type 'String"?"' can't be assigned to the parameter type 'String'

Argument type String? can't be assigned to the parameter type 'String'

Error: The argument type 'String?' can't be assigned to the parameter type 'String'

The argument type 'String' can't be assigned to the parameter type 'TextEditingController?'

The argument type 'RxString' can't be assigned to the parameter type 'String'

The argument type 'Object?' can't be assigned to the parameter type 'String'

The argument type 'String' can't be assigned to the parameter type 'Uri'

The argument type 'String' can't be assigned to the parameter type 'Source'

The argument type 'Object?' can't be assigned to the parameter type 'int'/ 'string'

The argument type 'String' can't be assigned to the parameter type 'Uri'. Flutter

The argument type 'Future<dynamic>' can't be assigned to the parameter type 'String'

The argument type 'String' can't be assigned to the parameter type 'Directory'

The argument type 'Object?' can't be assigned to the parameter type 'String?

error: The argument type 'Object?' can't be assigned to the parameter type 'String'

The argument type 'Object' can't be assigned to the parameter type 'String'

The argument type 'Object?' can't be assigned to the parameter type 'String'.?

The argument type 'Object?' can't be assigned to the parameter type 'String'. 1

The argument type 'MaterialPageRoute<dynamic>' can't be assigned to the parameter type 'String'

The argument type 'List<String>' can't be assigned to the parameter type 'String'.dart(argument_type_not_assignable) on the Dart

The argument type 'List<dynamic>' can't be assigned to the parameter type 'FutureOr<List<T>>?'

Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't

error: The argument type '() → Null' can't be assigned to the parameter type '(Null) → FutureOr<dynamic>'

error: The argument type '(File) → Future<dynamic>' can't be assigned to the parameter type '(dynamic) → FutureOr<dynamic>'

Flutter error: The argument type 'Future<Object?> Function()' can't be assigned to the parameter type 'FutureOr<dynamic> Function(dynamic)'

The argument type 'Object?' can't be assigned to the parameter type 'FutureOr<Uint8List>?'