-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFuture Builder Flutter Example.dart
58 lines (48 loc) · 1.27 KB
/
Future Builder Flutter Example.dart
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return StreamBuilder<int>(
stream: getCount(5),
initialData: 0,
builder:(context, count){
if(count.connectionState == ConnectionState.waiting){
return Text("Starting to count with: ${count.data}");
}
else if(count.connectionState == ConnectionState.active){
return Text("${count.data}");
}else if(count.connectionState == ConnectionState.done){
return Text("It's done with ${count.data} !");
}
else{
return CircularProgressIndicator();
}
}
);
}
}
Stream<int> getCount(int count) async*{
for(int i =1; i<= count; i++){
await Future.delayed(const Duration(seconds:1));
print(i);
yield i;
}
}