首页 > 解决方案 > 如何使用未来的构建器添加返回两个小部件

问题描述

我想显示两个小部件,比如一个文本,然后是一个表格,它们都包含来自 api 的数据。我正在使用堆栈,我为表格创建了一个单独的方法。这是代码

Container(
      
    padding: EdgeInsets.fromLTRB(15, 470, 0, 0),
    child:SingleChildScrollView(
      scrollDirection: Axis.vertical,
    
    child: FutureBuilder(
    
    future: _getRecord(),
   
    
    builder: (BuildContext context, AsyncSnapshot<List<History>> snapshot) {
      // Check if the data has been received.
      if (snapshot.hasData) {
        // Return the widget and provide the received data.
        if(historyList.length!=0){
              return Stack(children:<Widget>[
                Expanded(
                          child: ListView.builder(
                        itemCount: snapshot.data.length,
                        scrollDirection: Axis.vertical,
                        shrinkWrap: true,
                        itemBuilder: (BuildContext context, int index) {
                          return ListTile(subtitle:Text(snapshot.data[index].date));})),// it is not displaying this line
                SizedBox(height: 30,),
                attendanceHistory(snapshot.data)

              ]);
             // return attendanceHistory(snapshot.data);
        }
       
      }
    

attendanceHistory(snapshot.data)此行显示带有数据的表格,但字幕不起作用

请帮助如何做到这一点

标签: flutterwidgetflutter-futurebuilder

解决方案


推荐阅读