flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.45k stars 27.31k forks source link

Error: Unexpected null value while navigating from tab1 to tab 2 (Flutter Web - Using HTMLElementView) #72098

Open Damandroid opened 3 years ago

Damandroid commented 3 years ago

Hi, simple use of HTMLElementView is causing issues in my app.

My code is as follows:

Code ``` import 'dart:html'; import 'package:myPackage/constants.dart'; import 'package:myPackage/contentProvider/contentProvider.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'dart:html' as html; import 'dart:js' as js; import 'dart:ui' as ui; class Payment extends StatefulWidget { @override _PaymentState createState() => _PaymentState(); } String viewID = "myView"; String urlOnline = "myURL"; String urlLocal = "my localhost url"; bool online = true; class _PaymentState extends State { IFrameElement element; @override Widget build(BuildContext context) { double total = Provider.of(context).getTotal(); // ignore:undefined_prefixed_name ui.platformViewRegistry.registerViewFactory( viewID, (int id) { element = html.IFrameElement(); window.onMessage.forEach((element) { if(element.data=='Authorised'){ print("Successful payment"); Navigator.pop(context); // This throws the error explained above } else if(element.data=='Pending'){ print('PAYMENT Pending'); }else if(element.data=='Refused'){ print('PAYMENT Refused'); } }); element.width = MediaQuery.of(context).size.width.toString(); element.height = MediaQuery.of(context).size.height.toString(); element.src = online? urlOnline : urlLocal; element.style.border = 'none'; return element; } ); return Scaffold( appBar: AppBar( iconTheme: IconThemeData( color: Colors.white, //change your color here ), elevation: 0.0, title: Text("PAYMENT", style: Header), backgroundColor: Provider.of(context, listen: false).primary, ), backgroundColor: Color(0xfff6f7f8), body: Column( children: [ Padding( padding: const EdgeInsets.all(13.0), child: Text('Please enter your payment details'), ), Expanded( child: Container( child: HtmlElementView( viewType: viewID, ), ), ), ], ), ); } } ```

Anytime I move away from this page I get the following error:

Error: Looking up a deactivated widget's ancestor is unsafe.
At this point the state of the widget's element tree is no longer stable.
To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.

If I press back button on my appear I get the dependency error. Is this a problem with flutter? I have checked other examples online and they have done things in a similar way so I am not sure what the problem is here?

Flutter Doctor Output:

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel master, 1.25.0-5.0.pre.90, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-GB) [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) [✓] Xcode - develop for iOS and macOS (Xcode 12.2) [✓] Chrome - develop for the web [✓] Android Studio (version 4.1) [✓] Connected device (2 available)

• No issues found!

pedromassangocode commented 3 years ago

Hi @Damandroid Please provide a code that does not use any third-party plugin/package and the complete output of flutter doctor -v. Thank you

mjschaefer9395 commented 3 years ago

Here is an example to demonstrate the problem. The error occurs when you navigate to Tab2 the second time.

import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:universal_html/html.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          title: Text('HtmlElementView Test'),
          bottom: TabBar(
            tabs: [
              Tab(text: 'Tab1'),
              Tab(text: 'Tab2'),
            ],
          ),
        ),
        body: TabBarView(
          physics: NeverScrollableScrollPhysics(),
          children: [
            Tab1(),
            Tab2(),
          ],
        ),
      ),
    );
  }
}

class Tab1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text('Tab1'),
    );
  }
}

class Tab2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final String viewID = 'view1';

    // ignore: undefined_prefixed_name
    ui.platformViewRegistry.registerViewFactory(
      viewID,
      (int id) => IFrameElement()
        ..width = MediaQuery.of(context).size.width.toString()
        ..height = MediaQuery.of(context).size.height.toString()
        ..srcdoc = '<html><p>This is an HTML view</p></html>'
        ..style.border = 'none',
    );

    return HtmlElementView(
      viewType: viewID,
    );
  }
}

Flutter Doctor Output

[✓] Flutter (Channel beta, 1.25.0-8.1.pre, on Mac OS X 10.15.7 19H114 darwin-x64, locale en-US) • Flutter version 1.25.0-8.1.pre at /Users/martin/fvm/versions/beta • Framework revision 8f89f6505b (6 days ago), 2020-12-15 15:07:52 -0800 • Engine revision 92ae191c17 • Dart version 2.12.0 (build 2.12.0-133.2.beta)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) • Android SDK at /Users/martin/Library/Android/sdk • Platform android-30, build-tools 29.0.2 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.3, Build version 12C33 • CocoaPods version 1.9.3

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.0) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 45.1.1 • Dart plugin version 192.7761 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.52.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.14.0

[✓] Connected device (1 available) • Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.88

• No issues found!

mjschaefer9395 commented 3 years ago

The problem does not occur if you use a unique viewID on each call to platformViewRegistry.registerViewFactory.

pedromassangocode commented 3 years ago

Reproducible on latest master channel.

Logs ``` Downloading Web SDK... Launching lib/main.dart on Chrome in debug mode... Waiting for connection from debug service on Chrome... Debug service listening on ws://127.0.0.1:49813/ITqm_I_y9Vo=/ws Running with unsound null safety For more information see https://dart.dev/null-safety/unsound-null-safety Debug service listening on ws://127.0.0.1:49813/ITqm_I_y9Vo=/ws Error: Looking up a deactivated widget's ancestor is unsafe. At this point the state of the widget's element tree is no longer stable. To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method. at Object.throw_ [as throw] (http://localhost:49719/dart_sdk.js:5296:11) at http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25959:21 at framework.StatelessElement.new.[_debugCheckStateIsActiveForAncestorLookup] (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25962:26) at framework.StatelessElement.new.findAncestorWidgetOfExactType (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:26030:73) at http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:48846:65 at Object.debugCheckHasMediaQuery (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:48850:24) at Function.of (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:38411:30) at http://localhost:49719/packages/flutter_example/main.dart.lib.js:482:59 at http://localhost:49719/packages/flutter_example/main.dart.lib.js:487:11 at Object._createPlatformView (http://localhost:49719/dart_sdk.js:134025:19) at Object.handlePlatformViewCall (http://localhost:49719/dart_sdk.js:134002:12) at _engine.EnginePlatformDispatcher.__.[_sendPlatformMessage] (http://localhost:49719/dart_sdk.js:162853:16) at _engine.EnginePlatformDispatcher.__.sendPlatformMessage (http://localhost:49719/dart_sdk.js:162691:33) at _DefaultBinaryMessenger.[_sendPlatformMessage] (http://localhost:49719/packages/flutter/src/services/system_channels.dart.lib.js:2181:38) at _DefaultBinaryMessenger.send (http://localhost:49719/packages/flutter/src/services/system_channels.dart.lib.js:2225:40) at MethodChannel._invokeMethod (http://localhost:49719/packages/flutter/src/services/system_channels.dart.lib.js:943:50) at _invokeMethod.next () at runBody (http://localhost:49719/dart_sdk.js:38581:34) at Object._async [as async] (http://localhost:49719/dart_sdk.js:38612:7) at MethodChannel.[_invokeMethod] (http://localhost:49719/packages/flutter/src/services/system_channels.dart.lib.js:941:20) at MethodChannel.invokeMethod (http://localhost:49719/packages/flutter/src/services/system_channels.dart.lib.js:955:33) at platform_view$._HtmlElementViewController.new._initialize (http://localhost:49719/packages/flutter/src/widgets/platform_view.dart.lib.js:658:61) at _initialize.next () at runBody (http://localhost:49719/dart_sdk.js:38581:34) at Object._async [as async] (http://localhost:49719/dart_sdk.js:38612:7) at platform_view$._HtmlElementViewController.new.[_initialize] (http://localhost:49719/packages/flutter/src/widgets/platform_view.dart.lib.js:656:20) at platform_view$.HtmlElementView.new.[_createHtmlElementView] (http://localhost:49719/packages/flutter/src/widgets/platform_view.dart.lib.js:614:30) at platform_view$._PlatformViewLinkState.new.[_initialize] (http://localhost:49719/packages/flutter/src/widgets/platform_view.dart.lib.js:1251:318) at platform_view$._PlatformViewLinkState.new.initState (http://localhost:49719/packages/flutter/src/widgets/platform_view.dart.lib.js:1232:24) at framework.StatefulElement.new.[_firstBuild] (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:48431:54) at framework.StatefulElement.new.mount (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27068:28) at framework.StatelessElement.new.inflateWidget (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25825:16) at framework.StatelessElement.new.updateChild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25684:25) at framework.StatelessElement.new.performRebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27104:33) at framework.StatelessElement.new.rebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:26240:12) at framework.StatelessElement.new.[_firstBuild] (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27072:12) at framework.StatelessElement.new.mount (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27068:28) at framework.StatelessElement.new.inflateWidget (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25825:16) at framework.StatelessElement.new.updateChild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25684:25) at framework.StatelessElement.new.performRebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27104:33) at framework.StatelessElement.new.rebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:26240:12) at framework.StatelessElement.new.[_firstBuild] (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27072:12) at framework.StatelessElement.new.mount (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27068:28) at framework.StatelessElement.new.inflateWidget (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25825:16) at framework.StatelessElement.new.updateChild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25684:25) at framework.StatelessElement.new.performRebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27104:33) at framework.StatelessElement.new.rebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:26240:12) at framework.StatelessElement.new.[_firstBuild] (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27072:12) at framework.StatelessElement.new.mount (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27068:28) at framework.SingleChildRenderObjectElement.new.inflateWidget (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25825:16) at framework.SingleChildRenderObjectElement.new.updateChild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25684:25) at framework.SingleChildRenderObjectElement.new.mount (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:41123:31) at framework.SingleChildRenderObjectElement.new.inflateWidget (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25825:16) at framework.SingleChildRenderObjectElement.new.updateChild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25684:25) at framework.SingleChildRenderObjectElement.new.mount (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:41123:31) at framework.StatelessElement.new.inflateWidget (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25825:16) at framework.StatelessElement.new.updateChild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25684:25) at framework.StatelessElement.new.performRebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27104:33) at framework.StatelessElement.new.rebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:26240:12) at framework.StatelessElement.new.[_firstBuild] (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27072:12) at framework.StatelessElement.new.mount (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27068:28) at ParentDataElement.new.inflateWidget (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25825:16) at ParentDataElement.new.updateChild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25684:25) at ParentDataElement.new.performRebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27104:33) at ParentDataElement.new.rebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:26240:12) at ParentDataElement.new.[_firstBuild] (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27072:12) at ParentDataElement.new.mount (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27068:28) at framework.StatefulElement.new.inflateWidget (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25825:16) at framework.StatefulElement.new.updateChild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25684:25) at framework.StatefulElement.new.performRebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27104:33) at framework.StatefulElement.new.performRebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:48457:13) at framework.StatefulElement.new.rebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:26240:12) at framework.StatefulElement.new.[_firstBuild] (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27072:12) at framework.StatefulElement.new.[_firstBuild] (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:48450:29) at framework.StatefulElement.new.mount (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27068:28) at framework.StatelessElement.new.inflateWidget (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25825:16) at framework.StatelessElement.new.updateChild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25684:25) at framework.StatelessElement.new.performRebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27104:33) at framework.StatelessElement.new.rebuild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:26240:12) at framework.StatelessElement.new.[_firstBuild] (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27072:12) at framework.StatelessElement.new.mount (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:27068:28) at sliver$.SliverMultiBoxAdaptorElement.new.inflateWidget (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25825:16) at sliver$.SliverMultiBoxAdaptorElement.new.updateChild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:25684:25) at sliver$.SliverMultiBoxAdaptorElement.new.updateChild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:40716:28) at http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:40702:27 at framework.BuildOwner.new.buildScope (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:48024:13) at sliver$.SliverMultiBoxAdaptorElement.new.createChild (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:40695:34) at http://localhost:49719/packages/flutter/src/rendering/sliver_multi_box_adaptor.dart.lib.js:383:31 at http://localhost:49719/packages/flutter/src/rendering/layer.dart.lib.js:3427:11 at object$.PipelineOwner.new.[_enableMutationsToDirtySubtrees] (http://localhost:49719/packages/flutter/src/rendering/layer.dart.lib.js:6845:9) at sliver_fill.RenderSliverFillViewport.new.invokeLayoutCallback (http://localhost:49719/packages/flutter/src/rendering/layer.dart.lib.js:3426:68) at sliver_fill.RenderSliverFillViewport.new.[_createOrObtainChild] (http://localhost:49719/packages/flutter/src/rendering/sliver_multi_box_adaptor.dart.lib.js:371:12) at sliver_fill.RenderSliverFillViewport.new.insertAndLayoutChild (http://localhost:49719/packages/flutter/src/rendering/sliver_multi_box_adaptor.dart.lib.js:468:33) at sliver_fill.RenderSliverFillViewport.new.performLayout (http://localhost:49719/packages/flutter/src/rendering/sliver_fixed_extent_list.dart.lib.js:152:24) at sliver_fill.RenderSliverFillViewport.new.layout (http://localhost:49719/packages/flutter/src/rendering/layer.dart.lib.js:3390:14) at sliver_fill$._RenderSliverFractionalPadding.new.performLayout (http://localhost:49719/packages/flutter/src/rendering/sliver_padding.dart.lib.js:187:34) at sliver_fill$._RenderSliverFractionalPadding.new.performLayout (http://localhost:49719/packages/flutter/src/widgets/sliver_fill.dart.lib.js:389:13) at sliver_fill$._RenderSliverFractionalPadding.new.layout (http://localhost:49719/packages/flutter/src/rendering/layer.dart.lib.js:3390:14) at viewport.RenderViewport.new.layoutChildSequence (http://localhost:49719/packages/flutter/src/rendering/sliver.dart.lib.js:1924:17) at viewport.RenderViewport.new.[_attemptLayout] (http://localhost:49719/packages/flutter/src/rendering/sliver.dart.lib.js:2692:19) at viewport.RenderViewport.new.performLayout (http://localhost:49719/packages/flutter/src/rendering/sliver.dart.lib.js:2636:42) at viewport.RenderViewport.new.[_layoutWithoutResize] (http://localhost:49719/packages/flutter/src/rendering/layer.dart.lib.js:3277:14) at object$.PipelineOwner.new.flushLayout (http://localhost:49719/packages/flutter/src/rendering/layer.dart.lib.js:6822:107) at binding$5.WidgetsFlutterBinding.new.drawFrame (http://localhost:49719/packages/flutter/src/rendering/layer.dart.lib.js:6108:26) at binding$5.WidgetsFlutterBinding.new.drawFrame (http://localhost:49719/packages/flutter/src/widgets/widget_span.dart.lib.js:50625:15) at binding$5.WidgetsFlutterBinding.new.[_handlePersistentFrameCallback] (http://localhost:49719/packages/flutter/src/rendering/layer.dart.lib.js:6072:12) at binding$5.WidgetsFlutterBinding.new.[_invokeFrameCallback] (http://localhost:49719/packages/flutter/src/scheduler/binding.dart.lib.js:770:9) at binding$5.WidgetsFlutterBinding.new.handleDrawFrame (http://localhost:49719/packages/flutter/src/scheduler/binding.dart.lib.js:738:37) at binding$5.WidgetsFlutterBinding.new.[_handleDrawFrame] (http://localhost:49719/packages/flutter/src/scheduler/binding.dart.lib.js:693:12) at Object.invoke (http://localhost:49719/dart_sdk.js:181524:7) at _engine.EnginePlatformDispatcher.__.invokeOnDrawFrame (http://localhost:49719/dart_sdk.js:162665:15) at http://localhost:49719/dart_sdk.js:179051:55 ```
doctor -v ``` /Users/pedromassango/dev/SDKs/flutter_master/bin/flutter doctor --verbose [✓] Flutter (Channel master, 1.26.0-2.0.pre.103, on Mac OS X 10.15.7 19H2 darwin-x64, locale en) • Flutter version 1.26.0-2.0.pre.103 at /Users/pedromassango/dev/SDKs/flutter_master • Framework revision 32741c0ec8 (10 hours ago), 2020-12-21 18:34:02 -0600 • Engine revision af6889a600 • Dart version 2.12.0 (build 2.12.0-169.0.dev) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/pedromassango/Library/Android/sdk • Platform android-30, build-tools 30.0.2 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) • All Android licenses accepted. [!] Xcode - develop for iOS and macOS (Xcode 12.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.1, Build version 12A7403 ! CocoaPods 1.9.3 out of date (1.10.0 is recommended). CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see https://flutter.dev/platform-plugins To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions. [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) [✓] IntelliJ IDEA Community Edition (version 2020.3) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 52.1.5 • Dart plugin version 203.5981.152 [✓] VS Code (version 1.51.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.16.0 [✓] Connected device (3 available) • Redmi 5 Plus (mobile) • 0258ff700005 • android-arm64 • Android 8.1.0 (API 27) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.7 19H2 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.88 ! Doctor found issues in 1 category. Process finished with exit code 0 ```
MarcBritton commented 2 years ago

I am still experiencing this issue with Flutter 3.3.4. Basic usage of HtmlElementView results in a crash, is this really only a P4?

darshankawar commented 1 year ago

Verified this issue using latest versions and observed that the originally reported behavior doesn't occur anymore, but now it throws:

Error: Unexpected null value. upon navigating from tab1 to tab2 the second time. I also used dart:html import instead of the third party universal_html package that was originally used, but it gives same error.

runnable code sample ``` import 'dart:html'; import 'dart:ui' as ui; import 'package:flutter/material.dart'; //import 'package:universal_html/html.dart'; //import 'package:dart_html/html.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: HomePage(), ); } } class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { @override Widget build(BuildContext context) { return DefaultTabController( length: 2, child: Scaffold( appBar: AppBar( title: Text('HtmlElementView Test'), bottom: TabBar( tabs: [ Tab(text: 'Tab1'), Tab(text: 'Tab2'), ], ), ), body: TabBarView( physics: NeverScrollableScrollPhysics(), children: [ Tab1(), Tab2(), ], ), ), ); } } class Tab1 extends StatelessWidget { @override Widget build(BuildContext context) { return Center( child: Text('Tab1'), ); } } class Tab2 extends StatelessWidget { @override Widget build(BuildContext context) { final String viewID = 'view1'; // ignore: undefined_prefixed_name ui.platformViewRegistry.registerViewFactory( viewID, (int id) => IFrameElement() ..width = MediaQuery.of(context).size.width.toString() ..height = MediaQuery.of(context).size.height.toString() ..srcdoc = '

This is an HTML view

' ..style.border = 'none', ); return HtmlElementView( viewType: viewID, ); } } ```
console error log ``` An Observatory debugger and profiler on Chrome is available at: http://127.0.0.1:63881/3VAx5KJgGpA= The Flutter DevTools debugger and profiler on Chrome is available at: http://127.0.0.1:9101?uri=http://127.0.0.1:63881/3VAx5KJgGpA= Height of Platform View type: [view1] may not be set. Defaulting to `height: 100%`. Set `style.height` to any appropriate value to stop this message. Width of Platform View type: [view1] may not be set. Defaulting to `width: 100%`. Set `style.width` to any appropriate value to stop this message. Error: Unexpected null value. dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49 throw_ dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 561:63 nullCheck packages/flutter/src/widgets/framework.dart 3335:31 get widget packages/flutter/src/widgets/debug.dart 296:16 packages/flutter/src/widgets/debug.dart 311:12 debugCheckHasMediaQuery packages/flutter/src/widgets/media_query.dart 892:12 of packages/test_app/main.dart 71:53 packages/test_app/main.dart 74:26 lib/_engine/engine/platform_views/content_manager.dart 123:35 dart-sdk/lib/_internal/js_dev_runtime/private/identity_hash_map.dart 75:23 putIfAbsent lib/_engine/engine/platform_views/content_manager.dart 112:22 renderContent lib/_engine/engine/platform_views/message_handler.dart 89:48 [_createPlatformView] lib/_engine/engine/platform_views/message_handler.dart 138:9 handlePlatformViewCall lib/_engine/engine/platform_dispatcher.dart 540:9 [_sendPlatformMessage] lib/_engine/engine/platform_dispatcher.dart 324:5 sendPlatformMessage packages/flutter/src/services/binding.dart 370:36 send packages/flutter/src/services/platform_channel.dart 308:31 _invokeMethod dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async packages/flutter/src/services/platform_channel.dart 302:30 [_invokeMethod] packages/flutter/src/services/platform_channel.dart 491:12 invokeMethod packages/flutter/src/widgets/platform_view.dart 414:41 _initialize dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async packages/flutter/src/widgets/platform_view.dart 409:27 [_initialize] packages/flutter/src/widgets/platform_view.dart 385:15 [_createHtmlElementView] packages/flutter/src/widgets/platform_view.dart 919:47 [_initialize] packages/flutter/src/widgets/platform_view.dart 900:5 initState packages/flutter/src/widgets/framework.dart 5101:55 [_firstBuild] packages/flutter/src/widgets/framework.dart 4944:5 mount packages/flutter/src/widgets/framework.dart 3953:15 inflateWidget packages/flutter/src/widgets/framework.dart 3682:18 updateChild packages/flutter/src/widgets/framework.dart 4993:16 performRebuild packages/flutter/src/widgets/framework.dart 4690:5 rebuild packages/flutter/src/widgets/framework.dart 4950:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 4944:5 mount packages/flutter/src/widgets/framework.dart 3953:15 inflateWidget packages/flutter/src/widgets/framework.dart 3682:18 updateChild packages/flutter/src/widgets/framework.dart 4993:16 performRebuild packages/flutter/src/widgets/framework.dart 4690:5 rebuild packages/flutter/src/widgets/framework.dart 4950:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 4944:5 mount packages/flutter/src/widgets/framework.dart 3953:15 inflateWidget packages/flutter/src/widgets/framework.dart 3682:18 updateChild packages/flutter/src/widgets/framework.dart 4993:16 performRebuild packages/flutter/src/widgets/framework.dart 4690:5 rebuild packages/flutter/src/widgets/framework.dart 4950:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 4944:5 mount packages/flutter/src/widgets/framework.dart 3953:15 inflateWidget packages/flutter/src/widgets/framework.dart 3682:18 updateChild packages/flutter/src/widgets/framework.dart 6377:14 mount packages/flutter/src/widgets/framework.dart 3953:15 inflateWidget packages/flutter/src/widgets/framework.dart 3682:18 updateChild packages/flutter/src/widgets/framework.dart 6377:14 mount packages/flutter/src/widgets/framework.dart 3953:15 inflateWidget packages/flutter/src/widgets/framework.dart 3682:18 updateChild packages/flutter/src/widgets/framework.dart 4993:16 performRebuild packages/flutter/src/widgets/framework.dart 5133:11 performRebuild packages/flutter/src/widgets/framework.dart 4690:5 rebuild packages/flutter/src/widgets/framework.dart 4950:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 5124:11 [_firstBuild] packages/flutter/src/widgets/framework.dart 4944:5 mount packages/flutter/src/widgets/framework.dart 3953:15 inflateWidget packages/flutter/src/widgets/framework.dart 3682:18 updateChild packages/flutter/src/widgets/framework.dart 4993:16 performRebuild packages/flutter/src/widgets/framework.dart 4690:5 rebuild packages/flutter/src/widgets/framework.dart 4950:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 4944:5 mount packages/flutter/src/widgets/framework.dart 3953:15 inflateWidget packages/flutter/src/widgets/framework.dart 3682:18 updateChild packages/flutter/src/widgets/framework.dart 4993:16 performRebuild packages/flutter/src/widgets/framework.dart 4690:5 rebuild packages/flutter/src/widgets/framework.dart 4950:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 4944:5 mount packages/flutter/src/widgets/framework.dart 3953:15 inflateWidget packages/flutter/src/widgets/framework.dart 3682:18 updateChild packages/flutter/src/widgets/framework.dart 4993:16 performRebuild packages/flutter/src/widgets/framework.dart 5133:11 performRebuild packages/flutter/src/widgets/framework.dart 4690:5 rebuild packages/flutter/src/widgets/framework.dart 4950:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 5124:11 [_firstBuild] packages/flutter/src/widgets/framework.dart 4944:5 mount packages/flutter/src/widgets/framework.dart 3953:15 inflateWidget packages/flutter/src/widgets/framework.dart 3682:18 updateChild packages/flutter/src/widgets/framework.dart 4993:16 performRebuild packages/flutter/src/widgets/framework.dart 4690:5 rebuild packages/flutter/src/widgets/framework.dart 4950:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 4944:5 mount packages/flutter/src/widgets/framework.dart 3953:15 inflateWidget packages/flutter/src/widgets/framework.dart 3682:18 updateChild packages/flutter/src/widgets/sliver.dart 1451:37 updateChild packages/flutter/src/widgets/sliver.dart 1436:20 packages/flutter/src/widgets/framework.dart 2682:19 buildScope packages/flutter/src/widgets/sliver.dart 1428:5 createChild packages/flutter/src/rendering/sliver_multi_box_adaptor.dart 353:23 packages/flutter/src/rendering/object.dart 2300:59 packages/flutter/src/rendering/object.dart 1056:15 [_enableMutationsToDirtySubtrees] packages/flutter/src/rendering/object.dart 2300:7 invokeLayoutCallback packages/flutter/src/rendering/sliver_multi_box_adaptor.dart 342:5 [_createOrObtainChild] packages/flutter/src/rendering/sliver_multi_box_adaptor.dart 490:5 insertAndLayoutChild packages/flutter/src/rendering/sliver_fixed_extent_list.dart 250:17 performLayout packages/flutter/src/rendering/object.dart 2189:7 layout packages/flutter/src/rendering/sliver_padding.dart 149:5 performLayout packages/flutter/src/widgets/sliver_fill.dart 166:11 performLayout packages/flutter/src/rendering/object.dart 2189:7 layout packages/flutter/src/rendering/viewport.dart 550:12 layoutChildSequence packages/flutter/src/rendering/viewport.dart 1634:12 [_attemptLayout] packages/flutter/src/rendering/viewport.dart 1541:20 performLayout packages/flutter/src/rendering/object.dart 2027:7 [_layoutWithoutResize] packages/flutter/src/rendering/object.dart 1020:17 flushLayout packages/flutter/src/rendering/binding.dart 516:19 drawFrame packages/flutter/src/widgets/binding.dart 865:13 drawFrame packages/flutter/src/rendering/binding.dart 381:5 [_handlePersistentFrameCallback] packages/flutter/src/scheduler/binding.dart 1289:15 [_invokeFrameCallback] packages/flutter/src/scheduler/binding.dart 1218:9 handleDrawFrame packages/flutter/src/scheduler/binding.dart 1076:5 [_handleDrawFrame] lib/_engine/engine/platform_dispatcher.dart 1168:13 invoke lib/_engine/engine/platform_dispatcher.dart 218:5 invokeOnDrawFrame lib/_engine/engine/initialization.dart 190:45 dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 367:37 _checkAndCall dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 372:39 dcall ```
stable, master flutter doctor -v ``` [!] Flutter (Channel stable, 3.7.5, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.7.5 on channel stable at /Users/dhs/documents/fluttersdk/flutter ! Warning: `flutter` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision c07f788888 (7 days ago), 2023-02-22 17:52:33 -0600 • Engine revision 0f359063c4 • Dart version 2.19.2 • DevTools version 2.20.1 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. [!] Flutter (Channel master, 3.9.0-1.0.pre.72, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.9.0-1.0.pre.72 on channel master at /Users/dhs/documents/fluttersdk/flutter ! Warning: `flutter` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision 8557ffa024 (84 minutes ago), 2023-03-06 22:38:59 -0500 • Engine revision e2bd89f97e • Dart version 3.0.0 (build 3.0.0-290.0.dev) • DevTools version 2.22.2 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/dhs/Library/Android/sdk ✗ cmdline-tools component is missing Run `path/to/sdkmanager --install "cmdline-tools;latest"` See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details. [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 13C100 • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2) • IntelliJ at /Applications/IntelliJ IDEA.app • Flutter plugin version 65.1.4 • Dart plugin version 213.7228 [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.29.0 [✓] Connected device (3 available) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 15.3.1 19D52 • macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.119 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. ```

Updating the issue title to reflect latest behavior.

/cc @yjbanov for thoughts.