Notice
Recent Posts
Recent Comments
Link
«   2025/09   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

자라나라

[Flutter]Stream 본문

Flutter

[Flutter]Stream

자랄수있다 2022. 9. 2. 20:53
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void main() {
var myStream = Stream.fromIterable([1,2,3,4,5]);
  myStream.listen((x) => print('iterable : $x'));
 
var myStream2 = Stream.periodic(Duration(seconds: 1), (x) => x).take(5);
  myStream2.listen((x) => print('periodic : $x'));
 
var myStream3 = Stream.fromFuture(getData());
  myStream3.listen((x) => print('fromFuture : $x'));
 
}
 
Future<String> getData() async{
  await Future.delayed(Duration(seconds: 3));
  print("Fetched Data");
  return "3초 기다린 뒤 온 데이터";
}
 

fromIterable, periodic, fromFuture 요 세가지 일단 알면 될 듯

 

 

결과

++

아래 두 메서드의 위치를 바꿔보았다.

last.then()과 first.then()은 단순히 첫번째와 마지막 변수를 출력해주는 메서드가 아니다(당연)

똑같이 스트림을 하되,  첫번째와 마지막 것만 출력을 해줄 뿐. 

또한 myStream.first.then()과 myStream.last.then()의 위치를 바꿔봤음에도 불구하고,  출력되는 순서는 같다.

 

 

 

 

 

 

https://beomseok95.tistory.com/308

 

Dart 언어 Stream 알아보기(Dart 비동기 프로그래밍)

Dart 언어  Stream 알아보기(Dart 비동기 프로그래밍) Dart 언어의 Stream에 대하여 알아보겠습니다. 목차 Table of Contents Stream 이란?? 스트림은 데이터나 이벤트가 들어오는 통로입니다. 앱을 만들다 보

beomseok95.tistory.com

범석님 블로그를 참고했습니다@@