registerOnTouched method

  1. @override
void registerOnTouched(
  1. TouchFunction callback
)

Set the function to be called when the control is touched.

A control's touched state is most commonly used to determine whether or not to show a validation error (for example, many forms would not want to show a required field as having an error before it's been interacted with).

Idiomatically, the control is considered touched once it has received a blur event. Certain controls, such as a dropdown select, may want to consider the control as touched if the user has opened and then closed the list of options.

See TouchHandler for the default idiomatic implementation.

Implementation

@override
void registerOnTouched(callback) {
  late StreamSubscription sub;
  sub = input.onBlur.listen((_) {
    sub.cancel(); // We only need the first event. Cancel the subscription.
    callback();
  });
  disposer.addStreamSubscription(sub);
}