SingleChildScrollView 无法正常工作

SingleChildScrollView is not working properly

我用SingleChildScrollView包裹了整个body,向下滚动时有效,但无法向上滚动。

这是代码

body:SingleChildScrollView(
    scrollDirection: Axis.vertical,
    child: 
    Stack(children: <Widget>[
      calendar(),
      datefilter(),
 
    Container( 
    padding: EdgeInsets.fromLTRB(15, 450, 0, 0),
    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:1,
                        scrollDirection: Axis.vertical,
                        shrinkWrap: true,
                        itemBuilder: (BuildContext context, int index) {
                          return ListTile(subtitle:Text("Total Working hours :  "+workinghours,style:TextStyle(fontSize: 25,color:Colors.red)));})),


               //here the listtile are building and i used SingleChildScrollView, but it is not working
                 SingleChildScrollView(
                scrollDirection: Axis.vertical,
                child:Expanded(
                          child: ListView.builder(
                        itemCount: snapshot.data.length,
                        scrollDirection: Axis.vertical,
                        shrinkWrap: true,
                        itemBuilder: (BuildContext context, int index) {
                        return Stack(
                              overflow: Overflow.visible,
                              children: <Widget>[
                            ListTile(
                           leading:  CircleAvatar(
                             radius: 25,
                            backgroundColor:Color(int.parse(annualboxcolor)),
                            child: Container(
                              padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
                              child:Column(children: <Widget>[
                              
                              Text(snapshot.data[index].date[1].toString(),style: TextStyle(fontSize: 15.0,fontWeight: FontWeight.bold,color:Colors.white),),  
                            ]
                            
                            ),
                          )),
                          title: Text(snapshot.data[index].date),
                          isThreeLine: true,
                          subtitle:Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                              Text(snapshot.data[index].timeIn+" To "+snapshot.data[index].timeOut,
                                  ),
                          ],
                      ) 
                      Divider(color: Colors.grey,height: 10,),

                          ]);
                        },
                      )))

              ]);
        }
       
      }

当我删除我使用 future 的容器下的第二个 SingleChildScrollView 时,它在那种情况下也不起作用,如果用 SingleChildScrollView 包装容器它仍然不起作用。如果我 return 它在此行之后 if(historyList.length!=0){ 并调用 Stack 它的 child 那么它仍然无法正常工作。

更新:

body:SingleChildScrollView(
      scrollDirection: Axis.vertical,
      child: 
    Stack(children: <Widget>[   
      calendar(),
      datefilter(),
    Container(    
    padding: EdgeInsets.fromLTRB(15, 450, 0, 0), 
    child: FutureBuilder(  
    future: _getRecord(), 
    builder: (BuildContext context, AsyncSnapshot<List<History>> snapshot) {
      if (snapshot.hasData) {
        if(historyList.length!=0){
              return  SingleChildScrollView(
                scrollDirection: Axis.vertical,
                child:Stack(children: <Widget>[
                Expanded(
                          child: ListView.builder(
                        itemCount:1,
                        scrollDirection: Axis.vertical,
                        shrinkWrap: true,
                        itemBuilder: (BuildContext context, int index) {
                          return ListTile(subtitle:Text("Total Working hours :  "+workinghours,style:TextStyle(fontSize: 25,color:Colors.red)));})),
                  Padding(padding: EdgeInsets.fromLTRB(0, 70, 0, 0),
                child:Expanded(
                          child: ListView.builder(
                        itemCount: snapshot.data.length,
                        scrollDirection: Axis.vertical,
                        shrinkWrap: true,
                        itemBuilder: (BuildContext context, int index) {
                        return SingleChildScrollView(
                              //overflow: Overflow.visible,
                              child:Stack(
                                overflow: Overflow.visible,
                                children:<Widget>[
                            ListTile(
                           leading:  CircleAvatar(
                             radius: 25,
                            backgroundColor:Color(int.parse(annualboxcolor)),
                            child: Container(
                              padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
                              child:Column(children: <Widget>[
                              Text(snapshot.data[index].date[9].toString(),style: TextStyle(fontSize: 15.0,fontWeight: FontWeight.bold,color:Colors.white),),  
                            ]
                            
                            ),
                          )),
                          title: Text(snapshot.data[index].date),
                          isThreeLine: true,
                          subtitle:Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                              Text(snapshot.data[index].timeIn+" To "+snapshot.data[index].timeOut,),
                          ],
                      )
                          ),
                          Divider(color: Colors.grey,height: 10,),
                          ]));
                        },
                      )))

              ]));
        }
       
      }

当我在主要 SingleChildScrollView 中将 Stack 替换为 Column 时,它不显示 calender() 小部件输出,这就是我使用 Stack 的原因。

这是说我使用了不正确的ParentDataWidget 用法。 这是日志

════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.

The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type StackParentData.

Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets.
The offending Expanded is currently placed inside a Stack widget.

The ownership chain for the RenderObject that received the incompatible parent data was:
  RepaintBoundary ← NotificationListener<ScrollNotification> ← GlowingOverscrollIndicator ← Scrollable ← ListView ← Expanded ← Stack ← _SingleChildViewport ← IgnorePointer-[GlobalKey#c7d81] ← Semantics ← ⋯
When the exception was thrown, this was the stack
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.

请帮忙解决一下。

如果您的 calendardatefilter 小部件是常量,我的意思是它们没有滚动,所以请尝试删除您的两个 SingleChildScrollView 并使用下面的代码希望对您有所帮助,在 Column 中声明您的 Widgets 而不是 Stack

body:Column:(
  children [ 
    calendar (),
     datefilter (),
     Expanded:(
      child:FutureBuilder(),
      )
    ],
   ),