0
votes

I just want to assign this funtion variable to the onChanged event but it keeps throwing errors

class TextFieldWidget extends StatelessWidget {
  final String hintText;
  final IconData prefixIcon;
  final IconData suffixIconData;
  final bool obscure;
  final Function onTextChanged;

  const TextFieldWidget({
    Key? key,
    required this.hintText,
    required this.prefixIcon,
    required this.suffixIconData,
    required this.obscure,
    required this.onTextChanged,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return TextField(
      onChanged: onTextChanged,
      style: TextStyle(
        color: Colors.orange,
        fontSize: 14.0,
      ), 

and i try calling it here

TextFieldWidget(
                hintText: 'Email',
                obscure: false,
                prefixIcon: Icons.email,
                suffixIconData: Icons.arrow_back,
                onTextChanged: (Value) => homeModel.isVisable(Value),
)
..

here is the home model

class HomeModel extends ChangeNotifier {
  //password is visable ?? the user must set this as activated by clicking the visable icon
  get isVisable => _isVisable;
  bool _isVisable = false;
  set isVisable(value) {
    _isVisable = value;
    notifyListeners();
  }

  //if email is valid set change
  get isValid => _isVisable;
  // ignore: unused_field
  bool _isValid = false;
  void isValidEmail(String input) {
    if (input == Global.ValidEmail.first) {
      _isValid = true;
    } else {
      _isValid = false;
    }
    notifyListeners();
  }
}

and here is the exact error lib/widgets/textFieldWidgetStyle1.dart:22:18: Error: The argument type 'Function' can't be assigned to the parameter type 'void Function(String)?'.

  • 'Function' is from 'dart:core'. onChanged: onTextChanged,
1

1 Answers

0
votes

change

onChanged: onTextChanged,

to

onChanged: onTextChanged as void Function(String)?,