简体   繁体   English

如何正确编写以下引发此错误的代码(A RenderFlex 在底部溢出 126 像素。)

[英]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.

相关问题 Flutter 滚动问题 - RenderFlex 底部溢出 192 像素 - Flutter scroll issue - A RenderFlex overflowed by 192 pixels on the bottom 无限像素溢出底部? - BOTTOM OVERFLOWED BY Infinity PIXELS? Flutter 页面刷新问题 | ListView 显示错误“BOTTOM OVERFLOWED BY 98 PIXEL” - Flutter Page refresh problem | ListView showing a error “BOTTOM OVERFLOWED BY 98 PIXEL” 突发奇想我得到这个 Renderflex 错误并且无法解决它? - Whim im getting this Renderflex error and cannot solving it? 如何在Firestore上阅读和创建文档中所有提要的列表,以及如何创建一个替换以下代码中标题列表的列表 - How to read and create a list of all the feed in a document on firestore and create a list which replaces the list of titles in the following code Firebase 尝试将数据写入控制台时抛出错误 - Firebase throwing error when trying to write data to console Firebase 函数在尝试写入存储时抛出错误 - Firebase functions throwing error when attempting to write to Storage Firestore写限制错误代码 - Firestore Write Limitation Error Code 由于 FirebaseInstanceId() 已弃用,如何重写以下代码? - How to rewrite the following code since the FirebaseInstanceId() is deprecated? “ task.future.then ” 在我的 Flutter 代码中不断抛出错误 - “ task.future.then ” keeps throwing an error in my Flutter code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM