坏消息:Flutter官方暂时不会开发热更新(Code push)了。

坏消息

自从接触Flutter以来一直就觉得热更新/动态化是一个关键的点,也是很多互联网厂家是否选择Flutter的重要因素甚至是首要因素,之前参加Google北京办公室举办的和Flutter工程师面对面的活动,来自各个厂家的程序员们提的最多的问题就是Flutter对热更新的支持。年初的时候看到2019年的Roadmap增加了对热更新的支持还着实高兴了一阵子,然而前一阵子去看相关的issue时候却发现了这个令人失望的消息:Flutter官方暂时不会开发热更新(Code push)了。

原文如下:

This was previously on our roadmap for 2019. After investigating this in greater detail, we have decided not to proceed with this work for now.

There were several factors that led us to this decision:

To comply with our understanding of store policies on Android and iOS, any solution would be limited to JIT code on Android and interpreted code on iOS. We are not confident that the performance characteristics of such a solution on iOS would reach the quality that we demand of our product. (In other words, "it woul

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flutter 中使用 GetX 库进行热更新,可以通过使用`flutter_getx`插件实现。以下是具体的实现步骤: 1. 在项目中添加`flutter_getx`插件,可以在`pubspec.yaml`文件中添加以下依赖: ```yaml dependencies: flutter_getx: ^1.0.0 ``` 然后执行`flutter pub get`命令安装插件。 2. 在项目中添加热更新相关的代码,例如: ```dart import 'package:flutter_getx/flutter_getx.dart'; class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return GetMaterialApp( title: 'MyApp', initialRoute: '/splash', getPages: [ GetPage(name: '/splash', page: () => SplashPage()), GetPage(name: '/home', page: () => HomePage()), ], smartManagement: SmartManagement.full, builder: EasyLoading.init(), ); } } ``` 在以上代码中,`SmartManagement.full`表示启用全局状态管理,`EasyLoading.init()`是一个用于显示加载状态的插件,可以根据需要添加或删除。 3. 在服务器端准备新版本的资源文件,例如: ``` http://yourserver.com/app-release.apk ``` 4. 在客户端使用`flutter_getx`插件进行热更新,例如: ```dart import 'package:flutter_getx/flutter_getx.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await UpdateUtil.init( updateUrl: 'http://yourserver.com/app-release.apk', callback: () => runApp(MyApp()), ); } ``` 在以上代码中,`UpdateUtil.init()`方法会检查服务器上是否有新版本的资源文件,如果有则下载并安装新版本,然后调用`callback`函数启动应用程序。如果没有新版本的资源文件,则直接启动应用程序。 注意:热更新只能新资源文件(例如图片、字体、代码等),无法新应用程序的逻辑代码。如果需要新逻辑代码,可以考虑使用 Flutter 的动态插件机制。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值