firebase - 如何正确编写以下引发此错误的代码(A RenderFlex 在底部溢出 126 像素。)
问题描述
我最近开始使用颤振,我需要显示存储在 firestore 集合中的国家列表(只有三个国家需要测试,但我会添加更多)在此处输入图像描述,但问题是我可以访问单个文档,但我无法在列表视图中正确显示它们。这是我写的代码:
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 包装 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),
),
);
}
}
推荐阅读
- ubuntu-18.04 - 如何在 WSL 中正确运行 Ubuntu 中的 Cuda 工具包(最终用于 YOLO)?
- javascript - 为什么当 str 设置为 opt2 和 opt3 时 score 评估得分 +1
- octobercms - 如何预览模型记录
- machine-learning - 在逻辑回归中为分类选择正确的阈值
- python - 对象检测脚本错误 Winerror 2 未指定子进程和 numpy 未被识别?
- debugging - 如何在 Xcode 中为 initWithNibName 设置符号断点
- javascript - 在 TweenLite 中使用 text 方法显示未定义
- python-3.x - 我可以在单个 Cisco IOS 配置文件中使用两个 ciscoconfparse 对象来获取特定接口吗
- jsf - 为什么@Model 是@RequestScope 而不是@SessionScope 或@ViewScope?
- c++ - 相机标定数据检索