动态扩展列表仅显示抖动中的最后一个索引

时间:2019-03-07 09:35:39

标签: android dart flutter

我正在尝试在动态列表中显示动态列表,但无法显示整个子列表。

下面的创建列表

 ListView.builder(
                shrinkWrap: true,
                itemCount: opAtrrList.length>0?opAtrrList.length:0,
                itemBuilder: (context, i) {
                  return new ExpansionTile(
                    title: new Text(opAtrrList[i].groupname, style: new TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold, fontStyle: FontStyle.italic),),
                    children: <Widget>[
                      new Column(
                        children: _buildExpandableContent(opAtrrList[i]),
                      ),
                    ],
                  );
                },
              ),

我的扩展列表

 _buildExpandableContent(OptionAttribute vehicle) {
      List<Widget> columnContent = [];

      for (Attribute content in vehicle.attrlist)
        columnContent.add(
          new ListTile(
            title: new Text(content.attributename, style: new TextStyle(fontSize: 18.0),),
          ),
        );

      return columnContent;
    }

我正在从数据库中填充列表

 void _queryOptionList( ) async {
try{
  String grouprowid='';

  optionList = await dbHelper.queryOptionList();
   for(int i=0;i<optionList.length;i++){

     grouprowid=optionList[i]['grouprowid'];

     OptionAttribute optionAttribute=new OptionAttribute();
     optionAttribute.grouprowid=optionList[i]['grouprowid'];
     optionAttribute.groupname=optionList[i]['groupname'];
     optionAttribute.isrequired=optionList[i]['isrequired'];

     optionAttributeList = await dbHelper.queryReadGroupAttribute(grouprowid);

     debugPrint('Group Index:- ${ i}');
     debugPrint('Group Name:- ${  optionAttribute.groupname}');

     if(optionAttributeList.length==0){
       Attribute attribute=new Attribute();
       attribute.grouprowid='0000';
       attribute.attributename='No Items';
       attribute.attributerowid='0000';
       attribute.weight='0';

       List<Attribute> attr=new List<Attribute>();
       attr.add(attribute);
       optionAttribute.attrlist=attr;
       debugPrint('Attr Index:- ---------------');
       debugPrint('Attr Name:- ${  attribute.attributename}');

     }else{
       for(int j=0;j<optionAttributeList.length;j++){

         Attribute attribute=new Attribute();
         attribute.grouprowid=optionAttributeList[j]['grouprowid'];
         attribute.attributename=optionAttributeList[j]['attributename'];
         attribute.attributerowid=optionAttributeList[j]['attributerowid'];
         attribute.weight=optionAttributeList[j]['weight'];

         List<Attribute> attr=new List<Attribute>();
         attr.add(attribute);
         optionAttribute.attrlist=attr;



         debugPrint('Attr Index:- ${ j}');
         debugPrint('Attr Name:- ${  attribute.attributename}');
       }
     }

     opAtrrList.add(optionAttribute);
     debugPrint('AttributeList List Size:-- ${optionAttributeList.length}');
     debugPrint('Main List Size:-- ${opAtrrList.length}');

   }

   setState(() {
     opAtrrList;

   });

}catch(e){debugPrint('OPTION ATTRIBUTE EXCEPTION ${e}');}

}

我的Bean类

class OptionAttribute{

  String _grouprowid;
  String _groupname;
  String _isrequired;
  List<Attribute> _attrlist;
  OptionAttribute();

}
class Attribute{

  String _attributerowid;
  String _grouprowid;
  String _attributename;
  String _weight;

  Attribute();

} enter image description here

0 个答案:

没有答案