vendredi 3 septembre 2021

Flutter on web : How to get Iframe height to put in SingleChildScrollView

I am working on a webview based on Iframe for the desktop web version of my app, I want to get rid of the Iframe scrollbar and use flutter scrolling (ie:SingleChildScrollView), however this widget bugs if I dont give it's child a fixed size, I don't see how I can estimate the height of the Iframe after the page loads.

import 'package:flutter/cupertino.dart';
import 'dart:html' as html;
import 'dart:ui' as ui;

class MyWebView extends StatefulWidget {
  @override
  MyWebViewState createState() => MyWebViewState();
}

class MyWebViewState extends State<MyWebView> with AutomaticKeepAliveClientMixin{
  html.IFrameElement _iframeElement = new html.IFrameElement();
  late HtmlElementView _element;
  String element="myelement";

  @override
  void initState() {
    super.initState();

    _iframeElement.src = 'https://github.com/flutter/flutter/issues';
    _iframeElement.style.border = 'none';
    _iframeElement.style.width = '100%';
    _iframeElement.style.height = '100%';
    _iframeElement.contentEditable='false';
    _iframeElement.id=element;

    // ignore: undefined_prefixed_name
    ui.platformViewRegistry.registerViewFactory(
        element,
            (int viewId) {
          final wrapper = html.DivElement();
          final div = html.DivElement()
            ..contentEditable = 'false'
            ..style.width = '100%'
            ..style.height = '100%'
            ..style.background='#00000011'
            ..style.position='absolute'
            ..style.left='0'
            ..style.top='0';

          wrapper.append(_iframeElement);
          wrapper.append(div); //to prevent Iframe intercepting events
          return wrapper;
        }
    );

    _element=new HtmlElementView(viewType: element);
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(child: SizedBox(height:5000/*How to get Iframe Height??*/,child: _element));
  }

  @override
  void dispose() {super.dispose();}
  @override
  bool get wantKeepAlive => true;
}



Aucun commentaire:

Enregistrer un commentaire