错误: - 抛出另一个异常:RenderFlex底部溢出33个像素

时间:2018-05-29 05:04:32

标签: firebase flutter

[在此输入图片说明]
1显示我运行我的应用时出错...我的代码在下面...任何人都可以告诉我的代码有什么问题 /////////////////////// 当我运行我的应用程序时显示错误...我的代码在下面...任何人都可以告诉我的代码有什么问题 ///////////////////////

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

'软件包:flutter_staggered_grid_view / flutter_staggered_grid_view.dart&#39 ;;

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(),
        ));
  }
}

3 个答案:

答案 0 :(得分:0)

flutter中的列没有滚动功能。问题是来自firebase的数据不能适合单个屏幕。这就是抛出溢出错误的原因。使用ListView而不是具有滚动功能的Column。

答案 1 :(得分:0)

设备中可用房间的列小部件,用于获取firebase中的qll数据,以及获取滚动效果,您可以使用FirebaseAnimatedList。

答案 2 :(得分:0)

对于具有文本图像的网格视图的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});
}