Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.0k views
in Technique[技术] by (71.8m points)

listview - Dynamically display JSON data in data table layout in flutter. The argument type 'List<Text>' can't be assigned to the parameter type 'Widget'

I am Creating a Dynamic data table view in flutter , where the column headers and the row values are added dynamically. The data is a Json response,the header is a string array and the data to be displayed in row is also a string array .The goal is to display the data in the table view without any hardcoded values. This is how I have tried is to display the data.

                     return ListView.builder(
                         shrinkWrap: true,
                         scrollDirection: Axis.vertical,
                         itemCount: snapshot.data.dataList.length,
                         itemBuilder: (BuildContext context, int index){
                           return SingleChildScrollView(
                             child: DataTable(
                               columns: (snapshot.data.headerList[index] as List).map((item) =>
                               DataColumn(
                                   label:(
                                       List.generate(item.length,(index){
                                         return Text(item[index].toString());
                                       })
                                   )
                               )).toList(),
                               rows: (snapshot.data.dataList[index].dataList as List).map((item) =>
                               
                               DataRow(
                                 
                                   cells:<DataCell>[
                                     DataCell(
                                         List.generate(item.length,(index){
                                           return Text(item[index].toString());
                                         })
                                     )
                                    ])).toList(),
                             ),

This is the JSON response

 "DayEnd": {
        "ColumnWidths": "40′168′96′96′108′156",
        "Headers": "SL.>′Customer< ′Balance Qty>′Amount>′Oldest / Recent ",
        "FieldSeparator": "′",
        "DataList": [
            {
                "Data": "1. ′ABD ′14 / 14.60′11,090′313 / 313",
                "NextLevelZoomData": [
                    {
                        "Element": "eg7P27fbW/GmCr"
                    },
                    {
                        "Element": "AAA=="
                    }
                ],
                "NextLevelZoomType": 2
            },
            }

The above response gives a string data Headers which is separated by a special character "`",the each character has to be displayed in a each column header so which is converted to an array. Similarly the data as well . The column width that has to be maintained for each data is mentioned in columnWidth Similarly the alignment of the data like if "SL.>" then ">" it has to be right aligned.

I am not sure if this is the right approach to get it, This gives an error

The argument type 'List<Text>' can't be assigned to the parameter type 'Widget'.

Any idea to approach in a better way will be much appreciated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...