Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振类构造函数错误-“@这是必须的。”;_Flutter_Dart_Constructor_Default Constructor - Fatal编程技术网

Flutter 颤振类构造函数错误-“@这是必须的。”;

Flutter 颤振类构造函数错误-“@这是必须的。”;,flutter,dart,constructor,default-constructor,Flutter,Dart,Constructor,Default Constructor,在一个类的构造函数中,我得到了几个错误,因为它说默认情况下分配了null值,并且该值是不允许的。我也无法初始化它们,因为它们已修改了最终版本。我给你留下代码和错误信息。提前谢谢 代码: 错误: lib/widgets/custom_input.dart:13:11: Error: The parameter 'key' can't have a value of 'null' because of its type 'Key', but the implicit default value is

在一个类的构造函数中,我得到了几个错误,因为它说默认情况下分配了null值,并且该值是不允许的。我也无法初始化它们,因为它们已修改了最终版本。我给你留下代码和错误信息。提前谢谢

代码:

错误:

lib/widgets/custom_input.dart:13:11: Error: The parameter 'key' can't have a value of 'null' because of its type 'Key', but the implicit default value is 'null'.
 - 'Key' is from 'package:flutter/src/foundation/key.dart' ('../../../snap/flutter/common/flutter/packages/flutter/lib/src/foundation/key.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
      Key key,
          ^^^
lib/widgets/custom_input.dart:14:22: Error: The parameter 'icon' can't have a value of 'null' because of its type 'IconData', but the implicit default value is 'null'.
 - 'IconData' is from 'package:flutter/src/widgets/icon_data.dart' ('../../../snap/flutter/common/flutter/packages/flutter/lib/src/widgets/icon_data.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
      @required this.icon,
                     ^^^^
lib/widgets/custom_input.dart:15:22: Error: The parameter 'placeholder' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
      @required this.placeholder,
                     ^^^^^^^^^^^
lib/widgets/custom_input.dart:16:22: Error: The parameter 'textController' can't have a value of 'null' because of its type 'TextEditingController', but the implicit default value is 'null'.
 - 'TextEditingController' is from 'package:flutter/src/widgets/editable_text.dart' ('../../../snap/flutter/common/flutter/packages/flutter/lib/src/widgets/editable_text.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
      @required this.textController,
                     ^^^^^^^^^^^^^^

删除
@

 {
  final IconData icon;
  final String placeholder;
  final TextEditingController textController;
  final TextInputType keyboardType;
  final bool isPassword;

  const CustomInput ({
      required Key key,
      required this.icon,
      required this.placeholder,
      required this.textController,
      this.keyboardType = TextInputType.text,
      this.isPassword = false
  }) : super(key:key);

我见过“需要”或“需要”使用过几次,但从来没有理解过您最欢迎的差异,请考虑将此标记为您的问题的解决方案。在functions.De nada的可选参数中使用@required@Grafeno30非常感谢@HuthaifaSorry@Huthaifa
 {
  final IconData icon;
  final String placeholder;
  final TextEditingController textController;
  final TextInputType keyboardType;
  final bool isPassword;

  const CustomInput ({
      required Key key,
      required this.icon,
      required this.placeholder,
      required this.textController,
      this.keyboardType = TextInputType.text,
      this.isPassword = false
  }) : super(key:key);