alibaba / fish-redux

An assembled flutter application framework.
https://github.com/alibaba/fish-redux
Apache License 2.0
7.33k stars 843 forks source link

集成flutter_boost, 2次进入页面通过context获取屏幕宽高为零 #548

Closed Long2King closed 4 years ago

Long2King commented 4 years ago

Describe the bug 在fish_redux框架下集成flutter_boost进行混合开发,flutter页面获取宽高为零 Show the code you wrote as completely as possible. main.dart FlutterBoost.singleton.registerPageBuilders({ "vehicle://vehicle_setting_engine_plate_page":(pageName, params,uniqueId) => EngineNumberPage().buildPage(Map<String, dynamic>.from( params..addAll({"uniqueId": uniqueId}))), }); engine_number_page 的 view.dart Widget buildView(EngineNumberState state, Dispatch dispatch, ViewService viewService) { var w = MediaQuery.of(viewService.context).size.width; }

To Reproduce 1、从原生页面通过flutter_boost跳转flutter页面 2、在view.dart的buildView方法中,通过MediaQuery.of(viewService.context).size.width 3、首次进入页面可以正常获取宽高,第二次进入页面以后获取的宽高均为0

Expected behavior 期望每次进入页面都可以通过context正常获取宽高

Additional context

  1. flutter_boost : 0.1.61
  2. fish_redux :0.3.1
  3. flutter : 1.9.1
zjuwjf commented 4 years ago

和框架无关,和时机有关。确保context是已经可使用的。

Long2King commented 4 years ago

感谢回复! 另外: 1、context是通过 viewService.context获取的,假设不可用那也是viewService有问题? 2、请问关于fish_redux与flutter_boost有集成的demo吗?

Long2King commented 4 years ago

已解决,通过新建Widget,用其build方法里的context即可。谢谢