Flutter-桌面开发的新玩具

Flutter-桌面开发的新玩具

建个夹子备用

cd D:
makedir D:\FlutterDesktop
cd FlutterDesktop

拿一下flutter-desktop-embedding的代码

git clone http://github.com/flutter/flutter
git clone https://github.com/google/flutter-desktop-embedding

进入example 目录build一下

start D:\FlutterDesktop\flutter-desktop-embedding\example\windows

这里会需要用到VS2017 express

第一次编译会自动下载flutter相关的binary

1>------ Build started: Project: GLFW Library, Configuration: Debug Dynamic Library x64 ------
1>Get the flutter engine, engine artifacts and GLFW
1>Checking Dart SDK version...
1>Downloading Dart SDK from Flutter engine d8c5ec0e11b51ff385327fe5939f9405f89f46c7...
1>Unzipping Dart SDK...
1>Building flutter tool...
1>Running pub upgrade...
1>Downloading Material fonts...                                    1.3s
1>Downloading package sky_engine...                                1.5s
1>Downloading common tools...                                      2.2s
1>Downloading windows-x64 tools...                                 2.5s
1>Downloading android-arm-profile/windows-x64 tools...             1.6s
1>Downloading android-arm-release/windows-x64 tools...             1.6s
1>Downloading android-arm64-profile/windows-x64 tools...           1.5s
1>Downloading android-arm64-release/windows-x64 tools...           2.1s
1>Downloading android-x86 tools...                                 2.4s
1>Downloading android-x64 tools...                                 2.2s
1>Downloading android-arm tools...                                 1.5s
1>Downloading android-arm-profile tools...                         1.5s
1>Downloading android-arm-release tools...                         1.6s
1>Downloading android-arm64 tools...                               2.1s
1>Downloading android-arm64-profile tools...                       1.4s
1>Downloading android-arm64-release tools...                       2.0s
1>Downloading android-arm-dynamic-profile tools...                 1.6s
1>Downloading android-arm-dynamic-release tools...                 1.8s
1>Downloading android-arm64-dynamic-profile tools...               1.7s
1>Downloading android-arm64-dynamic-release tools...               1.9s
1>Downloading Gradle Wrapper...                                    0.8s
1>Downloaded flutter_engine.dll version d8c5ec0e11b51ff385327fe5939f9405f89f46c7.
1>1 File(s) copied


再运行一下即可看到Flutter在Windows上跑起来。

编译出来的尺寸比起electron 还是不错的,为了跑104K的代码用一个16M的库还算可以。

这个Example里的GLFW Library是Flutter用OpenGL的Embedder,自己建项目也可以用这个。

C部分的Code是这个样子的,界面里跑的逻辑仍然是Dart的。这里入口已经是C的了,所以Go完全可以用起来。

#include <iostream>
#include <vector>

#include <embedder.h>

int main(int argc, char **argv) {
  if (!FlutterInit()) {
    std::cout << "Couldn't init GLFW" << std::endl;
  }
  // Arguments for the Flutter Engine.
  std::vector<std::string> arguments;
  // First argument is argv[0] since the engine is expecting real command line
  // args.
  arguments.push_back(argv[0]);
#ifndef _DEBUG
  arguments.push_back("--dart-non-checked-mode");
#endif
  // Start the engine.
  // TODO: Make paths relative to the executable so it can be run from anywhere.
  auto window = CreateFlutterWindowInSnapshotMode(
      640, 480, "..\\..\\example\\flutter_app\\build\\flutter_assets",
      "..\\..\\library\\windows\\dependencies\\engine\\icudtl.dat", arguments);
  if (window == nullptr) {
    FlutterTerminate();
    return EXIT_FAILURE;
  }

  FlutterWindowLoop(window);
  FlutterTerminate();
  return EXIT_SUCCESS;
}

修改一下C code中的路径,把包都拿出来,这个内容就可以用来打包了。

这玩意尚处在早期阶段,用GLFW来Rendering和接收KeyEvent,现在键盘支持都没有做好,只是简单的支持退出事件。Rendering完全没有优化,只是简单pass canvas get flutter边缘平滑,抗锯齿都没有用上。看来再等等就可以用了

编辑于 2018-12-25