WebViews in Flutter - Does it really work?

WebViews in Flutter - Does it really work?

Talk given at Flutter London meetup
https://www.meetup.com/FlutterLDN/events/262574231/

8f5449e0199b2328460b35108934bcad?s=128

Lara Martín

July 15, 2019
Tweet

Transcript

  1. 1.
  2. 3.

    Why we need WebViews? Use cases Perform social login Show

    static content (e.g. FAQ) Payment confirmation Avoid for Making an app that is just a web
  3. 6.

    Implementation • Not reimplemented in Dart! • Uses native WebView

    iOS: WKWebView Android: android.webkit.WebView • But is it a Widget? The plugin creates the native WebView And renders it in Flutter!
  4. 12.

    WebView Rendering on Android AndroidView _AndroidPlatformView RenderAndroidView : RenderBox WebView

    renders contains … in requires WebViewFactory surface ID contains child PlatformViewController FlutterWebView : PlatformView creates WebViewFlutterPlugin registers Surface WebView contains
  5. 14.

    WebView Rendering on iOS • Similar to Android • RenderUiKitView

    will render a surface created in the PlatformViewIOS • Passes an ID
  6. 16.

    WebView Widget • InitialUrl • javaScriptMode • onWebViewCreated • onPageFinished

    • gestureRecognizers • navigationDelegate • javaScriptChannels
  7. 17.

    WebView Widget • InitialUrl • javaScriptMode • onWebViewCreated • onPageFinished

    • gestureRecognizers • navigationDelegate • javaScriptChannels
  8. 20.

    WebView Widget • InitialUrl • javaScriptMode • onWebViewCreated • onPageFinished

    • gestureRecognizers • navigationDelegate • javaScriptChannels
  9. 22.

    WebView Widget • InitialUrl • javaScriptMode • onWebViewCreated • onPageFinished

    • gestureRecognizers • navigationDelegate • javaScriptChannels
  10. 24.
  11. 25.
  12. 27.

    WebView Widget • InitialUrl • javaScriptMode • onWebViewCreated • onPageFinished

    • gestureRecognizers • navigationDelegate • javaScriptChannels
  13. 29.

    WebView Widget • InitialUrl • javaScriptMode • onWebViewCreated • onPageFinished

    • gestureRecognizers • navigationDelegate • javaScriptChannels
  14. 30.

    WebView Widget • InitialUrl • javaScriptMode • onWebViewCreated • onPageFinished

    • gestureRecognizers • navigationDelegate • javaScriptChannels The Power of WebViews in Flutter, by Emily Fortuna https:/ /medium.com/flutter-io/the-power-of-webviews-in-flutter- a56234b57df2
  15. 31.

    WebView Widget • InitialUrl • javaScriptMode • onWebViewCreated • onPageFinished

    • gestureRecognizers • navigationDelegate • javaScriptChannels
  16. 33.

    WebView Widget: NavigationDelegate WebView( navigationDelegate: (request) { bool isHost =

    request.url.startsWith( “https://flutter.dev”); if (isHost) return NavigationDecision.navigate; else return NavigationDecision.prevent; } );
  17. 34.

    WebView Widget • InitialUrl • javaScriptMode • onWebViewCreated • onPageFinished

    • gestureRecognizers • navigationDelegate • javaScriptChannels
  18. 36.

    WebView Widget: javaScriptChannels WebView( javascriptChannels: {_channel}, ); var _channel =

    JavascriptChannel( name: 'LaraDemo', onMessageReceived: (JavascriptMessage message) { print(message.message); });
  19. 37.

    WebView Widget: javaScriptChannels WebView( javascriptChannels: {_channel}, ); var _channel =

    JavascriptChannel( name: 'LaraDemo', onMessageReceived: (JavascriptMessage message) { print(message.message); });
  20. 38.

    WebView Widget: javaScriptChannels WebView( javascriptChannels: {_channel}, ); var _channel =

    JavascriptChannel( name: 'LaraDemo', onMessageReceived: (JavascriptMessage message) { print(message.message); });
  21. 39.

    WebView Widget: javaScriptChannels WebView( javascriptChannels: {_channel}, ); var _channel =

    JavascriptChannel( name: 'LaraDemo', onMessageReceived: (JavascriptMessage message) { print(message.message); });
  22. 40.

    WebView Widget: javaScriptChannels var _channel = JavascriptChannel( name: 'LaraDemo', onMessageReceived:

    (JavascriptMessage message) { print(message.message); }); Flutter side <script> LaraDemo.postMessage('Hello'); </script> HTML side
  23. 57.

    57 L a r a M a r t í

    n F l u t t e r / D a r t G D E 
 A n d r o i d D e v e l o p e r @ L a r i k i Thank You!