简体   繁体   English

如何为字幕动态添加小部件? (对于ListTile)

[英]How do I add dynamically widgets to a subtitle? (for ListTile)

I'm trying to add Chips to the ListTile subtitle, so that when the listTile is created via a ListView.builder, depending on the user's selection, they can have or see multiple chips in the subtitle. 我试图将Chips添加到ListTile字幕中,以便在通过ListView.builder创建listTile时,根据用户的选择,他们可以在字幕中看到多个芯片。

ListView.builder(

      scrollDirection: Axis.vertical,
      itemCount: myShoppingBasketList.length,
      itemBuilder: (ct, shoppingListViewBuilderItemInteger)
      {

       return Card(
            child: ListTile(key: UniqueKey(),
                //dense: true,
                leading: ...,
                title: ...
                subtitle: Wrap(<add chips here)...
                onTap: () 
                {

// Code to add new chips depending on selection


                }

        })

So - how could I dynamically += add to a Wrap widget. 所以-我如何动态+ =添加到Wrap小部件。 When I say 当我说

+=

What I'm hoping for is that if a Chip was like a String, then I'd like something like: 我希望的是,如果Chip就像一个String,那么我想要这样的东西:

Wrap(SomeChipContainerWidget = SomeChipContainerWidget+ newChipWidget))

Do you see my problem?? 看到我的问题了吗?

So let's say the subTitle was a Text widget, then the String text inside could be: 因此,假设subTitle是一个Text小部件,那么其中的String文本可能是:

Text(stringVar += stringVar + newString) 文字(stringVar + = stringVar + newString)

I have tried EVERYTHING - You cannot imagine. 我已经尝试了一切-您无法想象。 I've looked at Expansion Tiles - does't work, Animated, etc.. 我看过扩展图块-无效,动画等。

Any help will be really appreciated. 任何帮助将不胜感激。 Even sympathy. 甚至同情。

Declare a List and add a Chip to the List as per your requirement. 根据您的要求声明一个列表并将芯片添加到列表中。

Example Code: 示例代码:

List<Chip> chips = []; // Global Variable (Add a chip by default)
[...]
ListView.builder(
      scrollDirection: Axis.vertical,
      itemCount: myShoppingBasketList.length,
      itemBuilder: (ct, shoppingListViewBuilderItemInteger)
      {
       return Card(
            child: ListTile(key: UniqueKey(),
                //dense: true,
                leading: [...],
                title: [...]
                subtitle: Wrap(children: <Widget>[chips])...
                onTap: () 
                {
                   setState((){
                       chips.add(
                        Chip() //Your new chip
                        );
                    });
                }
        })

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

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