【问题标题】:error:- Another exception was thrown: A RenderFlex overflowed by 33 pixels on the bottom错误:- 引发了另一个异常:A RenderFlex 在底部溢出了 33 个像素
【发布时间】:2018-05-29 05:04:31
【问题描述】:

[在此处输入图像描述]
1运行我的应用程序时显示错误...我的代码在下面...谁能告诉我我的代码有什么问题 ///////////////////// 当我运行我的应用程序时显示错误...我的代码在下面...谁能告诉我的代码有什么问题 /////////////////////

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'dart:async';
import 

'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

class OfferPage extends StatefulWidget {

  @override
  _OfferPageState createState() => new _OfferPageState();
}

class _OfferPageState extends State<OfferPage> {


  StreamSubscription<QuerySnapshot> subscription;
  List<DocumentSnapshot> offerpostList;
  final CollectionReference collectionReference =
  Firestore.instance.collection("todos");



  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    subscription = collectionReference.snapshots().listen((datasnapshot) {
      setState(() {
        offerpostList = datasnapshot.documents;
      });
    });

    // _currentScreen();
  }

  @override
  void dispose() {
    subscription?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        body: offerpostList != null? new StaggeredGridView.countBuilder(
          padding: const EdgeInsets.all(8.0),
          crossAxisCount: 4,
          itemCount: offerpostList.length,
          itemBuilder: (context, i) {
            String imgPath = offerpostList[i].data['url'];
            String title = offerpostList[i].data['productTitle'];
            return new Material(
              elevation: 8.0,
              borderRadius:
              new BorderRadius.all(new Radius.circular(8.0)),
              child: new InkWell(
                child:new Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text(title,style: new TextStyle(
                        fontStyle: FontStyle.italic,
                        color: Colors.green[900],
                        fontSize: 16.0)),
                  new Hero(
                    tag: imgPath,
                    child:
                      new FadeInImage(
                      image: new NetworkImage(imgPath),
                      fit: BoxFit.cover,
                      placeholder: new AssetImage("assets/logo.png"),
                      ),


                  ),

              ],
                ),

              ),
            );
          },
          staggeredTileBuilder: (i) =>
          new StaggeredTile.count(2, i.isEven ? 2 : 3),
          mainAxisSpacing: 8.0,
          crossAxisSpacing: 8.0,
        )
            : new Center(
          child: new CircularProgressIndicator(),
        ));
  }
}

【问题讨论】:

    标签: firebase flutter


    【解决方案1】:

    flutter 中的列没有滚动功能。问题是您来自 firebase 的数据不能放在单个屏幕中。这就是引发溢出错误的原因。使用 ListView 代替具有滚动能力的 Column。

    【讨论】:

    • thanq 现在可以正常工作了.. 但是当尝试滚动全屏时,有时只有特定的文件是滚动的.. 我可以在图像上看到我的文字
    • 抱歉,我无法理解您的问题。你能发布实际和预期结果的截图吗?
    • 图片上的文字怎么可以不在图片的上方或下方
    • 使用 Stack 小部件包装图像和文本小部件。这将把一个放在另一个之上。
    • flutter 中的@Column 没有滚动功能。问题是您来自 firebase 的数据不能放在单个屏幕中。这就是引发溢出错误的原因。使用 ListView 而不是具有滚动能力的 Column....@ 单屏内将接受什么类型的数据
    【解决方案2】:

    设备中可用空间的列小部件可在 firebase 中获取 qll 数据并获得滚动效果,您可以使用 FirebaseAnimatedList。

    【讨论】:

      【解决方案3】:

      对于像文本覆盖图像的网格视图这样的 Olx,这里有一个示例。尝试一下并更改您的问题,因为它可能会产生误导。

      main.dart

      import 'package:cloud_firestore/cloud_firestore.dart';
      import 'package:firestore_grid_view/product.dart';
      import 'package:firestore_grid_view/product_details.dart';
      import 'package:flutter/material.dart';
      
      void main() => runApp(new MaterialApp(
            home: new MyApp(),
            debugShowCheckedModeBanner: false,
          ));
      
      class MyApp extends StatefulWidget {
        @override
        _MyAppState createState() => new _MyAppState();
      }
      
      class _MyAppState extends State<MyApp> {
        List<Product> _products = [];
      
        @override
        Widget build(BuildContext context) {
          return new Scaffold(
            appBar: new AppBar(
              title: new Text('Home'),
            ),
            body: new StreamBuilder<QuerySnapshot>(
              stream: Firestore.instance.collection('products').snapshots(),
              builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
                if (!snapshot.hasData) return new Text('Loading...');
                return new GridView.count(
                  crossAxisCount: 2,
                  children: _buildGrid(snapshot.data.documents),
                );
              },
            ),
          );
        }
      
        List<Widget> _buildGrid(List<DocumentSnapshot> documents) {
          List<Widget> _gridItems = [];
          _products.clear();
      
          for (DocumentSnapshot document in documents) {
            _products.add(new Product(
                name: document['productTitle'],
                category: document['category'],
                imageUrl: document['url'],
                contactNumber: document['contactNumber']));
          }
      
          for (Product product in _products) {
            _gridItems.add(_buildGridItem(product));
          }
      
          return _gridItems;
        }
      
        Widget _buildGridItem(Product product) {
          return new GestureDetector(
            child: new Card(
              child: new Stack(
                alignment: Alignment.center,
                children: <Widget>[
                  new Hero(
                    tag: product.name,
                    child: new Image.network(product.imageUrl, fit: BoxFit.cover),
                  ),
                  new Align(
                    child: new Container(
                      padding: const EdgeInsets.all(10.0),
                      child: new Text(product.name,
                          style: new TextStyle(color: Colors.white)),
                      color: Colors.black.withOpacity(0.4),
                      width: double.infinity,
                    ),
                    alignment: Alignment.bottomCenter,
                  ),
                ],
              ),
            ),
            onTap: () => onProductTapped(product),
          );
        }
      
        onProductTapped(Product product) {
          Navigator.of(context).push(new MaterialPageRoute(
              builder: (context) => new ProductDetails(product)));
        }
      }
      

      product_details.dart

      import 'package:firestore_grid_view/product.dart';
      import 'package:flutter/material.dart';
      
      class ProductDetails extends StatelessWidget {
        final Product product;
      
        ProductDetails(this.product);
      
        @override
        Widget build(BuildContext context) {
          return new Scaffold(
            body: new Column(
              children: <Widget>[
                new Expanded(child: new Container()),
                new Hero(
                    tag: product.name,
                    child: new Image(
                      image: new NetworkImage(product.imageUrl),
                      fit: BoxFit.fill,
                      width: double.infinity,
                      height: 300.0,
                    )),
                new Padding(
                  padding: const EdgeInsets.all(15.0),
                  child: new Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      new Padding(
                        padding: const EdgeInsets.only(right: 8.0),
                        child: new Text(
                          'Category -',
                          style: new TextStyle(
                              fontSize: 20.0, fontWeight: FontWeight.bold),
                        ),
                      ),
                      new Text(
                        product.category,
                        style: new TextStyle(
                            fontSize: 20.0, fontWeight: FontWeight.bold),
                      ),
                    ],
                  ),
                ),
                new Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 15.0),
                  child: new Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      new Padding(
                        padding: const EdgeInsets.only(right: 8.0),
                        child: new Text(
                          'Contact Number -',
                          style: new TextStyle(
                              fontSize: 20.0, fontWeight: FontWeight.bold),
                        ),
                      ),
                      new Text(
                        product.contactNumber,
                        style: new TextStyle(
                            fontSize: 20.0, fontWeight: FontWeight.bold),
                      ),
                    ],
                  ),
                ),
      
                new Expanded(child: new Container()),
              ],
            ),
          );
        }
      }
      

      product.dart

      class Product {
        final name, category, imageUrl, contactNumber;
      
        Product({this.name, this.category, this.imageUrl, this.contactNumber});
      }
      

      【讨论】:

        猜你喜欢
        • 2020-07-28
        • 2020-10-08
        • 2021-12-24
        • 2021-12-11
        • 2020-02-18
        • 2021-09-05
        • 1970-01-01
        • 2020-01-16
        • 2019-12-06
        相关资源
        最近更新 更多