Abdallah
Abdallah

Reputation: 31

The argument type 'void Function()?' can't be assigned to the parameter type 'void Function(String)?'

I'm getting this error trying to apply the concept of reusable component. can some one help please? I need to make both the onFieldSubmitted and onChanged a optional functions. also I tried just using Function to declear name of the function instead of VoidCallback but it didn't word. this is the code

Widget defaultTextBox({
  required TextEditingController inputController,
  required String boxLapel,
  VoidCallback? onSubmit,
  VoidCallback? changed,
  required VoidCallback pressed,
}) =>
    TextFormField(
      validator: (value) {
        if (value!.isEmpty) {
          return 'please enter password address';
        }
        return null;
      },
      controller: inputController,
      decoration: InputDecoration(
          labelText: boxLapel,
          labelStyle: TextStyle(fontSize: 20, color: Colors.black),
          border: OutlineInputBorder(
              borderRadius: BorderRadius.all(Radius.circular(9.0))),
          suffixIcon: IconButton(
            onPressed: pressed,
            icon: Icon(
               Icons.visibility),
          ),
          prefixIcon: Icon(
            Icons.lock,
            color: Colors.black,
          )),
      obscureText: true,
      keyboardType: TextInputType.visiblePassword,
       // error is here and here 
      onFieldSubmitted: onSubmit, // <-
      onChanged: changed, // <-
    );

Upvotes: 0

Views: 423

Answers (1)

Abdallah
Abdallah

Reputation: 31

I found a solution and I should declare the function as follow :

required String? Function(String?)? onSubmit,

Upvotes: 1

Related Questions