简体   繁体   English

Flutter 如何在展开的列表视图中

[英]Flutter how to in a expanded list view

Hello good day everyone i want to make my listview into a expanded listview i pull my data using mysql i want to display first the transaction id and the vesselname then in the side it has it mut have a arrow that when you click it it will show other information details.大家好,大家好,我想让我的列表视图变成一个扩展的列表视图,我使用 mysql 提取我的数据,我想首先显示交易 ID 和船只名称,然后在它的侧面有一个箭头,当你点击它时它会显示其他信息详情。

  Widget build(BuildContext context) {
        return Scaffold(
            body: RefreshIndicator(
          onRefresh: getData,
          key: _refresh,
          child: loading
              ? Center(child: CircularProgressIndicator())
              : ListView.builder(
                  itemCount: list.length,
                  itemBuilder: (context, i) {
                    final x = list[i];
                    debugPrint(x.toString());
                    return Container(
                      padding: EdgeInsets.all(20.0),
                      child: Row(
                        children: <Widget>[
                          Expanded(
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                            the data will be shown first is transaction id and vessel name a arrow icon on the side when it is click it will show the other information
                          Text(
                              'Transaction ID:\t' + x.transaction_id,
                              style: TextStyle(
                                  fontSize: 20.0, fontWeight: FontWeight.bold),
                            ),
                            Text('Vessel Name:\t' + x.vesselname,
                                style: TextStyle(fontSize: 20.0)),

//this will be the the information displayed after the side arrow will be click //这将是点击侧箭头后显示的信息

     Text('Type of Port :\t' + x.typeofport.capitalize(),
                            style: TextStyle(fontSize: 20.0)),
                        Text('Vessel Number:\t' + x.voyageno,
                            style: TextStyle(fontSize: 20.0)),
                        Text('Ship Call #:\t' + x.scn,
                            style: TextStyle(fontSize: 20.0)),
                        Text('OR #:\t' + x.ornum,
                            style: TextStyle(fontSize: 20.0)),
                        Text(
                            'Amount:\t ' +
                                money.format(int.parse(x.payment)),
                            style: TextStyle(fontSize: 20.0)),
                        Text('Status:\t' + x.status.toUpperCase(),
                            style: TextStyle(
                                fontSize: 25.0,
                                fontWeight: FontWeight.bold,
                                color: x.status == 'pending'
                                    ? Colors.red
                                    : Colors.green)),
                        Divider()
                      ],
                    ),
                  ),
                ],
              ),
            );
          },
        ),
));

} } } }

在颤动中探索ExpansionTile ,我认为它符合您的要求。

first when you fetch data in your DTO you can put bool variable inside or you can remap your DTO and put variable bool so your variable inside somehow like this:首先,当您在 DTO 中获取数据时,您可以将 bool 变量放入其中,或者您可以重新映射 DTO 并放入变量 bool 以便您的变量以某种方式放入其中:

Map<DTO, bool> 

or或者

DTO{
    ........, bool collapsed;
}

then in your code when you create your builder然后在您创建构建器时的代码中

final x = list[i]; >> changed to entries if you used Map [final x = mapData[i].entries.toList()]

return Container(
padding: EdgeInsets.all(20.0),
child: GestureDetector(
onTap: (){
    setState({
        // if you using Map
        x[i] = !x.value;

    // if you using DTO
    x.collapsed = !x.collapsed;
    });

},
    child: Column(
        children:[
            // Your Header
            Row(
children: <Widget>[
  Expanded(
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
    the data will be shown first is transaction id and vessel name a arrow icon on the side when it is click it will show the other information
  Text(
      'Transaction ID:\t' + x.transaction_id,
      style: TextStyle(
          fontSize: 20.0, fontWeight: FontWeight.bold),
    ),
    Text('Vessel Name:\t' + x.vesselname,
        style: TextStyle(fontSize: 20.0)),

        ]

        // Your Detail
        // [if you used DTO]
        if(!x.collapsed) Container(child:.......)


        // [if you used Map]
        if(!x.value) Container(child:......)
    )

)

this is only the logic of changing the list inside to become Collapsible listView这只是把里面的list改成Collapsible listView的逻辑

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

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