In the constructor of a class I get several errors because it says that a null value is assigned by default and that value cannot be allowed. I can't initialize them either because they have the final modified. I leave you the code and the error messages. Thanks in advance
Code:
{
final IconData icon;
final String placeholder;
final TextEditingController textController;
final TextInputType keyboardType;
final bool isPassword;
const CustomInput ({
Key key,
@required this.icon,
@required this.placeholder,
@required this.textController,
this.keyboardType = TextInputType.text,
this.isPassword = false
}) : super(key:key);
Error:
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,
^^^^^^^^^^^^^^
remove the @
{
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With