Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- flutter
- node.js
- Load Image
- HTTP
- Flutter 앱 배포
- Flutter Tutorial
- ListView.builder
- Flutter Example
- WillPopScope
- Row Widget
- ListTile
- FutureBuilder
- Scaffold
- InkWell
- Row
- Snackbar
- Networking
- AppBar
- listview
- navigator
- Column Widget
- MainAxisAlignment
- Image.network
- CrossAxisAlignment
- 반석천
- Flutter 예제
- Flutter 강좌
- Cached Image
- sqlite
- Hello World
Archives
- Today
- Total
꿈꾸는 시스템 디자이너
Flutter Example - ListView | ListView with diffrent types of items 본문
Tutorial/Flutter with App
Flutter Example - ListView | ListView with diffrent types of items
독행소년 2019. 9. 27. 14:34import 'package:flutter/material.dart';
abstract class ListsItem {}
class HeadingItem implements ListsItem {
final String heading;
HeadingItem(this.heading);
}
class MessageItem implements ListsItem {
final String sender;
final String body;
MessageItem(this.sender, this.body);
}
class ListViewWithDiffTypeItems extends StatelessWidget {
List<ListsItem> items;
ListViewWithDiffTypeItems() {
items = List<ListsItem>.generate(100, (index) {
if (index % 5 == 0) {
return HeadingItem("HeadingItem $index");
} else {
return MessageItem("Sender $index", "Message body $index");
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("ListView with diffrent types of itmes")),
body: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index];
if (item is HeadingItem) {
return ListTile(
title: Text(item.heading,style: TextStyle(fontWeight: FontWeight.bold),),
);
} else if (item is MessageItem) {
return Padding(
padding: const EdgeInsets.only(left: 10),
child: ListTile(
title: Text(item.sender),
subtitle: Text(item.body),
),
);
}
return null;
},
),
);
}
}
▶ Go to Table of Contents | 강의 목차로 이동
※ This example is also available in the Flutter Code Examples app. | 본 예제는 Flutter Code Examples 앱에서도 제공됩니다.
'Tutorial > Flutter with App' 카테고리의 다른 글
Flutter Example - GridView Widget (0) | 2019.09.27 |
---|---|
Flutter Example - ListView | Horizontal ListView (0) | 2019.09.27 |
Flutter Example - ListView | Create ListView with builder (2) | 2019.09.27 |
Flutter Example - ListView | basic (0) | 2019.09.27 |
Flutter Example - Screen Management | Kept On Screen (0) | 2019.09.27 |
Comments