Flutter应用缓慢 [英] Flutter app slow

查看:122
本文介绍了Flutter应用缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试Flutter,而我的应用在模拟器和真实设备上的响应速度都非常慢.我收到这样的警告

I'm trying out Flutter and my app is responding very very slow on both the emulator and real device. I get warnings like this

跳过51帧!该应用程序可能在其上进行了过多的工作主线程.

Skipped 51 frames! The application may be doing too much work on its main thread.

我知道Dart是一种单线程编程语言,在Android中,我曾经使用旧的 new Thread(); 块来解决此问题,以实现异步.我试图在Flutter中应用相同的内容,并通过 Future await async 和排序进行阅读,但是阅读时这些示例似乎正在解决来自互联网的数据.我的应用程序在此阶段无法在线阅读任何内容,当屏幕上出现进度对话框,打开新的屏幕/页面以及应用程序上的每个动画时,我都会收到跳过x帧".这是我遇到问题的班级示例:

I'm aware Dart is a single-threaded programming language and in Android I used to solve this with the good old new Thread(); block for async. I am trying to apply the same in Flutter and I reading through Future await async and the sorts but the examples seem to be addressing when you reading data from the internet. My app doesn't read anything online at this stage, I'm getting Skipped x frames when my screen has progress dialog, when I am opening a new screen/page, and with every animation on the app. Here is an example of the class where I am getting the issue:

_buildContent(){
    return new Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        new InkWell(
          onTap: (){
            Navigator.push(context, new MaterialPageRoute(builder:
                (context) => new LoginScreen()));
          },
          child: new Container(
            height: 150.0,
            width: 150.0,
            child: new Image.asset("images/logo.png", fit: BoxFit.cover,),
          ),
        ),
        new Container(
          margin: const EdgeInsets.all(16.0),
          child: new CircularProgressIndicator(
              value: null,
              strokeWidth: 1.0,
              valueColor: new AlwaysStoppedAnimation<Color>(
                  Colors.white
              )
          ),
        )
      ],
    );
  }

我假设跳过x帧警告是由进度对话框引起的?我有另一个屏幕(登录屏幕),该屏幕在打开时将小部件设置为动画,动画移动的速度非常慢,我可以从字面上看到正在渲染的每一帧.在线上是否有教程可以帮助您解决这个问题,或者只是了解Dart的异步编程?

I'm assuming the skipped x frames warning is caused by the progress dialog? I have another screen (Login Screen) which animates widgets into place when opened, the animations move so slow, I can literally see each frame being rendered. Is there a tutorial online that can assist with addressing this or just understanding Dart's Asynchronous Programming?

推荐答案

调试模式

  • 启动缓慢
  • 启动时闪烁
  • 应用大小很大.

因为调试模式具有热重载.

because debug mode with Hot reloads.

创建发行版本apk时 https://flutter.io/docs/deployment/android

您可以找到

  • 快速启动
  • 启动期间不眨眼
  • 应用尺寸小(但比普通的android应用大)

编辑

https://flutter.io/docs/testing/ui-performance#调试标志

调试模式启用了不在概要文件或发行版中运行的其他检查(例如断言),这些检查可能会很昂贵.调试模式还以与释放模式不同的方式执行代码.调试版本会在应用运行时及时"(JIT)编译Dart代码,但是在将应用加载到应用之前,配置文件和发布版本已预先编译为本机指令(也称为提前"或AOT)装置.JIT可能会导致应用暂停以进行JIT编译,这本身可能会导致垃圾邮件.

Debug mode enables additional checks (such as asserts) that don’t run in profile or release builds, and these checks can be expensive. Debug mode also executes code in a different way than release mode. The debug build compiles the Dart code "just in time" (JIT) as the app runs, but profile and release builds are pre-compiled to native instructions (also called "ahead of time", or AOT) before the app is loaded onto the device. JIT can cause the app to pause for JIT compilation, which itself can cause jank.

https://github.com/flutter/flutter/wiki/Flutter%27s模式

设备(包括模拟器,仿真器)上的调试模式:打开世界上所有的断言,包括所有调试信息,启用所有调试器辅助工具(例如天文台)和服务扩展.针对快速开发/运行周期进行了优化.没有针对执行速度,二进制大小或部署进行优化.由颤动运行使用.使用sky/tools/gn --android或sky/tools/gn --ios构建.有时也称为检查模式"或慢速模式".

Debug mode on device (including simulators, emulators): Turns on all the assertions in the world, includes all debugging information, enables all the debugger aids (e.g. observatory) and service extensions. Optimizes for fast develop/run cycles. Does not optimize for execution speed, binary size, or deployment. Used by flutter run. Built with sky/tools/gn --android or sky/tools/gn --ios. Also sometimes called "checked mode" or "slow mode".

这篇关于Flutter应用缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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