Skip to content

Instantly share code, notes, and snippets.

@edubskiy
Last active July 12, 2020 11:52
Show Gist options
  • Save edubskiy/f83fce13f7d7846eef8814453875ec9f to your computer and use it in GitHub Desktop.
Save edubskiy/f83fce13f7d7846eef8814453875ec9f to your computer and use it in GitHub Desktop.
import 'dart:html';
import 'dart:async';
void main() {
final InputElement input = querySelector('input');
final DivElement div = querySelector('div');
final validator = new StreamTransformer.fromHandlers(
handleData: (inputValue, sink) {
if (inputValue.contains('@')) {
sink.add(inputValue);
} else {
sink.addError('Enter a valid email');
}
}
);
input.onInput
.map((dynamic event) => event.target.value)
.transform(validator)
.listen(
(event) {
div.innerHtml = '';
print('That email looks valid');
},
onError: (error) => div.innerHtml = error
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment