专业的编程技术博客社区

网站首页 > 博客文章 正文

Flutter 2 的Windows 开发试验

baijin 2025-01-12 11:20:00 博客文章 8 ℃ 0 评论

刚安装了flutter 2.1 dev 版本,测试下很感觉兴趣的Windows开发

当前flutter 环境为(flutter doctor):

Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel dev, 2.1.0-10.0.pre, on Microsoft Windows [Version 10.0.19042.804], locale zh-CN)
[?] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
[?] Chrome - develop for the web
[?] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.6)
[?] Android Studio (version 4.1.0)
[?] IntelliJ IDEA Ultimate Edition (version 2020.1)
[?] VS Code, 64-bit edition (version 1.51.1)
[!] Proxy Configuration
    ! NO_PROXY is not set
[?] Connected device (3 available)

! Doctor found issues in 1 category.

一 打Android Studio ,创建项目

二 创建项目向导完成后,进入编辑界面,选择目标设备为 "Windows",开始运行调试


不幸的,报错了。。。从错误信息来的,刚创建的项目,是不支持Windows 桌面的

根据错误信息里的网页链接的指导,在项目的根目录下执行指令添加Windows 桌面相关项目信息:

flutter create --platforms=windows .

应该是添加了C++代码,使用C++代码启动Flutter引擎并进入主页面


三 尝试做点小小的修改:移除了按钮,并添加了一个定时器,每秒更新一下文本:

class _MyHomePageState extends State<MyHomePage> {
  
  String text="---";
  
  @override
  void initState() {
    super.initState();

    new Timer.periodic(Duration(seconds: 1), (e)=>{
      this.setState(()=> {
        text=  DateTime.now().toString()
      })
    });
  }

  @override
  Widget build(BuildContext context) {    
    return Scaffold(
      appBar: AppBar(      
        title: Text(widget.title),
      ),
      body: Center(       
        child: Column(        
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              '当前时间为:',
            ),
            Text(
              text,
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),       
    );
  }
}


能正确的运行!


四 编译打包

在根目录下执行“flutter build windows",之后得到了以下两个文件和一个目录,可以执行。将其复制到另一台没有安装flutter 环境的windows机器上,也可以执行。测试通过!



比起flutter 1.0 来说,2.0 的windows 开发过程让我印象深刻,简单的运行没有问题了。不过windows还开发还有很多复杂的问题,期待越来越完美。

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表