如何修复const图标(Icons.person)颤振错误?



嗨,我一直得到一个错误,当试图运行main。由于以下错误导致的Dart:

          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 

我找到了这个答案:Flutter Dev,你知道如何修复这个图标吗?

但是我从VS code和android studio尝试过。

错误收到:

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

问题:

为什么我得到这个错误,如何避免它?

您需要提供prefixIcon作为参数之一,并将其添加到两个String之后。

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

相关内容

最新更新