![](/img/trans.png)
[英]ListView not scrolling in SingleChildScrollView Flutter
[英]Flutter listview scrolling is not available
我可以在我的列表視圖小部件中看到 6 個列表項,盡管還有 3 個項目,但我無法滾動列表視圖。
實際上我想讓這個鍛煉頁面非常簡單,這意味着我想避免使用很多行/列......
我在左上角和列表視圖下方只有一個文本 label。
我必須改變什么才能使列表視圖滾動?
我已經使用物理:AlwaysScrollableScrollPhysics(),
appBar: AppBar(
title: Text(title),
),
body: Container(
color: Colors.green,
margin: const EdgeInsets.all(5.0),
child: Column(
children: [
Align(
alignment: Alignment.topLeft,
child: Text("Workouts", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25)),
),
Expanded(
child: ListView.builder(
physics: AlwaysScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: workouts.length,
itemBuilder: (context, index) {
var workout = workouts[index];
return WorkoutWidget(key: Key(workout.id.toString()), workout: workout);
}),
),
],
),
),
將物理更改為NeverScrollableScrollPhysics()
,然后使用SingleChildScrollView
小部件包裝您的Container
。 您也可以省略scrollDirection
,因為Axis.vertical
已經是默認值。
appBar: AppBar(
title: Text(title),
),
body: SingleChildScrollView(
child: Container(
color: Colors.green,
margin: const EdgeInsets.all(5.0),
child: Column(
children: [
Align(
alignment: Alignment.topLeft,
child: Text(
"Workouts",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25),
),
),
Expanded(
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: workouts.length,
itemBuilder: (context, index) {
var workout = workouts[index];
return WorkoutWidget(
key: Key(workout.id.toString()),
workout: workout,
);
}),
),
],
),
),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.