자라나라
[Flutter]Stream 본문
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
범석님 블로그를 참고했습니다@@
'Flutter' 카테고리의 다른 글
[Flutter] 데이터 저장 (2) 파일 이용하기 (0) | 2022.09.12 |
---|---|
[Flutter] 데이터 저장 (1) shared_preferences (0) | 2022.09.12 |
[Flutter] JSON을 이용한 API 통신 (0) | 2022.09.09 |
[Flutter] 회원가입 폼 만들기(2)firebase 유저등록 (0) | 2022.09.02 |
[Flutter] 회원가입 폼 만들기(1)TextFormField validator 사용하기 (0) | 2022.08.27 |