Flutter新手在這里!
目前,我的 Scaffold 有 2 個串列視圖構建器,底部的一個給了我無限高度(!constraints.hasBoundedHeight錯誤)問題。
我已嘗試shrinkWrap在所有 3 個串列視圖上使用,如類似問題中所建議的,但我遇到了相同的錯誤。
唯一可行的事情是包裹FutureBuilder在SizedBox。但這對我來說似乎不直觀,因為我希望它可以根據需要理想地擴展并可以滾動。
My rough solution is to maybe dynamically calculate the height based on the number of items the FutureBuilder needs, but again, I feel there should be a better solution.
我的代碼片段附在下面:
return Scaffold(
appBar: AppBar(),
body: ListView(
children: [
ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 2,
itemBuilder: (context, index) {
return const SuggestCard(
indexKey: 'takt',
);
}),
FutureBuilder<AnimeDetails>(
future: _animeDetail,
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: 2, //Number of anime from list
itemBuilder: (context, index) {
var anime = snapshot.data; //Get the data from the index
return AnimeCard(
anime: anime,
);
});
} else {
return const Center(child: CircularProgressIndicator());
}
},
),
],
),
);
uj5u.com熱心網友回復:
根據您的評論,我認為以下鏈接將對您有所幫助。
串列
uj5u.com熱心網友回復:
父ListView處理身體滾動事件,而第二個 ListView 將具有固定高度,您可以這樣做
return Scaffold(
body: LayoutBuilder(
builder: (context, constraints) => ListView(
children: [
SizedBox(
height: constraints.maxHeight * .3,
child: ListView.builder(
itemCount: 122,
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => Text("H $index"),
),
),
ListView.builder(
shrinkWrap: true,
physics:
const NeverScrollableScrollPhysics(), // parent controll the scroll event
itemCount: 44,
itemBuilder: (context, index) => Text("$index"),
),
],
),
));
uj5u.com熱心網友回復:
我剛剛將以下幾行添加到您的代碼中。你可以試試下面的代碼。
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
return Scaffold(
appBar: AppBar(),
body: ListView(
children: [
ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 2,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return const SuggestCard(
indexKey: 'takt',
);
}),
FutureBuilder<AnimeDetails>(
future: _animeDetail,
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: 2, //Number of anime from list
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
var anime = snapshot.data; //Get the data from the index
return AnimeCard(
anime: anime,
);
});
} else {
return const Center(child: CircularProgressIndicator());
}
},
),
],
),
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/401918.html
上一篇:未處理的例外:MissingPluginException(在通道flutter_barcode_scanner上找不到方法scanBarcode的實作)
