TimeToCode
TimeToCode

Reputation: 1838

SingleChildScrollView is not working properly

I wrap the whole body with SingleChildScrollView, it works when i scroll down, but can't able to scroll up.

here is the code

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,),

                          ]);
                        },
                      )))

              ]);
        }
       
      }

When i remove the second SingleChildScrollView under the Container where i used future, it is not working in that case too, and if wrap the container with SingleChildScrollView it is still not working. and if i return it after this line if(historyList.length!=0){ and calling Stack its child then it's still not working.

Updated:

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,),
                          ]));
                        },
                      )))

              ]));
        }
       
      }

When i replace Stack with Column in the main SingleChildScrollView it is not displaying calender() widget output, that's why i am using Stack.

And it is saying this that i used incorrect use of Incorrect use of ParentDataWidget. here are the logs

════════ 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.

please help how to fix it.

Upvotes: 1

Views: 1991

Answers (1)

Ravindra S. Patil
Ravindra S. Patil

Reputation: 14885

If your calendar and datefilter widgets are constants I mean they are not scrolling so try to remove your both SingleChildScrollView and use Below code hope it's helpful to you, declare your Widgets inside Column instead of Stack

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

Upvotes: 1

Related Questions