【问题标题】:Flutter Error: No named parameter with the name 'keyboardType'.keyboardType: TextInputType.textFlutter 错误:没有名为“keyboardType”的命名参数。键盘类型:TextInputType.text
【发布时间】:2021-11-26 11:39:44
【问题描述】:

我是 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:上下文:找到了这个候选人,但参数不匹配。 常量输入装饰({ ^^^^^^^^^^^^^^^ lib/main.dart:61:15:错误:没有名为“keyboardType”的命名参数。 键盘类型:TextInputType.text, ^^^^^^^^^^^^^ ../../flutter/packages/flutter/lib/src/material/input_decorator.dart:2522:9:上下文:找到了这个候选人,但参数不匹配。 常量输入装饰({ ^^^^^^^^^^^^^^^ lib/main.dart:72:15:错误:没有名为“keyboardType”的命名参数。 键盘类型:TextInputType.number, ^^^^^^^^^^^^^ ../../flutter/packages/flutter/lib/src/material/input_decorator.dart:2522:9:上下文:找到了这个候选人,但参数不匹配。 常量输入装饰({ ^^^^^^^^^^^^^^^ lib/main.dart:82:15:错误:没有名为“keyboardType”的命名参数。 键盘类型:TextInputType.visiblePassword, ^^^^^^^^^^^^^ ../../flutter/packages/flutter/lib/src/material/input_decorator.dart:2522:9:上下文:找到了这个候选人,但参数不匹配。 常量输入装饰({ ^^^^^^^^^^^^^^^ ../../flutter/.pub-cache/hosted/pub.dartlang.org/pull_to_refresh-1.6.3/lib/src/smart_refresher.dart:273:21:错误:未定义方法“ancestorWidgetOfExactType”对于“BuildContext”类。

  • “BuildContext”来自“package:flutter/src/widgets/framework.dart”(“../../flutter/packages/flutter/lib/src/widgets/framework.dart”)。 尝试将名称更正为现有方法的名称,或定义名为“ancestorWidgetOfExactType”的方法。 返回上下文?.ancestorWidgetOfExactType(SmartRefresher); ^^^^^^^^^^^^^^^^^^^^^^^^^ ../../flutter/.pub-cache/hosted/pub.dartlang.org/pull_to_refresh-1.6.3/lib/src/smart_refresher.dart:277:41:错误:找不到方法:'TypeMatcher'。 返回上下文?.ancestorStateOfType(TypeMatcher()); ^^^^^^^^^^^^ ../../flutter/.pub-cache/hosted/pub.dartlang.org/pull_to_refresh-1.6.3/lib/src/smart_refresher.dart:277:21:错误:未定义方法“ancestorStateOfType”对于“BuildContext”类。
  • “BuildContext”来自“package:flutter/src/widgets/framework.dart”(“../../flutter/packages/flutter/lib/src/widgets/framework.dart”)。 尝试将名称更正为现有方法的名称,或定义名为“ancestorStateOfType”的方法。 返回上下文?.ancestorStateOfType(TypeMatcher()); ^^^^^^^^^^^^^^^^^^^ ../../flutter/.pub-cache/hosted/pub.dartlang.org/pull_to_refresh-1.6.3/lib/src/smart_refresher.dart:1003:20:错误:未定义方法“inheritFromWidgetOfExactType”对于“BuildContext”类。
  • “BuildContext”来自“package:flutter/src/widgets/framework.dart”(“../../flutter/packages/flutter/lib/src/widgets/framework.dart”)。 尝试将名称更正为现有方法的名称,或定义名为“inheritFromWidgetOfExactType”的方法。 返回 context.inheritFromWidgetOfExactType(RefreshConfiguration); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ../../flutter/.pub-cache/hosted/pub.dartlang.org/pull_to_refresh-1.6.3/lib/src/internals/indicator_wrap.dart:631:9:错误:“ValueNotifier”类型的值不能分配给“ValueNotifier”类型的变量。
  • “ValueNotifier”来自“package:flutter/src/foundation/change_notifier.dart”(“../../flutter/packages/flutter/lib/src/foundation/change_notifier.dart”)。 ? refresher.controller.headerMode

请帮帮我

【问题讨论】:

    标签: flutter


    【解决方案1】:

    试试下面的代码我认为你的问题已经解决了。参考文本框here

     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,
                ),
              ),
            ),
    

    你的结果屏幕喜欢->

    【讨论】:

      【解决方案2】:
      TextFormField(
                                keyboardType: TextInputType.number,
                                controller: stepcontroller,
                                focusNode: _focusNodes[0],
                                decoration: InputDecoration(
                                  labelText: "Enter Step",
                                  labelStyle: TextStyle(
                                    color: _focusNodes[0].hasFocus
                                        ? appcolor
                                        : Colors.grey,
                                    // fontSize: 24.0
                                  ),
                                  focusedBorder: OutlineInputBorder(
                                    borderSide: const BorderSide(
                                        color: appcolor, width: 2.0),
                                    // borderRadius: BorderRadius.circular(25.0),
                                  ),
                                  // prefixIcon: Icon(
                                  //   Icons.person,
                                  //   color: _focusNodes[0].hasFocus
                                  //       ? Colors.teal
                                  //       : Colors.grey,
                                  // ),
                                ),
                                validator: (value) {
                                  if (value.isEmpty) {
                                    return "   Step  cant be empty";
                                  } else if (value.length > contactlist.length) {
                                    return "step out of range";
                                  }
                                },
                              ),
      

      你可以试试这个,它会打开数字键盘

      【讨论】:

        【解决方案3】:

        请参阅此链接以清楚了解 Flutter 中的 textfiled 属性。

        https://api.flutter.dev/flutter/material/TextField-class.html

        【讨论】:

          猜你喜欢
          • 2023-01-16
          • 2021-05-21
          • 2022-01-17
          • 2021-12-11
          • 1970-01-01
          • 2023-01-03
          • 2021-06-18
          • 2022-01-17
          • 2011-12-10
          相关资源
          最近更新 更多