Last active
July 12, 2020 11:52
-
-
Save edubskiy/f83fce13f7d7846eef8814453875ec9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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