-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
example_listview.dart
61 lines (56 loc) · 2 KB
/
example_listview.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
59
60
61
import 'package:example/mock_data.dart';
import 'package:example/widgets.dart';
import 'package:flutter/material.dart';
import 'package:sticky_and_expandable_list/sticky_and_expandable_list.dart';
class ExampleListView extends StatefulWidget {
@override
_ExampleListViewState createState() => _ExampleListViewState();
}
class _ExampleListViewState extends State<ExampleListView> {
var sectionList = MockData.getExampleSections();
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
//In this example, we create a custom model class(ExampleSection).
//class ExampleSection implements ExpandableListSection<String> {}
//so: SliverExpandableChildDelegate<String, ExampleSection>()
return Scaffold(
appBar: CustomAppBar(title: "ListView Example"),
body: ExpandableListView(
builder: SliverExpandableChildDelegate<String, ExampleSection>(
sectionList: sectionList,
headerBuilder: _buildHeader,
itemBuilder: (context, sectionIndex, itemIndex, index) {
String item = sectionList[sectionIndex].items[itemIndex];
return ListTile(
leading: CircleAvatar(
child: Text("$index"),
),
title: Text(item),
);
}),
));
}
Widget _buildHeader(BuildContext context, int sectionIndex, int index) {
ExampleSection section = sectionList[sectionIndex];
return InkWell(
child: Container(
color: Colors.lightBlue,
height: 48,
padding: EdgeInsets.only(left: 20),
alignment: Alignment.centerLeft,
child: Text(
section.header,
style: TextStyle(color: Colors.white),
)),
onTap: () {
//toggle section expand state
setState(() {
section.setSectionExpanded(!section.isSectionExpanded());
});
});
}
}