繁体   English   中英

我如何在 flutter 中创建子 ListTile 或某种子列表

[英]How do i create a sub-ListTile or kind of a sublist in flutter

从抽屉中单击一个选项,如何创建子列表。 此子列表应显示另一组选项。 在此处输入图像描述

使用扩展瓦。

    import 'package:flutter/material.dart';

    class ExpansionTileSample extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: const Text('ExpansionTile'),
            ),
            drawer: Container(
              color: Colors.white,
              width: 200.0,
              child: ListView.builder(
                itemBuilder: (BuildContext context, int index) =>
                    EntryItem(data[index]),
                itemCount: data.length,
              ),
            ),
            body: Text("hhelo World"),
          ),
        );
      }
    }

    // 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>[
      Entry(
        'Chapter A',
        <Entry>[
          Entry(
            'Section A0',
            <Entry>[
              Entry('Item A0.1'),
              Entry('Item A0.2'),
              Entry('Item A0.3'),
            ],
          ),
          Entry('Section A1'),
          Entry('Section A2'),
        ],
      ),
      Entry(
        'Chapter B',
        <Entry>[
          Entry('Section B0'),
          Entry('Section B1'),
        ],
      ),
      Entry(
        'Chapter C',
        <Entry>[
          Entry('Section C0'),
          Entry('Section C1'),
          Entry(
            'Section C2',
            <Entry>[
              Entry('Item C2.0'),
              Entry('Item C2.1'),
              Entry('Item C2.2'),
              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 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);
      }
    }

    void main() {
      runApp(ExpansionTileSample());
    }

是这样的??

ExpansionTile(
    title: Text('Main ListTile'),
    children: <Widget>[
      ListTile(
        title: Text('Sub-ListTile 1'),
        onTap: () {
        
        },
      ),
      ListTile(
        title: Text('Sub-ListTile 2'),
        onTap: () {
         
        },
      ),
    ],
  )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM