List - ExpansionTile

 ExpansionTile



Source Code
import 'package:flutter/material.dart';

void main() {
runApp( MaterialApp(
title:"ExpansionTile",
home:Scaffold(appBar: AppBar(title: Text(' ExpansionTile',),),
body: Material(
child: Center(
child:
ExpansionTileExample()
,
),
) ,
),
));
}



class ExpansionTileExample extends StatelessWidget {
const ExpansionTileExample({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return ListView.builder(
itemBuilder: (BuildContext context, int index) => EntryItem(data[index]),
itemCount: data.length,
);
}
}

// One entry in the multilevel list displayed by this app.
class Entry {
const Entry(this.title, [this.children = const <Entry>[]]);
final String title;
final List<Entry> children;
}

// Data to display.
const List<Entry> data = <Entry>[
Entry(
'Chapter A',
<Entry>[
Entry(
'Section A0',
<Entry>[
Entry('Item A0.1'),
Entry('Item A0.2'),
],
),
Entry('Section A1'),
Entry('Section A2'),
],
),
Entry(
'Chapter B',
<Entry>[
Entry('Section B0'),
Entry('Section B1'),
],
),
];

// 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 ListTile(title: Text(root.title));
return ExpansionTile(
key: PageStorageKey<Entry>(root),
title: Text(root.title),
children: root.children.map(_buildTiles).toList(),
);
}

@override
Widget build(BuildContext context) {
return _buildTiles(entry);
}
}


Comments