当我在flutter中循环数据表时出现错误:引发了另一个异常:类型'List <dynamic>'不是类型'List <DataRow>'的子类型

时间:2019-08-27 07:25:36

标签: flutter dart

I/flutter (19962): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (19962): The following assertion was thrown building StreamBuilder<int>(dirty, state:
I/flutter (19962): _StreamBuilderBaseState<int, AsyncSnapshot<int>>#46296):
I/flutter (19962): type 'List<dynamic>' is not a subtype of type 'List<DataRow>'
 @override
  Widget build(BuildContext context) {
    return Scaffold( 
      backgroundColor: Colors.white,
      body: new SingleChildScrollView(
        child:new StreamBuilder(
          stream: timedCounter(Duration(seconds: 4),10),
          builder: (context,snapshot){
            if (!snapshot.hasData) {
              return Container(
                alignment: Alignment.center,

                child: Padding(

                  padding: const EdgeInsets.only(top:300.0,left: 100.0,right: 100.0),
                  child: new Image.asset('assets/images/loader.gif'),
                ),
              );
            }
            return Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                new ClipPath(
                  clipper: HalfShapeClipper(),
                  child: Container(
                    height: 200.0,
                    color: Colors.orange,
                  ),
                ),
                // Flexible(child: _dispalyTable()),
                for(var i=0;i<mainarray.length;i++)
                  Padding(
                    padding: const EdgeInsets.only(top:20.0),
                    child: Column(
                      children: <Widget>[

                        new Text('${mainarray[i]['label']}',style: TextStyle(color: Colors.black,fontSize: 30.0,fontFamily: 'Poppins'),textAlign: TextAlign.start,),
                        new DataTable(
                          columns: [
                            DataColumn(
                              label: Text('Exam'),
                              numeric: false,
                              tooltip: 'Subject Names'
                            ),
                            DataColumn(
                              label: Text('Grade'),
                              numeric: false,
                              tooltip: 'Individual Marks'
                            ),
                            DataColumn(
                              label: Text('Description'),
                              numeric: false,
                              tooltip: 'Remarks of subject'
                            )
                          ],
                          rows:mainarray[i]['data'].map((marks)=>
                            DataRow(
                              cells: <DataCell>[
                                DataCell(Text('${marks['name']}'),),
                                DataCell(Text('${marks['marks']}'),),
                                DataCell(Text('${marks['desc']}'),)
                              ],
                            ),
                          ).toList(),
                        ),
                      ],
                    ),
                  ),
              ],
            );
          },
        ),
      ),
    );
  }

0 个答案:

没有答案