我想顯示一個帶有 Text 的 Container,后跟一個 ListView 類別。在我當前的代碼中,除了我無法弄清楚如何使文本容器也可滾動之外,它可以解決(因此它會倒置移出框架)。
它目前看起來像這樣:

藍色的容器是靜態的并且停留在它的位置,而紅色的 ListView 是完全可以滾動的。
當前代碼:
body: Container(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Container(
padding: EdgeInsets.fromLTRB(15, 0, 0, 10),
child: Align(
alignment: Alignment.topLeft,
child: const Text("Browse through the individual categories...", style: TextStyle(fontSize: 32, color: Colors.black, fontWeight: FontWeight.w900)),
),
),
Expanded(
child: ListView.builder(
itemCount: 20,
itemBuilder: (context, index){
return Padding(
padding: const EdgeInsets.all(8.0),
child: Category(),
);
}
),
),
],
),
我試圖實作這個答案。
body: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Container(
padding: EdgeInsets.fromLTRB(15, 0, 0, 30),
child: Align(
alignment: Alignment.topLeft,
child: const Text("Browse through the individual categories...", style: TextStyle(fontSize: 32, color: Colors.black, fontWeight: FontWeight.w900)),
),
),
Expanded(
child: ListView.builder(
shrinkWrap: true,
primary: false,
itemCount: 20,
itemBuilder: (context, index){
return Padding(
padding: const EdgeInsets.all(8.0),
child: Category(),
);
}
),
),
],
),
),
我收到以下錯誤:
RenderFlex 子項具有非零彈性,但傳入的高度約束是無界的。
RenderBox 未布置:RenderFlex#12630 relayoutBoundary=up11 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
uj5u.com熱心網友回復:
在您的串列視圖中添加這些行
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
您可以跳過此解決方案的擴展小部件。
uj5u.com熱心網友回復:
剛剛洗掉SingleChildScrollView小部件它會作業。
uj5u.com熱心網友回復:
用小部件包裝,SingleChildScrollView然后添加physics : NeverScrollableScrollPhysics()到ListView小部件。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/421013.html
標籤:
上一篇:Flutter-如何獲取需要在變數中“等待”的提供程式呼叫函式的值?
下一篇:如何在飛鏢中列印日期值
