1

I am attempting to use a WebView inside of a Container inside of a Transform. I have attempted this with both flutter_webview and flutter_inappwebview.

However, the transform renders differently on Android and iOS when a Webview is involved (as opposed to a Container with anything else inside).

I am wondering what causes this, and if there is a known way to fix it. It impacts animations in some libraries, such as in a previous library-specific question I asked (which appears to be affected by this issue).

An example:

import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

String html =
    '<!DOCTYPE html><html><body bgcolor="red"><h1>My First Heading</h1><p>My first paragraph.</p></body></html>';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  InAppWebViewController webView;

  @override
  dispose() {
    webView.stopLoading();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Transform(
          transform: pvMatrix,
          alignment: FractionalOffset.center,
          child: Container(
            color: Colors.orange,
            child: Container(
              child: InAppWebView(
                initialUrl: "",
                initialHeaders: {},
                initialOptions: InAppWebViewGroupOptions(
                  crossPlatform: InAppWebViewOptions(
                    debuggingEnabled: true,
                  ),
                ),
                onWebViewCreated: (InAppWebViewController controller) {
                  webView = controller;
                  webView.loadData(data: html);
                },
              ),
              margin: EdgeInsets.all(50),
            ),
            height: 500,
          ),
        ));
  }

  final Matrix4 pvMatrix = Matrix4.identity()..setEntry(3, 3, 1 / 0.9);
}

On Android:

enter image description here

On iOS:

enter image description here

Many thanks for any ideas or insight!

JosephG
  • 3,111
  • 6
  • 33
  • 56

0 Answers0