[英]How to write the following code correctly which is throwing this error (A RenderFlex overflowed by 126 pixels on the bottom.)
I have started using flutter very recently and I need to show a list of countries which are stored in a collection in firestore (there are just three countries for testing but I will be adding more) enter image description here but the problem is I can access individual documents but I am unable to show them properly in a list view.我最近开始使用 flutter,我需要显示存储在 firestore 集合中的国家/地区列表(只有三个国家/地区进行测试,但我会添加更多)在此处输入图像描述,但问题是我可以访问单个文档,但我无法在列表视图中正确显示它们。 Here is the code I have written:这是我写的代码:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
class test extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('countries')
.doc('nW9L4LGpn2MZVyiTyUII')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Text('Loading data.. please wait..');
return ListTile(
title: Text(snapshot.data['name']),
subtitle: Text(snapshot.data['description']),
contentPadding: EdgeInsets.all(20),
leading: Image.network(
snapshot.data['image'],
height: 200,
width: 80,
),
);
},
),
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('countries')
.doc('2mnr4W3HYxCXrwb1KPAS')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Text('Loading data.. please wait..');
return ListTile(
title: Text(snapshot.data['name']),
subtitle: Text(snapshot.data['description']),
contentPadding: EdgeInsets.all(20),
leading: Image.network(
snapshot.data['image'],
height: 200,
width: 80,
),
);
},
),
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('countries')
.doc('WMWhmYkDgm6PXnt5Ze7F')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Text('Loading data.. please wait..');
return ListTile(
title: Text(snapshot.data['name']),
subtitle: Text(snapshot.data['description']),
contentPadding: EdgeInsets.all(20),
leading: Image.network(
snapshot.data['image'],
height: 200,
width: 80,
),
);
;
},
),
],
),
appBar: AppBar(
centerTitle: true,
backgroundColor: Color.fromRGBO(255, 111, 82, 0.8),
),
);
}
}
App UI Firestore database snapshot App UI Firestore 数据库快照
How do I write this code correctly?如何正确编写此代码?
Wrapping Column with SingleChildScrollView should work.用 SingleChildScrollView 包装 Column 应该可以工作。
class test extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: [
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('countries')
.doc('nW9L4LGpn2MZVyiTyUII')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Text('Loading data.. please wait..');
return ListTile(
title: Text(snapshot.data['name']),
subtitle: Text(snapshot.data['description']),
contentPadding: EdgeInsets.all(20),
leading: Image.network(
snapshot.data['image'],
height: 200,
width: 80,
),
);
},
),
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('countries')
.doc('2mnr4W3HYxCXrwb1KPAS')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Text('Loading data.. please wait..');
return ListTile(
title: Text(snapshot.data['name']),
subtitle: Text(snapshot.data['description']),
contentPadding: EdgeInsets.all(20),
leading: Image.network(
snapshot.data['image'],
height: 200,
width: 80,
),
);
},
),
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('countries')
.doc('WMWhmYkDgm6PXnt5Ze7F')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Text('Loading data.. please wait..');
return ListTile(
title: Text(snapshot.data['name']),
subtitle: Text(snapshot.data['description']),
contentPadding: EdgeInsets.all(20),
leading: Image.network(
snapshot.data['image'],
height: 200,
width: 80,
),
);
;
},
),
],
),
),
appBar: AppBar(
centerTitle: true,
backgroundColor: Color.fromRGBO(255, 111, 82, 0.8),
),
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.