首页 > 解决方案 > 颤振错误:没有名称为“keyboardType”的命名参数。键盘类型:TextInputType.text

问题描述

我是 Flutter 的新手,我想设置一个表单。这是我的代码:

const TextField(
              decoration: InputDecoration(
              labelText: 'Nom',
              hintText: 'Entrez votre nom',
              icon: Icon(
                Icons.person,
                color: Colors.blue,
                size: 25,
              ),
              keyboardType: TextInputType.text,
              autocorrect: true,
              autofocus: true,
            )),
            const TextField(
              decoration: InputDecoration(
              labelText: 'Prenom',
              hintText: 'Entrez votre Prenom',
              icon: Icon(
                Icons.person,
                color: Colors.blue,
                size: 25,
              ),
              keyboardType: TextInputType.text,
            )),
            const TextField(
              decoration: InputDecoration(
              labelText: 'Telephome',
              hintText: 'Entrez votre numero de telephone',
              icon: Icon(
                Icons.phone,
                color: Colors.blue,
                size: 25,
              ),
              keyboardType: TextInputType.number,
            )),
            const TextField(decoration: InputDecoration(
              labelText: 'Mot de passe',
              hintText: 'Entrez votre mot de passe',
              icon: Icon(
                Icons.lock,
                color: Colors.red,
                size: 25,
              ),
              keyboardType: TextInputType.visiblePassword,
              ObscureText: true,
            )),

当我运行时,我看到了这个错误:

lib/main.dart:48:15:错误:没有名为“keyboardType”的命名参数。键盘类型:TextInputType.text,^^^^^^^^^^^^ ../../flutter/packages/flutter/lib/src/material/input_decorator.dart:2522:9:上下文:找到这个候选人,但论点不匹配。const InputDecoration({ ^^^^^^^^^^^^^^^ lib/main.dart:61:15: 错误: 没有名为“keyboardType”的命名参数。keyboardType: TextInputType.text, ^^^ ^^^^^^^^^ ../../flutter/packages/flutter/lib/src/material/input_decorator.dart:2522:9: 上下文:找到了这个候选人,但参数不匹配。 InputDecoration({ ^^^^^^^^^^^^^^^ lib/main.dart:72:15: 错误: 没有名为“keyboardType”的命名参数。keyboardType: TextInputType.number, ^^^^ ^^^^^^^^ ../../flutter/packages/flutter/lib/src/material/input_decorator.dart:2522:9: 上下文:找到了这个候选人,但论点不匹配。const InputDecoration({ ^^^^^^^^^^^^^^^ lib/main.dart:82:15: 错误: 没有名为“keyboardType”的命名参数。keyboardType: TextInputType.visiblePassword, ^^^ ^^^^^^^^^ ../../flutter/packages/flutter/lib/src/material/input_decorator.dart:2522:9: 上下文:找到了这个候选人,但参数不匹配。 InputDecoration({ ^^^^^^^^^^^^^^^ ../../flutter/.pub-cache/hosted/pub.dartlang.org/pull_to_refresh-1.6.3/lib/src/smart_refresher .dart:273:21:错误:没有为类“BuildContext”定义方法“ancestorWidgetOfExactType”。^^^^^^^^^^^^ ../../flutter/packages/flutter/lib/src/material/input_decorator.dart:2522:9:上下文:找到了这个候选人,但论点没有匹配。const InputDecoration({ ^^^^^^^^^^^^^^^ ../../flutter/.pub-cache/hosted/pub.dartlang.org/pull_to_refresh-1.6.3/lib/src/ smart_refresher.dart:273:21:错误:没有为类“BuildContext”定义方法“ancestorWidgetOfExactType”。^^^^^^^^^^^^ ../../flutter/packages/flutter/lib/src/material/input_decorator.dart:2522:9:上下文:找到了这个候选人,但论点没有匹配。const InputDecoration({ ^^^^^^^^^^^^^^^ ../../flutter/.pub-cache/hosted/pub.dartlang.org/pull_to_refresh-1.6.3/lib/src/ smart_refresher.dart:273:21:错误:没有为类“BuildContext”定义方法“ancestorWidgetOfExactType”。

请帮我

标签: flutter

解决方案


试试下面的代码,我认为你的问题已经解决了。在此处参考文本字段

 TextField(
          keyboardType: TextInputType.text,
          autocorrect: true,
          autofocus: true,
          decoration: InputDecoration(
            labelText: 'Nom',
            hintText: 'Entrez votre nom',
            icon: Icon(
              Icons.person,
              color: Colors.blue,
              size: 25,
            ),
          ),
        ),
        TextField(
          keyboardType: TextInputType.text,
          decoration: InputDecoration(
            labelText: 'Prenom',
            hintText: 'Entrez votre Prenom',
            icon: Icon(
              Icons.person,
              color: Colors.blue,
              size: 25,
            ),
          ),
        ),
        TextField(
          keyboardType: TextInputType.number,
          decoration: InputDecoration(
            labelText: 'Telephome',
            hintText: 'Entrez votre numero de telephone',
            icon: Icon(
              Icons.phone,
              color: Colors.blue,
              size: 25,
            ),
          ),
        ),
        TextField(
          keyboardType: TextInputType.visiblePassword,
          obscureText: true,
          decoration: InputDecoration(
            labelText: 'Mot de passe',
            hintText: 'Entrez votre mot de passe',
            icon: Icon(
              Icons.lock,
              color: Colors.red,
              size: 25,
            ),
          ),
        ),

你的结果屏幕像->在此处输入图像描述


推荐阅读