그림
수입 ' 패키지 : 플러터 / material.dart ' ; 클래스 ExpansionTileSample이 StatelessWidget {확장 @Override 위젯 빌드 (BuildContext 컨텍스트를) { 반환 새 MaterialApp ( : 집에 새로운 발판 ( appBar : 새로운 AppBar ( 제목 : CONST 텍스트 ( ' ExpansionTile ' ), ), 몸 : 새로운 ListView.builder ( itemBuilder을 : ( BuildContext 컨텍스트 INT 인덱스) => 새로운 EntryItem (데이터 [인덱스), ITEMCOUNT : data.length입니다, ), ), ); } } // One entry in the multilevel list displayed by this app. class Entry { Entry(this.title, [this.children = const <Entry>[]]); final String title; final List<Entry> children; } // The entire multilevel list displayed by this app. final List<Entry> data = <Entry>[ new Entry('Chapter A', <Entry>[ new Entry('Section A0', <Entry>[ new Entry('Item A0.1'), new Entry('Item A0.2'), new Entry('Item A0.3'), ], ), new Entry('Section A1'), new Entry('Section A2'), ], ), new Entry('Chapter B', <Entry>[ new Entry('Section B0'), new Entry('Section B1'), ], ), new Entry('Chapter C', <Entry>[ new Entry('Section C0'), new Entry('Section C1'), new Entry('Section C2', <Entry>[ new Entry('Item C2.0'), new Entry('Item C2.1'), new Entry('Item C2.2'), new Entry('Item C2.3'), ], ), ], ), ]; // Displays one Entry. If the entry has children then it's displayed // with an ExpansionTile. class EntryItem extends StatelessWidget { const EntryItem(this.entry); final Entry entry; Widget _buildTiles(Entry root) { if (root.children.isEmpty) return new ListTile(title: new Text(root.title)); return new ExpansionTile( key: new PageStorageKey<Entry>(root), title: new Text(root.title), children: root.children.map(_buildTiles).toList(), ); } @override Widget build(BuildContext context) { return _buildTiles(entry); } } void main() { runApp(new ExpansionTileSample()); }