我已經實作了一個包含 Stream-Builder 的卡片,該卡片具有一個顯示專案的串列視圖。(專案存在并且顯示正常)。但是,除非我將卡片包裝在具有特定高度的 Sized-Box 中,否則卡片不會顯示專案。固定高度并不理想,因為我不知道動態文本的長度是多少,因此我希望文本可以包裹內容。如果沒有固定高度的大小框,則根本不會出現。
已嘗試使用 Flexible、Wrap、Column 和 Row 包裝卡片,但在所有這些專案中都不會顯示。我怎樣才能解決這個問題?
Card(
child: StreamBuilder(
stream: _midref.onValue,
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.hasData &&
!snapshot.hasError &&
snapshot.data.snapshot.value != null) {
midlists.clear();
DataSnapshot dataValues = snapshot.data.snapshot;
Map<dynamic, dynamic> values =
dataValues.value as Map;
values.forEach((key, values) {
midlists.add(values);
});
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: midlists.length,
itemBuilder: (BuildContext context, int index) {
return Card(
margin: EdgeInsets.fromLTRB(2, 2, 2, 2),
elevation: 20,
child: Text(
midlists[index]["name"].toUpperCase(),
textAlign: TextAlign.center,
style: TextStyle(fontSize: 13),
),
);
},
);
}
return Container();
},
),
),
父容器。這個 Container 被包裹在一個 Single Child ScrollView 中
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
]),
uj5u.com熱心網友回復:
用像這樣包裝你的卡Expanded:
Expanded(child: Card(
child: StreamBuilder(
stream: _midref.onValue,
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.hasData &&
!snapshot.hasError &&
snapshot.data.snapshot.value != null) {
midlists.clear();
DataSnapshot dataValues = snapshot.data.snapshot;
Map<dynamic, dynamic> values =
dataValues.value as Map;
values.forEach((key, values) {
midlists.add(values);
});
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: midlists.length,
itemBuilder: (BuildContext context, int index) {
return Card(
margin: EdgeInsets.fromLTRB(2, 2, 2, 2),
elevation: 20,
child: Text(
midlists[index]["name"].toUpperCase(),
textAlign: TextAlign.center,
style: TextStyle(fontSize: 13),
),
);
},
);
}
return Container();
},
),
));
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/450900.html
標籤:扑
