dart - flutter : Is it possible to create multiple elements in a expansion tile?

标签 dart flutter flutter-layout

我使用 Flutter,我想创建一个 ExpansionTile在同一个 Tile 中列出 2 个元素。

例如:

name :/.......White-Space....../ Snow.

firstname :/.......White-Space....../ John.

location :/.......White-Space....../ Winterfell.

但我不知道这是否可能。(在互联网和文档上进行了一些搜索之后)

我尝试在 child 属性(property)中使用 Column、Row 等,但没有任何效果。

有人有解决方案吗?

我的代码:

class Entry{
 const Entry(this.title,[this.children = const <Entry>[]]);
 final String title;
 final List<Entry> children;
 }

 const List<Entry> data = <Entry> [
 Entry(
 '   Profile',
 <Entry>[
   Entry('Jhon'),
   Entry('Snow'),
   Entry('Winterfell'),
 ],
),

...

  class Collapsible extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemBuilder: (BuildContext context, int index) => EntryItem(data[index]),
      itemCount: data.length,
    );
  }
}
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(
      backgroundColor: Colors.white30,
        initiallyExpanded: true,
        key: PageStorageKey<Entry>(root),
        title: Center(child: Text(root.title),),
    children: root.children.map(_buildTiles).toList()
    );
  }
  @override
  Widget build(BuildContext context) {
    return _buildTiles(entry);
  }
}

最佳答案

(已编辑)

这是您要找的吗?

class Collapsible extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemBuilder: (context, i) {
        if(i >= data.length) return null;
        return ExpansionTile(
          title: Text('name: ${data[i].title}'),
          children: [
            Text('firstname: ${data[i].children[0].title}'),
            Text('firstname: ${data[i].children[1].title}'),
          ]
        );
      },
      itemCount: data.length,
    );
  }
}

关于dart - flutter : Is it possible to create multiple elements in a expansion tile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54983545/

相关文章:

flutter - 如何对 flutter 进行测试分片或并行运行

Flutter:如何创建圆形/圆形按钮

flutter - 如何从 Flutter 应用程序调用电话

flutter - Flutter中如何从子小部件调用父小部件功能

pdf - 参数类型 'Future<Widget>' 无法分配给参数类型 'Widget' .dart

redux - Dart/Flutter - 从回调函数中产生

dart - Flutter LBS to KG app 未注册 "Convert"提交

css - 如何让 CSS 变量在 Dart 中工作

Flutter Firebase 电话身份验证不发送短信代码。直接调用 PhoneCodeAutoRetrievalTimeout 方法。这是我的代码

google-maps - Flutter - 谷歌地图在调整大小时崩溃