Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AndroidView去加载webview无法显示 #37

Closed
Wanchen7 opened this issue Mar 19, 2019 · 8 comments
Closed

AndroidView去加载webview无法显示 #37

Wanchen7 opened this issue Mar 19, 2019 · 8 comments

Comments

@Wanchen7
Copy link

场景:
flutter端 从 A页面跳转到B页面 并且销毁A页面,在B页面通过androidview 加载一个原生的webview页面。但是无法显示出来。

初步定位:
1、flutterview 是单例,所以FlutterPluginRegistry的attach的时候,context是A页面的。
2、在PlatformViewFactory 的create 方法里面 context是SingleViewPresentation持有的,也就是A页面的context。但是A已经销毁了,所以显示不出来。

问题:有些手机是android 9.0的可以显示出来的,但是我手头上的一个pad是7.0的就无法显示。

这个有解吗?

@Wanchen7
Copy link
Author

我尝试这样改是可以解决:

屏幕快照 2019-03-20 下午2 20 51

@ruanchaohouzi
Copy link

@nightwolf-chen @Wanchen7 其实这个问题,我老早就提出来了,只是作者不愿意测试这个问题也不愿意解决,如果连最基本的WebView都不支持,开源还有什么意思???

@ruanchaohouzi
Copy link

我尝试这样改是可以解决:

屏幕快照 2019-03-20 下午2 20 51

@Wanchen7
为啥我按照你这样操作,还是加载不了WebView,WebView一直转圈加载中,就是加载不出页面

@Wanchen7
Copy link
Author

Wanchen7 commented Mar 25, 2019

我尝试这样改是可以解决:
屏幕快照 2019-03-20 下午2 20 51

@Wanchen7
为啥我按照你这样操作,还是加载不了WebView,WebView一直转圈加载中,就是加载不出页面

@ruanchaohouzi 你尝试这样做:

abstract class BaseState<T extends StatefulWidget> extends State<T>
    with WidgetsBindingObserver {
  final MethodChannel _channel = const MethodChannel('flutter/platform_views');

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  void _updatePlatformView() async {
    await _channel.invokeMethod('dispose');
    await _channel.invokeMethod('create');
    setState(() {});
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    switch (state) {
      case AppLifecycleState.paused:
        break;
      case AppLifecycleState.resumed:
        _updatePlatformView();
        break;
      default:
    }
  }
}

1、在flutter端 写一个state的基类并且 with WidgetsBindingObserver 复写它的方法
2、创建一个“flutter/platform_views” 的MethodChannel 然后
3、在AppLifecycleState.resumed 的时候发送 “dispose” 和 “create” 消息

前面写的原生端的代码可以去掉了。

@jp1017
Copy link

jp1017 commented Apr 15, 2019

1、在flutter端 写一个state的基类并且 with WidgetsBindingObserver 复写它的方法

只在webview页面使用这个BaseState不行啊,怎么使用的呢,每个页面都用?

@jp1017
Copy link

jp1017 commented May 15, 2019

还是写个插件调用原生的WebView吧,,,

@timelove
Copy link

老哥,太强了,我不是 webview 加载不了,我是有一个手机红米5加载各种 androidView 都出现不了,底层报 dialog 获取不到context。果然是flutterboost 的坑。用了这个方法,搞定

@A-jiaotailang
Copy link

所以这个flutterboost 调用原生的webview 怎么解决呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants