Created
September 22, 2018 16:14
-
-
Save shellcode/20fd8c47d0fe4a13ab4ad44e146aa1e9 to your computer and use it in GitHub Desktop.
Stream Example
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
<h4>Enter your Email</h4> | |
<input /> | |
<div style="color:red"></div> |
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( | |
(inputValue) => div.innerHtml = "", | |
onError: (err) => div.innerHtml = err | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment