在gridview中查找networkimage时,应用程序崩溃

时间:2019-06-18 08:22:13

标签: flutter

我正在使用Future创建图像的gridview,但是在滚动gridview应用程序时崩溃,并且没有错误,只是

与设备的连接丢失。

退出(sigterm)

图像在上下滚动时重新出现和消失。

我尝试使用image.network,缓存的网络映像,fadein映像,但无法正常工作。我也将图像请求限制为40个,但也崩溃了。图像大小只有20-100 kb。

// Your service
@Injectable()
class SomeService {
  rootTreeElement;

  registerElement(element: any, ticksToCallback: number): void {
    this.sortIntoTree(this.rootTreeElement, ticksToCallback, element);
  }

  private sortIntoTree(rootTreeElement, ticksToCallback, element) {
    for (let i = 0; i < ticksToCallback; i++) {
      if (element.associatedObject.timeOutCallback) { // You can check like this if callback is provided
        element.associatedObject.timeOutCallback();
      }
    }
  }
}

// Tests
describe('SomeService', () => {
  let service: SomeService;
  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [SomeService]
    });
    service = TestBed.get(SomeService);
  });

  it('should call callback 5 times', () => {
    const mockElement = {associatedObject: {timeOutCallback: createSpy()}};

    service.registerElement(mockElement, 5);

    expect(mockElement.associatedObject.timeOutCallback).toHaveBeenCalledTimes(5);
  });
});

1 个答案:

答案 0 :(得分:0)

我创建了相同类型的应用。我发现 NeverScrollableScrollPhysics()对于可滚动图像gridview非常有用。希望以下代码段对您有所帮助。

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Column(
          children: <Widget>[
            ConstrainedBox(
              constraints: BoxConstraints(
                minHeight: 10, // Set as you want or you can remove it also.
                maxHeight: double.infinity,
              ),
              child: Container(
                child: GridView.count(
                  crossAxisCount:
                      MediaQuery.of(context).orientation == Orientation.portrait
                          ? 3
                          : 4,
                  shrinkWrap: true,
                  scrollDirection: Axis.vertical,
                  physics: NeverScrollableScrollPhysics(),
                  childAspectRatio: .6,
                  children: thumbUrls
                      .map((urlThumb) => Card(
                            child: Container(
                                decoration: BoxDecoration(color: Colors.white),
                                child: GestureDetector(
                                  onTap: () => Navigator.push(context,
                                          new MaterialPageRoute(
                                              builder: (context) {
                                        return new FullScreenImagePage(wallpapers[urlThumb]);//Map wallpaper = {url_thumb : [id, url_image]}
                                      })),
                                  child: new Image.network(
                                    urlThumb,
                                    fit: BoxFit.cover,
                                  ),
                                )),
                          ))
                      .toList(),
                ),
              ),
            )
          ],
        ),
      ],
    );
  }
}