Slow Flutter GridView

问题描述 投票:0回答:1

我需要创建一个52x80的正方形方块网格。看起来像这样:

enter image description here

但是在仿真器中开发时性能特别慢(超过1s的“滞后”)。我了解Flutter代码在物理设备上的发布模式下运行得更快,在我的情况下,如果设备是新设备,也是如此。但是,如果设备使用了几年(例如,三星Galaxy S8或iPhone 8),则在加载视图和滚动时会有令人沮丧的明显时间。而且我不能那样发布我的应用程序。我正在这样构建我的GridView:

  GridView.count(
    shrinkWrap: true,
    primary: false,
    padding: const EdgeInsets.all(5.0),
    crossAxisCount: 52,
    crossAxisSpacing: 1.0,
    mainAxisSpacing: 1.0,
    addAutomaticKeepAlives: true,
    children: blocks.map((block) => // blocks is just a list of 4160 objects
      FlatButton(
        child: null,
        color: block.backgroundColor,
        onPressed: () {
          // open a new route
        },
        splashColor: Colors.transparent,  
        highlightColor: Colors.transparent
      )
    ).toList()
  )

我已经尝试将FlatButton换成ImageSizedBox,这会有所帮助。关于如何提高速度的任何建议?

android ios flutter dart flutter-layout
1个回答
0
投票

要查看您的应用在设备上运行的速度如何,您可以在Android Studio的“配置文件”中运行它。它将像没有所有权限的情况下构建应用程序一样运行它。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.