mpflutter / mpflutter

MPFlutter 是一个跨平台 Flutter 开发框架,可用于微信小程序以及 Web 应用开发。
http://mpflutter.com/
Apache License 2.0
1.94k stars 133 forks source link

使用getx库,如果页面使用了Platform View会导致GetxController释放失败,报错 #531

Closed a395726103 closed 9 months ago

a395726103 commented 9 months ago

awesome_project.zip demo中地图页面第一次进去会正常初始化,返回页面够再进去GetxController因为没释放,所以不会初始化了,

image e869295b8a2215761aba34c504016a7

PonyCui commented 9 months ago

提供一下代码

a395726103 commented 9 months ago

提供一下代码

上面发了代码

PonyCui commented 9 months ago

没用过 GetX,我也不知道这题怎么解,Controller 理应随页面结束而更换,没理由一直保持旧的 Controller 不变。

Gavin0x0 commented 9 months ago

试试使用 binding 来管理 Controller

// routes: {
//   '/map_demo': (context) => WXMapView(),
// },
getPages: [
  GetPage(
    name: "/map_demo",
    page: () => WXMapView(),
    binding: WXMapViewBinding(),
  ),
],
class WXMapViewBinding implements Bindings {
  @override
  void dependencies() {
    Get.lazyPut<WXMapViewController>(() => WXMapViewController());
  }
}
class WXMapView extends GetView<WXMapViewController> {
  WXMapView({super.key}) {}
  .......
a395726103 commented 9 months ago

没用过 GetX,我也不知道这题怎么解,Controller 理应随页面结束而更换,没理由一直保持旧的 Controller 不变。

页面中有Platform View才会导致不能释放,没有Platform View可以正常释放

a395726103 commented 9 months ago

试试使用 binding 来管理 Controller

// routes: {
//   '/map_demo': (context) => WXMapView(),
// },
getPages: [
  GetPage(
    name: "/map_demo",
    page: () => WXMapView(),
    binding: WXMapViewBinding(),
  ),
],
class WXMapViewBinding implements Bindings {
  @override
  void dependencies() {
    Get.lazyPut<WXMapViewController>(() => WXMapViewController());
  }
}
class WXMapView extends GetView<WXMapViewController> {
  WXMapView({super.key}) {}
  .......

你这个只适合跳转的新页面,不适合一个页面嵌套多个页面的情况

a395726103 commented 9 months ago

没用过 GetX,我也不知道这题怎么解,Controller 理应随页面结束而更换,没理由一直保持旧的 Controller 不变。

可不可以给Platform View提供一个手动释放的函数

PonyCui commented 9 months ago

没用过 GetX,我也不知道这题怎么解,Controller 理应随页面结束而更换,没理由一直保持旧的 Controller 不变。

可不可以给Platform View提供一个手动释放的函数

加个 dispose 应该可以

PonyCui commented 9 months ago

已修复,请使用 mpflutter_core: 2.1.2 mpflutter_build_tools: 2.1.2 mpflutter_wechat_api: 2.1.0 mpflutter_wechat_mapview: 0.0.3