Home > Software design >  How to fix const Icon(Icons.person) Flutter error?
How to fix const Icon(Icons.person) Flutter error?

Time:11-07

Hi I keep getting an error when trying to run main.dart due to the following error:

          Padding(
            padding: const EdgeInsets.only(bottom: 10),
            child: FormHelper.inputFieldWidget(
              context,
              const Icon(Icons.person), <---- This line over here 
              "Username",
              "Username",<---- This line over here 

I have found this answer: Flutter Dev, did you know how to fix this icon?

but I tried it from VS code and android studio.

Error received:

error: The argument type 'Icon' can't be assigned to the parameter type 'String'. (argument_type_not_assignable at [...] lib\screens\login_page.dart:115)

Question:

Why I am getting this error and how to avoid it?

CodePudding user response:

You need to provide prefixIcon as one of the parameter, and add it after the two String.

 Padding(
            padding: const EdgeInsets.only(bottom: 10),
            child: FormHelper.inputFieldWidget(
              context,
              "Username",
              "Username",
              prefixIcon:Icon(Icons.person), <---- add prefixIcon here
             
  • Related