listview.separator 沒有顯示任何專案,只有空白螢屏,串列與 Firestore 存盤鏈接......我的代碼是否正確?請幫忙
class _SpecialOffersState extends State<SpecialOffers> {
final Stream<QuerySnapshot> _userStream =
FirebaseFirestore.instance.collection('med_cntr').snapshots();
@override
Widget build(BuildContext context) {
return Column(
children: [
SizedBox(height: getProportionateScreenWidth(5)),
StreamBuilder<QuerySnapshot>(
stream: _userStream,
builder:
(BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
return Expanded(
child: SizedBox(
height: 150.0,
child: ListView.separated(
scrollDirection: Axis.horizontal,
padding: EdgeInsets.all(12.0),
itemCount: 10,
separatorBuilder: (context, idx) {
return SizedBox(width: 12);
},
itemBuilder: (BuildContext context, int index) {
return Card(
clipBehavior: Clip.antiAliasWithSaveLayer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Stack(
children: [
Positioned.fill(
child: Image.network(
snapshot.data?.docs[index]['coverArt'],
fit: BoxFit.cover,
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
height: 80.0,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [
Colors.black.withOpacity(0.6),
Colors.transparent
],
),
)),
),
Positioned(
bottom: 8,
left: 8,
child: Text(
snapshot.data?.docs[index]['name'],
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
],
),
);
},
),
),
);
},
),
],
);
控制臺中顯示的錯誤:
RenderFlex 子項具有非零彈性,但傳入的高度約束是無界的。
無效引數:在 URI 檔案中未指定主機:///
uj5u.com熱心網友回復:
移除Expanded外部ListView并設定卡片的高度-寬度
嘗試:
class _SpecialOffersState extends State<SpecialOffers> {
final Stream<QuerySnapshot> _userStream =
FirebaseFirestore.instance.collection('med_cntr').snapshots();
@override
Widget build(BuildContext context) {
return Column(
children: [
SizedBox(height: getProportionateScreenWidth(5)),
StreamBuilder<QuerySnapshot>(
stream: _userStream,
builder:
(BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
return SizedBox(
height: 150.0,
child: ListView.separated(
scrollDirection: Axis.horizontal,
padding: EdgeInsets.all(12.0),
itemCount: 10,
separatorBuilder: (context, idx) {
return SizedBox(width: 12);
},
itemBuilder: (BuildContext context, int index) {
return SizedBox(
height: 150.0,
width: 150,
child: Card(
clipBehavior: Clip.antiAliasWithSaveLayer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Stack(
children: [
Positioned.fill(
child: Image.network(
snapshot.data?.docs[index]['coverArt'],
fit: BoxFit.cover,
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
height: 80.0,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [
Colors.black.withOpacity(0.6),
Colors.transparent
],
),
)),
),
Positioned(
bottom: 8,
left: 8,
child: Text(
snapshot.data?.docs[index]['name'],
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
],
),
),
);
},
),
);
},
),
],
);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/484328.html
