Created
August 12, 2022 04:10
-
-
Save RileySeaburg/e530228d68ea8a33e188bbc65b630413 to your computer and use it in GitHub Desktop.
Stream 'Take' and 'Where' Functions in Dart
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
<form> | |
<h4>Guess the Word<h4> | |
<input/> | |
<button>Guess</button> | |
</form> |
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'; | |
void main() { | |
final ButtonElement button = querySelector('button') as ButtonElement; | |
final InputElement input = querySelector('input') as InputElement; | |
button.onClick | |
/// Stream Method Take https://api.dart.dev/stable/2.17.6/dart-async/Stream/take.html | |
.take(4) | |
/// Where Method | |
/// Example | |
/// ```dart | |
/// final stream = | |
/// Stream<int>.periodic(const Duration(seconds: 1), (count) => count) | |
/// .take(10); | |
/// final customStream = stream.where((event) => event > 3 && event <= 6); | |
/// customStream.listen(print); // Outputs event values: 4,5,6. | |
/// ``` | |
/// https://api.dart.dev/stable/2.17.6/dart-async/Stream/where.html | |
.where((event) => input.value == "balloon") | |
/// Listen Method | |
/// API Documentation: | |
/// https://api.dart.dev/stable/2.17.6/dart-async/Stream/listen.html | |
.listen( | |
(event) => print("This is sparta!, JK You guessed it!"), | |
onDone: () => print("You Lost!") | |
); | |
} |
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 { | |
color: white; | |
} | |
form{ | |
display: flex; | |
flex-direction: column; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment