일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 늑대상
- 거북이상
- #자바
- 인공지능 관상
- Teachable Machine
- 호랑이상
- Lipstick
- 관상 테스트
- 자바
- AR Lipstick Viewer
- 코틀린
- 재물운
- 연애운
- 인공지능 거북이 관상
- 안드로이드
- 쥐상관상
- 나른한 오후
- ==>
- 나른한오후
- 프로그램
- 코로나
- 관상이야기
- 실시간 인공지능 관상 테스트
- 관상 이야기
- 관상
- 인공지능
- 테스트
- 인공지능 동물상 관상 테스트
- 인공지능 호랑이상
- 동물상
- Today
- Total
주식회사 이웃사촌
FutureBuilder 사용예제 본문
download == true 이면 CircleProgerssIndicator 를 보여주고
false 이면 받은 이미지 화일을 builder 에서 처리해서 future 에서 이미지 위젯을
만들어 화면에 던진다.
body: Center(
child: downloading
? Container(
width: 200,
height: 120,
child: Card(
color: Colors.black,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(
height: 20,
),
Text(
'Downloading File : $progressString',
style: TextStyle(color: Colors.white),
)
],
),
),
)
: FutureBuilder(
future: downloadWidget(file), //데이타를 다 받았으면 위젯을 반환한다.
builder: (context, snapshot) {
//데이타처리
print('builder');
//Widget 를 반환하는데 상황에 따라서
//다른걸 반환하겠다.
switch (snapshot.connectionState) {
case ConnectionState.none:
print('none');
return Text('none');
case ConnectionState.waiting:
print('waiting');
return Text('waiting');
//return CircularProgressIndicator();
case ConnectionState.active:
print('active');
return Text('active');
//return CircularProgressIndicator();
case ConnectionState.done:
print('done');
if (snapshot.hasData) {
return snapshot.data as Widget;
}
}
print('end process');
return Text('no data');
},
),
),
Future<Widget> downloadWidget(filePath) async {
File file = File(filePath);
print('after exist future');
bool exist = await file.exists();
FileImage(file).evict(); //캐시 초기화
if (exist) {
print('after exist future');
return Center(
child: Column(
children: [Text('$file'), Image.file(file)],
),
);
} else {
return Text('no data');
}
}
'Flutter' 카테고리의 다른 글
List.generate List<Map<String, dynamic>>==> <List<Todo>> (0) | 2021.08.11 |
---|---|
내부저장소에 데이타 읽고쓰기 (0) | 2021.08.10 |
path_provider + File 을 이용한 화일 읽고/쓰기 (0) | 2021.08.10 |
ListView.builder 스크롤로 책정보 가져오기 (0) | 2021.08.10 |
이미지파일 다운로드및 FutureBuilder 를 이용한 화면에 나타내기 소스 (0) | 2021.08.09 |