简体   繁体   English

在我的 Flutter 应用程序中,从 firebase 获取产品时显示 RangeError(索引):无效值:有效值范围为空:0

[英]In My Flutter Application while Fetching products from firebase showing RangeError (index): Invalid value: Valid value range is empty: 0

This is my code when I run this code it shows me error valid range is empty:0 At the output screen, some images are working properly but when I click on some images it shows me the error valid range is empty:0这是我的代码,当我运行此代码时,它显示错误有效范围为空:0在输出屏幕上,某些图像工作正常,但是当我单击某些图像时,它显示错误有效范围为空:0

import 'package:flutter_ecommerce/provider/product.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'featured_card.dart';

class FeaturedProducts extends StatefulWidget {
  @override
  _FeaturedProductsState createState() => _FeaturedProductsState();
}

class _FeaturedProductsState extends State<FeaturedProducts> {
  @override
  Widget build(BuildContext context) {
    final productProvider = Provider.of<ProductProvider>(context);

    return Container(
        height: 230,
        child: ListView.builder(
            scrollDirection: Axis.horizontal,
            itemCount: productProvider.products.length,
            itemBuilder: (_, index) {
              return FeaturedCard(
                product: productProvider.products[index],
              );
            }));
  }
}

Please help me in this error请帮我解决这个错误

You should check if productProvider.products.length == 0 show a loader or everything you want otherwise show the ListView widget.您应该检查 productProvider.products.length == 0 是否显示加载程序或您想要的所有内容,否则显示 ListView 小部件。

import 'package:flutter_ecommerce/provider/product.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'featured_card.dart';

class FeaturedProducts extends StatefulWidget {
  @override
  _FeaturedProductsState createState() => _FeaturedProductsState();
}

class _FeaturedProductsState extends State<FeaturedProducts> {
  @override
  Widget build(BuildContext context) {
    final productProvider = Provider.of<ProductProvider>(context);

    return Container(
        height: 230,
        child: productProvider.products.length == 0 
            ?
            Center(child: CircularProgressIndicator()) 
            :
            ListView.builder(
            scrollDirection: Axis.horizontal,
            itemCount: productProvider.products.length,
            itemBuilder: (_, index) {
              return FeaturedCard(
                product: productProvider.products[index],
              );
            }
       )
     );
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter:RangeError(索引):无效值:有效值范围为空:0 - Flutter: RangeError (index): Invalid value: Valid value range is empty: 0 Flutter rangeError (index) 有效值范围为空 - Flutter rangeError (index) Valid value range is empty Flutter 错误:未处理的异常:RangeError(索引):无效值:有效值范围为空:0 - Flutter Error : Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 0 RangeError(索引):无效值:有效值范围为0 - RangeError (index): Invalid value: Valid value range is 0 无法解决此错误:RangeError(索引):无效值:有效值范围为空:0 - Unable to solve this error : RangeError (index): Invalid value: Valid value range is empty: 0 Flutter 错误:RangeError (index): Invalid value: Not in range 0..2, inclusive: 3 - Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3 RangeError(索引):无效值:不在0..5范围内(包括6):Flutter SliverChildBuilderDelegate - RangeError (index): Invalid value: Not in range 0..5, inclusive: 6 : Flutter SliverChildBuilderDelegate Flutter:RangeError(索引):无效值:不在包含范围 0..27:28 - Flutter : RangeError (index): Invalid value: Not in inclusive range 0..27: 28 RangeError (index): Invalid value: Not in range 0..3, inclusive: 4 in Flutter - RangeError (index): Invalid value: Not in range 0..3, inclusive: 4 in Flutter 颤振范围错误(索引):无效值:不在包含范围内 0..4:CarouselSlider 上的 5 - flutter RangeError (index): Invalid value: Not in inclusive range 0..4: 5 on CarouselSlider
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM