我用 SingleChildScrollView 包裹整个身体,当我向下滚动时它可以工作,但不能向上滚动。
这是代码
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,),
]);
},
)))
]);
}
}
当我删除SingleChildScrollView
我使用未来的容器下的第二个时,它在这种情况下也不起作用,如果用SingleChildScrollView
它包裹容器仍然不起作用。如果我在这条线之后返回它if(historyList.length!=0){
并调用Stack
它的孩子,那么它仍然无法正常工作。
更新:
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,),
]));
},
)))
]));
}
}
当我在主目录中Stack
替换为时,它不显示小部件输出,这就是我使用.Column
SingleChildScrollView
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.
请帮助如何解决它。