因此,我有2个功能。一种是在顶部显示一些文本,另一种是listview.builder。我的listview.builder是可滚动的,但是我想使我的文本也可滚动,它位于listview.builder的上方。因为当我滚动时,我只能滚动listview.builder。因此,当我滚动listview.builder时,我的文本也应该自动滚动
我的 body ,我称这些功能为:
return Scaffold(
appBar: header(context, apptitle: true),
backgroundColor: Color(0xff66FF99),
body: ListView(children: [
displaytitle(), \\ my function1
SizedBox(
height: 500,
child: showpics(), \\ my second function
),
]));
我的displaytitle()函数:
displaytitle() {
return Column(children: [
SizedBox(
height: 30.0,
),
Text(
"General Contest",
style: TextStyle(
fontFamily: "Montesserat",
fontSize: 20.0,
fontStyle: FontStyle.italic,
fontWeight: FontWeight.w700,
),
),
SizedBox(height: 30.0),
Container(
width: MediaQuery.of(context).size.width / 2,
height: 40.0,
child: Material(
borderRadius: BorderRadius.circular(100.0),
//shadowColor: Color(0xff859DEF),
color: Color(0xff4AA0F0),
elevation: 10.0,
我的表演图片功能在我有listview.builder的地方
return FutureBuilder(
future: Future.wait([getposts(), getposts2()]),
builder: (BuildContext context, AsyncSnapshot<List<dynamic>> snapshot) {
if (!snapshot.hasData) {
return Text(
"Loading...",
)
}
return ListView.builder(
itemCount: snapshot.data[0].length,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
child: Card(
elevation: 20.0,
child: Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
CircleAvatar(
radius: 20.0,
backgroundImage:
NetworkImage(snapshot.data[0][index].picture),
),
所以我的问题是,我只能滚动listview.builder,而不能滚动上方的文本。我无法将文本添加到listview.builder,因为它将破坏我的结构。
最佳答案
将ClampingScrollPhysics()添加到listviewbuilder
ListView.builder(
physics: ClampingScrollPhysics(),
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return ;
},
),
例如
ListView(
children: [
Column(
children: [
SizedBox(
height: 30.0,
),
Text(
"General Contest",
style: TextStyle(
fontFamily: "Montesserat",
fontSize: 20.0,
fontStyle: FontStyle.italic,
fontWeight: FontWeight.w700,
),
),
Container(
width: MediaQuery.of(context).size.width / 2,
height: 40.0,
child: Material(
borderRadius: BorderRadius.circular(100.0),
//shadowColor: Color(0xff859DEF),
color: Color(0xff4AA0F0),
elevation: 10.0,
),
),
],
),
ListView.builder(
physics: ClampingScrollPhysics(),
shrinkWrap: true,
itemCount: 30,
itemBuilder: (context, index) => GestureDetector(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 50,
width: double.infinity,
color: Colors.yellow,
),
),
),
),
],
),