Firebase 如何正确编写引发此错误的以下代码(底部的RenderFlex溢出126像素)
我最近开始使用flutter,我需要显示存储在firestore集合中的国家列表(只有三个国家需要测试,但我将添加更多),但问题是我可以访问单个文档,但无法在列表视图中正确显示它们。 以下是我编写的代码:Firebase 如何正确编写引发此错误的以下代码(底部的RenderFlex溢出126像素),firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,我最近开始使用flutter,我需要显示存储在firestore集合中的国家列表(只有三个国家需要测试,但我将添加更多),但问题是我可以访问单个文档,但无法在列表视图中正确显示它们。 以下是我编写的代码: import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:cloud_fires
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),
),
);
}
}
如何正确编写此代码?使用SingleChildScrollView包装列应该可以
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),
),
);
}
}
使用列表视图而不是列。或者可以使用SingleChildScrollView小部件包装该列。