ExpansionTile inside ListView - page not scrolling

安稳与你 提交于 2020-03-06 09:43:11

问题


I am facing issue with page scrolling. I am showing users transactions grouped per day. so there will be multiple items inside ExpansionTile.

I am first taking days from database and then taking transactions done on that day . so below is how my page working

  1. take all records
  2. get days and put in one list (days list)
  3. load main expansion tiles with for loop in this list(days list)
  4. when we do for loop take transactions on that day and load in another array
  5. bind children list as children to ExpansionTile.

My view is loading properly , but when i open subitems of ExpansionTile , i am not able to scroll page. please check video for more clear understanding. https://drive.google.com/file/d/1EVETVRHx0vZqiGryrcxUR0klrEX8Y63G/view?usp=sharing

My code is given below ,

 Widget build(BuildContext context) {
    return new Scaffold(

      body: FutureBuilder(
        future: getTransactions(),
        builder: (context, snapshot) {
          if (!snapshot.hasData) {
            return Center(child: CircularProgressIndicator());
          } else if (feedItemsParent.isEmpty) {
            return noRecordsDialogue(context, 'No transactions record', '');
          } else if (feedItemsParent.length == 0) {
            return noRecordsDialogue(context, 'No transactions record', '');
          } else {
            return new ListView.builder(
                shrinkWrap: true,
                itemCount: feedItemsParent.length,
                itemBuilder: (BuildContext ctxt, int index) =>
                    buildBody(ctxt, index));
          }
        },
      ),
    );
  }

below is buildBody function.

Widget buildBody(BuildContext ctxt, int index) {
    return new custom.ExpansionTile(
      initiallyExpanded: true,
      trailing: new Container(width: 20),
      headerBackgroundColor: Color(0xFFeff0f1),
      title: Text(
        feedItemsParent[index].transactiondatesmall.toString(),
        style: TextStyle(
          fontSize: 16,
          color: Colors.black,
          fontWeight: FontWeight.bold,
        ),
      ),
      children: <Widget>[
        buildTransactionList(
            feedItemsParent[index].transactiondatesmall.toString()),
      ],
    );
  }

below is how i am taking all children and binding them inside ExpansionTile.

 buildTransactionList(dtCompare) {
    if (feedItems.length == 0) {
      return noRecordsDialogue(context, 'No transactions record', '');
    } else {
      List<UserTransaction> feedItemsChild = [];
      for (int j = 0; j < feedItems.length; j++) {
        if (feedItems[j].transactiondatesmall == dtCompare) {
          feedItemsChild.add(feedItems[j]);
        }
      }

      return ListView(
        padding: const EdgeInsets.only(bottom: 16.0),
        shrinkWrap: true,
        children: feedItemsChild,
      );
    }
}

Thanks in advance.


回答1:


Finally i am able to solve this using answers given in below link. Changed my code as per given in answer as my requirement was 80% similar.

How to create Expandable ListView in Flutter

Thank you.



来源:https://stackoverflow.com/questions/60115628/expansiontile-inside-listview-page-not-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!