Reputation: 13
I have a list of different ListTiles and when tapped on, want them to open two more ListTiles directly underneath with specific information. When pressed on again, I want them to be removed. Can someone please help? This is what I have so far:
import 'package:flutter/material.dart';
class Page5 extends StatefulWidget {
@override
_Page5State createState() => _Page5State();
}
class _Page5State extends State<Page5> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(''
'Names',
),
elevation: 0.0,
),
body:
ListView(
children: <Widget> [
Card(
child: ListTile(
leading: Text(
'Susan',
),
),
onTap: () {},
)
),
Card(
child: ListTile(
leading: Text(
'Steve',
),
),
onTap: () {},
)
),
]
)
);
}
}
Upvotes: 1
Views: 744
Reputation: 789
You can use SliverList. I think that it is the best solution for your case. There is a video explaining how to use it.
https://api.flutter.dev/flutter/widgets/SliverList-class.html
Upvotes: 0
Reputation: 3235
You can use an ExpansionTile
.
It's like a normal ListTile
but it takes a children
parameter where you put the widgets you want to appear when it is clicked.
ExpansionTile(
title: Text(
'Your 1st ListTile',
),
children: <Widget>[
ListTile(
title: Text('1'),
)
ListTile(
title: Text('2'),
)
ListTile(
title: Text('3'),
)
],
),
Upvotes: 1