ScrollExtent在颤动中为负 [英] ScrollExtent is negative in flutter

查看:126
本文介绍了ScrollExtent在颤动中为负的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Flutter应用程序的此段上收到非常讨厌的错误,不知道为什么:

Getting a very pesky error on this segment of my Flutter app and no clue why:

child: GridView.builder(
    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 1,
        childAspectRatio: 4 / 3,
        mainAxisSpacing: 30.0,
        crossAxisSpacing: 20.0),
    padding: EdgeInsets.only(left: 20),
    scrollDirection: Axis.horizontal,
    itemCount: products.length,
    itemBuilder: (context, i) => ChangeNotifierProvider.value(
      value: products[i],
      child: Consumer<Product>(
        builder: (context, product, _) {
          return ProductCard(
              product: product,
              onSelected: (prod) {
                setState(() {
                  products.forEach(
                    (item) {
                      item.isSelected = false;
                    },
                  );
                  prod.isSelected = true;
                });
here's the error: SliverGeometry is not valid: The "scrollExtent" is negative.geometry: SliverGeometry(scrollExtent: -10.0, paintExtent: 20.0, maxPaintExtent: -10.0, cacheExtent: 20.0)
scrollExtent: -10.0
paintExtent: 20.0
maxPaintExtent: -10.0
cacheExtent: 20.0

填充:EdgeInsets(20.0,0.0,0.0,0.0)

padding: EdgeInsets(20.0, 0.0, 0.0, 0.0)

即使安装了apk,但该错误仍无法在Android上进行模拟,但该错误无法运行.它可以在iOS上运行,但错误仍然存​​在.

This error is preventing emulation on Android even though the apk is installed but it just won't run. It runs on iOS but the error remains.

推荐答案

是我的代码引起了同样的异常在发生异常之前

It is my code that was causing the same, Exception before exception

我搜索了很多内容,简而言之,这就是我的解决方法

我做了什么修复

就我而言,更改 gridDelegate ,我的异常已修复!

In my case, changing gridDelegate, my exception is fixed!

注意:请勿使用任何可能产生双精度值的数学运算(例如(/,*))!

如果喜欢对您有用,请给个赞!:)

give a like if it is Useful for you! :)

这篇关于ScrollExtent在颤动中为负的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆