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 62 63 64 65 66 67 68
| import 'package:flutter/material.dart'; class ExpansionTileSample extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( home: new Scaffold( appBar: new AppBar( title: const Text('ExpansionTile'), ), body: new ListView.builder( itemBuilder: (BuildContext context, int index) => new EntryItem(data[index]), itemCount: data.length, ), ), ); } }
class Entry { Entry(this.title, [this.children = const <Entry>[]]); final String title; final List<Entry> children; }
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'), ], ), ];
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()); }
|