我正在嘗試在一行中添加一個串列視圖,但出現此錯誤

我在行中有兩個小部件,第一個小部件帶有一列,第二個小部件是回傳另一個小部件的串列視圖構建器。
我試圖使行看起來像下圖

這是我的代碼
body: SingleChildScrollView(
child: Column(
children: [
Row(
children: [
Column(
children: [
Stack(
children: [
Container(
height: 60,
width: 60,
decoration: const BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
image: DecorationImage(
image: AssetImage("assets/images/meee.jpg"))),
),
Positioned(
bottom: 0,
right: 0,
child: Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.blue, shape: BoxShape.circle),
child: Text(
" ",
style: TextStyle(color: Colors.white),
),
),
)
],
),
const SizedBox(
height: 7,
),
const Text(
"Your Story",
style: TextStyle(color: Colors.white, fontSize: 13),
)
],
),
ListView.builder(
itemCount: 3,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
return __buildStory();
},
),
],
),
],
),
),
uj5u.com熱心網友回復:
你有沒有嘗試改變這條線
ListView.builder(
用這條線
ListView.builder(shrinkWrap: true,
如果它不起作用,請考慮將您的ListView.builder小部件包裝在小Flexible部件中
Flexible(child:
uj5u.com熱心網友回復:
由于ListView需要 中的所有剩余空間Row,所以ListView.builder用包裹Expanded。還可以使用shrinkWrap:true在ListView。
添加mainAxisSize: MainAxisSize.min到Column.
body: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(
children: [
Container(
height: 60,
width: 60,
decoration: const BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
image: DecorationImage(
image: AssetImage("assets/images/meee.jpg"))),
),
Positioned(
bottom: 0,
right: 0,
child: Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.blue, shape: BoxShape.circle),
child: Text(
" ",
style: TextStyle(color: Colors.white),
),
),
)
],
),
const SizedBox(
height: 7,
),
const Text(
"Your Story",
style: TextStyle(color: Colors.white, fontSize: 13),
)
],
),
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: 3,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
return __buildStory();
},
),
),
],
),
],
),
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/334425.html
