您当前的位置: 首页 >  windows

大前端之旅

暂无认证

  • 4浏览

    0关注

    403博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

flutter项目打包.exe文件发布windows版

大前端之旅 发布时间:2021-09-28 15:08:14 ,浏览量:4

目录
  • 发布windows版
    • 1.为现有的 Flutter 应用程序添加桌面支持
    • 2..创建main_desktop.dart文件
    • 3.hover安装和环境配置
    • 4.初始化,并打包
    • 坑1

发布windows版

image-20210928095003619

我们希望你完成迁移后尽快将其发布,可以作为预览版:

参考文章: https://dart.cn/null-safety/migration-guide

迁移桌面 flutter config --enable--desktop

image-20210927100236887

1.为现有的 Flutter 应用程序添加桌面支持

要将桌面支持添加到现有 Flutter 项目,请从项目根目录在终端中运行以下命令:

$ flutter create --platforms=windows,macos,linux .

这会将必要的桌面文件和目录添加到您现有的 Flutter 项目中。要仅添加特定桌面平台,请将platforms列表更改为仅包含您要添加的平台。

image-20210927100948120

必须下载vs

https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=Community&rel=16

可以看到build目录下已经有windows

image-20210928082949206

2…创建main_desktop.dart文件

比如我的main.dart文件是这样的

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:outlook/constants.dart';
import 'package:outlook/screens/main/main_screen.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter blog',
      theme: ThemeData(),
      home: MainScreen(),
    );
  }
}

那么我的main_desktop.dart文件就是这样的

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:outlook/constants.dart';
import 'package:outlook/screens/main/main_screen.dart';

void main() {
  debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;//这句话很关键
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter blog',
      theme: ThemeData(),
      home: MainScreen(),
    );
  }
}

flutter和go都是google出品,如何安装做一下不做介绍

3.hover安装和环境配置
go get -u github.com/go-flutter-desktop/hover

稍等会hover就会出现在go语言的SDK下面的bin文件夹下

image-20210928084124073

你又会发现报错:**exec: “gcc”: executable file not found in %PATH%**这是缺少一个环境变量,别急,补上去, https://sourceforge.net/projects/mingw-w64/files/mingw-w64/

image-20210928084641518

img

img

image-20210928084842376

img

安装过程会下载很多东西,都到这一步了,不要放弃,接下来配置环境变量

C:\Program Files (x86)\mingw-w64\i686-6.2.0-posix-sjlj-rt_v5-rev1\mingw32\bin

img

4.初始化,并打包

接下来,我们到你的flutter项目的目录下面

hover init github.com/my-organization/flutter_bloc_super #前面的地址固定,后面写你项目的名字

就会出现一个go文件夹

image-20210928091320860

生成这个文件之后再执行,

hover run

最后一步大功告成

变身!!!!! 如图的路径就是打包后生成的exe文件,双击执行,就好了。

image-20210928091457350

坑1

如果报错goland编译报错cc1.exe: sorry, unimplemented: 64-bit mode not compiled in

主要原因是本地的cc1.exe版本不是64位的,在64位环境下无法编译

请下载这个、https://sourceforge.net/projects/mingw-w64/

image-20210928090948605

关注
打赏
1660524863
查看更多评论
立即登录/注册

微信扫码登录

0.0360s