1

How can I use optional parameters in given code of dart? when I remove the required keyword it shows error

class CustomInput extends StatelessWidget {
    final String hintText;
    final Function onChanged;
    final Function onSubmitted;
    final FocusNode focusedNode;
    final TextInputAction textInputAction;

    CustomInput({ required this.hintText,
        required this.onChanged,
        required this.onSubmitted,
        required this.focusedNode,
        required this.textInputAction});
}

I want to use different parameters of that class in different custom inputs like some parameters in Email field and some in Password field but it require all parameters for both...

Razvan Fulea
  • 437
  • 4
  • 13
  • If an optional parameter is no longer `required` you have to make it nullable (by adding `?`) as it may not otherwise be initialized. Or you could give it a default value. – Richard Heap Jan 06 '23 at 15:53
  • An optional parameter needs a default value to use if no argument is supplied. That default value either must be explicitly specified or it can be implicitly `null` if the optional parameter has a nullable type. – jamesdlin Jan 06 '23 at 17:40

1 Answers1

-1

If my understanding is correct, you want to have a Widget with multiple parameters, and you want to construct it based on various combinations between them. If that's correct, check out this.

Razvan Fulea
  • 437
  • 4
  • 13