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

[url_launcher]Error: setState() called after dispose(): _PlatformViewLinkState#946fb(lifecycle state: defunct, not mounted) #102741

Closed
kristoffer-zliide opened this issue Apr 28, 2022 · 15 comments · Fixed by flutter/plugins#5963
Labels
a: error message Error messages from the Flutter framework found in release: 2.10 Found to occur in 2.10 found in release: 2.13 Found to occur in 2.13 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: url_launcher Plugin to launch external applications P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. r: fixed Issue is closed as already fixed in a newer version

Comments

@kristoffer-zliide
Copy link

kristoffer-zliide commented Apr 28, 2022

onPlatformViewCreated calls setState(), so it probably shouldn't be called indiscriminately after an async operation. Or, maybe onPlatformViewCreated shouldn't call setState without checking mounted state.

Easily reproducible by making a large list of widgets with Links and scroll through it.

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.5, on Microsoft Windows [Version 10.0.22000.613], locale en-DK)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc2)
    ✗ 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/windows#android-setup for more details.
[✓] Chrome - develop for the web
[✓] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.9.4)
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.66.2)
[✓] VS Code, 64-bit edition
[✓] Connected device (4 available)
[✓] HTTP Host Availability

! Doctor found issues in 1 category.
@maheshj01 maheshj01 added the in triage Presently being triaged by the triage team label Apr 28, 2022
@maheshj01
Copy link
Member

Hi @kristoffer-zliide, Thanks for filing the issue. Please share a minimal and complete reproducible code to better address the issue

@maheshj01 maheshj01 added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 28, 2022
@kristoffer-zliide
Copy link
Author

@maheshmnj: I updated the example in a pull request that may fix it. You need to scroll quite aggressively in that simple example to reproduce it 😄

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 28, 2022
@kristoffer-zliide
Copy link
Author

The error I get when I scroll in that list:

This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
    at Object.throw_ [as throw] (http://localhost:55799/dart_sdk.js:5067:11)
at http://localhost:55799/packages/flutter/src/widgets/widget_inspector.dart.lib.js:12948:23
at platform_view$._PlatformViewLinkState.new.setState (http://localhost:55799/packages/flutter/src/widgets/widget_inspector.dart.lib.js:12954:28)
at platform_view$._PlatformViewLinkState.new.[_onPlatformViewCreated] (http://localhost:55799/packages/flutter/src/widgets/platform_view.dart.lib.js:1134:12)
at http://localhost:55799/packages/url_launcher_web/src/link.dart.lib.js:277:12
    at _RootZone.runUnary (http://localhost:55799/dart_sdk.js:40441:59)
    at _FutureListener.then.handleValue (http://localhost:55799/dart_sdk.js:35363:29)
    at handleValueCallback (http://localhost:55799/dart_sdk.js:35931:49)
    at Function._propagateToListeners (http://localhost:55799/dart_sdk.js:35969:17)
    at _Future.new.[_completeWithValue] (http://localhost:55799/dart_sdk.js:35817:23)
    at async._AsyncCallbackEntry.new.callback (http://localhost:55799/dart_sdk.js:35838:35)
    at Object._microtaskLoop (http://localhost:55799/dart_sdk.js:40708:13)
    at _startMicrotaskLoop (http://localhost:55799/dart_sdk.js:40714:13)
    at http://localhost:55799/dart_sdk.js:36191:9```

@maheshj01
Copy link
Member

Thanks for the code sample @kristoffer-zliide, Can you please clarify on which platform is this issue on ?

Screen.Recording.2022-04-29.at.12.27.02.PM.mov

You need to scroll quite aggressively in that simple example to reproduce it 😄

I tried to reproduce the issue on Android, either I was not aggressive enough xD or the bug does not exist on Android

code sample
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/link.dart';

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

class _HorizontalScrollBehavior extends MaterialScrollBehavior {
  @override
  Set<PointerDeviceKind> get dragDevices => <PointerDeviceKind>{
        PointerDeviceKind.touch,
        PointerDeviceKind.stylus,
        PointerDeviceKind.invertedStylus,
        PointerDeviceKind.mouse,
      };
}

/// App for testing
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) => MaterialApp(
        home: Scaffold(
          body: ConstrainedBox(
            constraints: const BoxConstraints(maxHeight: 300),
            child: const _List(),
          ),
        ),
      );
}

class _List extends StatelessWidget {
  const _List({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) => ScrollConfiguration(
        behavior: _HorizontalScrollBehavior(),
        child: ListView.separated(
          scrollDirection: Axis.horizontal,
          itemCount: 500,
          separatorBuilder: (_, __) => const SizedBox(height: 24, width: 24),
          itemBuilder: (_, int index) => Link(
            uri: Uri.parse('https://example.com/$index'),
            builder: (_, __) => GestureDetector(
              onTap: () {
                ScaffoldMessenger.of(context).showSnackBar(
                    SnackBar(content: Text('https://example.com/$index')));
              },
              child: Card(
                  child: Padding(
                padding: const EdgeInsets.all(64),
                child: Text('#$index', textAlign: TextAlign.center),
              )),
            ),
          ),
        ),
      );
}
flutter doctor -v (mac)
[✓] Flutter (Channel stable, 2.10.5, on macOS 12.3 21E230 darwin-arm, locale en-IN)
    • Flutter version 2.10.5 at /Users/mahesh/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5464c5bac7 (12 hours ago), 2022-04-18 09:55:37 -0700
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/mahesh/Library/Android/sdk
    • Platform android-32, build-tools 31.0.0
    • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.10.2

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

[✓] Android Studio (version 2021.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 11.0.11+0-b60-7772763)

[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

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

[✓] Connected device (4 available)
    • Redmi K20 Pro (mobile) • 192.168.1.2:55555                    • android-arm64  • Android 11 (API 30)
    • iPhone 12 Pro (mobile) • 535317A4-921C-488F-B234-C2CC6D4AE5A1 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 12.3 21E230 darwin-arm
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 100.0.4896.88

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

@maheshj01 maheshj01 added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 29, 2022
@kristoffer-zliide
Copy link
Author

@maheshmnj: Try a desktop browser and scrolling with the mouse.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 29, 2022
@maheshj01
Copy link
Member

@kristoffer-zliide Unfortunately that doesn't seem to make any difference , I am unable to reproduce the error on Windows Web / Desktop app

2022-04-29.20-01-53_Trim.mp4
2022-04-29.19-44-26_Trim.mp4
flutter doctor -v (windows)
[√] Flutter (Channel stable, 2.10.5, on Microsoft Windows [Version 10.0.19044.1645], locale en-US)
    • Flutter version 2.10.5 at C:\flutter_sdk\stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5464c5bac7 (2 days ago), 2022-04-18 09:55:37 -0700
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\mahesh\AppData\Local\Android\sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java      
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)    
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.4)      
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.31727.386
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 11.0.10+0-b96-7249189)        

[√] VS Code (version 1.64.2)
    • VS Code at C:\Users\mahesh\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.38.1

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19044.1645]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 100.0.4896.127
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 100.0.1185.44

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

details>

@maheshj01 maheshj01 added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 29, 2022
@kristoffer-zliide
Copy link
Author

@maheshmnj: maybe a little more aggressive: 😃

Screen.Recording.mp4

Or, are you running directly from the PR, because there the issue is fixed?

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 2, 2022
@maheshj01
Copy link
Member

maheshj01 commented May 2, 2022

I still can't reproduce @kristoffer-zliide..

Or, are you running directly from the PR, because there the issue is fixed?

I am running on stable 2.10.5 Can you please share which PR you are referring too? Also if it is fixed then the fix must be on the master channel. Can you please check if switching to master fixes the issue for you?

you can switch to master channel by running

flutter channel master
flutter upgrade
flutter doctor -v (windows)
[√] Flutter (Channel stable, 2.10.5, on Microsoft Windows [Version 10.0.19044.1645], locale en-US)
    • Flutter version 2.10.5 at C:\flutter_sdk\stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5464c5bac7 (2 days ago), 2022-04-18 09:55:37 -0700
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\mahesh\AppData\Local\Android\sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java      
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)    
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.4)      
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.31727.386
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 11.0.10+0-b96-7249189)        

[√] VS Code (version 1.64.2)
    • VS Code at C:\Users\mahesh\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.38.1

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19044.1645]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 100.0.4896.127
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 100.0.1185.44

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

@maheshj01 maheshj01 added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 2, 2022
@kristoffer-zliide
Copy link
Author

The PR I believe fixes it, the one I linked to with the example. It's a fix to the plugin, so it's not from flutter master, and I'm also running stable 2.10.5. But if you're running on just the example Flutter code, I think you should be able to repro it.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 2, 2022
@maheshj01
Copy link
Member

@kristoffer-zliide I am trying this code sample , Can you please confirm if the issue reproduces with that sample?

Also looking at your logs the error doesn't seem related to URL launcher But looks similar to #91814

@maheshj01 maheshj01 added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 3, 2022
@kristoffer-zliide
Copy link
Author

kristoffer-zliide commented May 3, 2022

@maheshmnj: really sorry, I didn't see the code in your reply because it was collapsed! That code should repro it with url_launcher 6.1.0.

Both in the error I posted and in the repro video, you can see platform_view$._PlatformViewLinkState.new.setState and http://localhost:55799/packages/url_launcher_web/src/link.dart.lib.js, so the url_launcher is involved, and no streams that I'm aware of. Please feel free to take a look at the PR, since it's pretty obvious that what it's doing is fishy.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 3, 2022
@kristoffer-zliide
Copy link
Author

kristoffer-zliide commented May 3, 2022

@maheshmnj : maybe try this and scroll fast downward with the mouse wheel:

import 'package:url_launcher/link.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => const MaterialApp(
        home: Scaffold(
          body: _List(),
        ),
      );
}

class _List extends StatelessWidget {
  const _List({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => ListView.builder(
        itemCount: 5000,
        itemBuilder: (_, int index) => Link(
          uri: Uri.parse('https://example.com/$index'),
          builder: (_, __) => Text('#$index', textAlign: TextAlign.center),
        ),
      );
}

@maheshj01
Copy link
Member

Thanks for the code sample @kristoffer-zliide, I was able to reproduce the issue on stable and the master channel. On Scrolling a bit faster the exception is thrown.

A reproducible code sample can be found here #102741 (comment)

2022-05-04.12-03-06_Trim.mp4

The logs don't seem to point at the issue in the URL launcher plugin, so labeling it as a framework issue.

logs
PS C:\Users\mahesh\Desktop\keyboardissue> flutterm run -d chrome
Launching lib\main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...             51.0s
This app is linked to the debug service: ws://127.0.0.1:53054/ywI-oBGhrfM=/ws        
Debug service listening on ws://127.0.0.1:53054/ywI-oBGhrfM=/ws

 Running with sound null safety

  To hot restart changes while running, press "r" or "R".
For a more detailed help message, press "h". To quit, press "q".

An Observatory debugger and profiler on Chrome is available at:
http://127.0.0.1:53054/ywI-oBGhrfM=
Flutter Web Bootstrap: Auto
The Flutter DevTools debugger and profiler on Chrome is available at:
http://127.0.0.1:9101?uri=http://127.0.0.1:53054/ywI-oBGhrfM=
Error: setState() called after dispose(): _PlatformViewLinkState#946fb(lifecycle     
state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no     
longer appears in the widget tree (e.g., whose parent widget no longer includes the  
widget in its build). This error can occur when code calls setState() from a timer oran animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in  
the dispose() callback. Another solution is to check the "mounted" property of this  
object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because anotherobject is retaining a reference to this State object after it has been removed from  
the tree. To avoid memory leaks, consider breaking the reference to this object      
during dispose().
    at Object.throw_ [as throw] (http://localhost:54116/dart_sdk.js:5145:11)
    at http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11670:23    at platform_view$._PlatformViewLinkState.new.setState
    (http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11676:28) 
    at platform_view$._PlatformViewLinkState.new.[_onPlatformViewCreated]
    (http://localhost:54116/packages/flutter/src/widgets/platform_view.dart.lib.js:11    62:12)
    at http://localhost:54116/packages/url_launcher_web/src/link.dart.lib.js:277:12  
    at _RootZone.runUnary (http://localhost:54116/dart_sdk.js:40589:59)
    at _FutureListener.then.handleValue (http://localhost:54116/dart_sdk.js:35516:29)    at handleValueCallback (http://localhost:54116/dart_sdk.js:36077:49)
    at Function._propagateToListeners (http://localhost:54116/dart_sdk.js:36115:17)  
    at _Future.new.[_completeWithValue] (http://localhost:54116/dart_sdk.js:35950:23)    at async._AsyncCallbackEntry.new.callback
    (http://localhost:54116/dart_sdk.js:35984:35)
    at Object._microtaskLoop (http://localhost:54116/dart_sdk.js:40856:13)
    at _startMicrotaskLoop (http://localhost:54116/dart_sdk.js:40862:13)
    at http://localhost:54116/dart_sdk.js:36339:9
Error: setState() called after dispose(): _PlatformViewLinkState#fe2c2(lifecycle
state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no     
longer appears in the widget tree (e.g., whose parent widget no longer includes the  
widget in its build). This error can occur when code calls setState() from a timer oran animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in  
the dispose() callback. Another solution is to check the "mounted" property of this  
object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because anotherobject is retaining a reference to this State object after it has been removed from  
the tree. To avoid memory leaks, consider breaking the reference to this object      
during dispose().
    at Object.throw_ [as throw] (http://localhost:54116/dart_sdk.js:5145:11)
    at http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11670:23    at platform_view$._PlatformViewLinkState.new.setState
    (http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11676:28) 
    at platform_view$._PlatformViewLinkState.new.[_onPlatformViewCreated]
    (http://localhost:54116/packages/flutter/src/widgets/platform_view.dart.lib.js:11    62:12)
    at http://localhost:54116/packages/url_launcher_web/src/link.dart.lib.js:277:12  
    at _RootZone.runUnary (http://localhost:54116/dart_sdk.js:40589:59)
    at _FutureListener.then.handleValue (http://localhost:54116/dart_sdk.js:35516:29)    at handleValueCallback (http://localhost:54116/dart_sdk.js:36077:49)
    at Function._propagateToListeners (http://localhost:54116/dart_sdk.js:36115:17)  
    at _Future.new.[_completeWithValue] (http://localhost:54116/dart_sdk.js:35950:23)    at async._AsyncCallbackEntry.new.callback
    (http://localhost:54116/dart_sdk.js:35984:35)
    at Object._microtaskLoop (http://localhost:54116/dart_sdk.js:40856:13)
    at _startMicrotaskLoop (http://localhost:54116/dart_sdk.js:40862:13)
    at http://localhost:54116/dart_sdk.js:36339:9
Error: setState() called after dispose(): _PlatformViewLinkState#6c2d7(lifecycle     
state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no     
longer appears in the widget tree (e.g., whose parent widget no longer includes the  
widget in its build). This error can occur when code calls setState() from a timer oran animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in  
the dispose() callback. Another solution is to check the "mounted" property of this  
object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because anotherobject is retaining a reference to this State object after it has been removed from  
the tree. To avoid memory leaks, consider breaking the reference to this object      
during dispose().
    at Object.throw_ [as throw] (http://localhost:54116/dart_sdk.js:5145:11)
    at http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11670:23    at platform_view$._PlatformViewLinkState.new.setState
    (http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11676:28) 
    at platform_view$._PlatformViewLinkState.new.[_onPlatformViewCreated]
    (http://localhost:54116/packages/flutter/src/widgets/platform_view.dart.lib.js:11    62:12)
    at http://localhost:54116/packages/url_launcher_web/src/link.dart.lib.js:277:12  
    at _RootZone.runUnary (http://localhost:54116/dart_sdk.js:40589:59)
    at _FutureListener.then.handleValue (http://localhost:54116/dart_sdk.js:35516:29)    at handleValueCallback (http://localhost:54116/dart_sdk.js:36077:49)
    at Function._propagateToListeners (http://localhost:54116/dart_sdk.js:36115:17)  
    at _Future.new.[_completeWithValue] (http://localhost:54116/dart_sdk.js:35950:23)    at async._AsyncCallbackEntry.new.callback
    (http://localhost:54116/dart_sdk.js:35984:35)
    at Object._microtaskLoop (http://localhost:54116/dart_sdk.js:40856:13)
    at _startMicrotaskLoop (http://localhost:54116/dart_sdk.js:40862:13)
    at http://localhost:54116/dart_sdk.js:36339:9
Error: setState() called after dispose(): _PlatformViewLinkState#d591c(lifecycle
state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no     
longer appears in the widget tree (e.g., whose parent widget no longer includes the  
widget in its build). This error can occur when code calls setState() from a timer oran animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in  
the dispose() callback. Another solution is to check the "mounted" property of this  
object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because anotherobject is retaining a reference to this State object after it has been removed from  
the tree. To avoid memory leaks, consider breaking the reference to this object      
during dispose().
    at Object.throw_ [as throw] (http://localhost:54116/dart_sdk.js:5145:11)
    at http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11670:23    at platform_view$._PlatformViewLinkState.new.setState
    (http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11676:28) 
    at platform_view$._PlatformViewLinkState.new.[_onPlatformViewCreated]
    (http://localhost:54116/packages/flutter/src/widgets/platform_view.dart.lib.js:11    62:12)
    at http://localhost:54116/packages/url_launcher_web/src/link.dart.lib.js:277:12  
    at _RootZone.runUnary (http://localhost:54116/dart_sdk.js:40589:59)
    at _FutureListener.then.handleValue (http://localhost:54116/dart_sdk.js:35516:29)    at handleValueCallback (http://localhost:54116/dart_sdk.js:36077:49)
    at Function._propagateToListeners (http://localhost:54116/dart_sdk.js:36115:17)  
    at _Future.new.[_completeWithValue] (http://localhost:54116/dart_sdk.js:35950:23)    at async._AsyncCallbackEntry.new.callback
    (http://localhost:54116/dart_sdk.js:35984:35)
    at Object._microtaskLoop (http://localhost:54116/dart_sdk.js:40856:13)
    at _startMicrotaskLoop (http://localhost:54116/dart_sdk.js:40862:13)
    at http://localhost:54116/dart_sdk.js:36339:9
Error: setState() called after dispose(): _PlatformViewLinkState#705ae(lifecycle
state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no     
longer appears in the widget tree (e.g., whose parent widget no longer includes the  
widget in its build). This error can occur when code calls setState() from a timer oran animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in  
the dispose() callback. Another solution is to check the "mounted" property of this  
object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because anotherobject is retaining a reference to this State object after it has been removed from  
the tree. To avoid memory leaks, consider breaking the reference to this object      
during dispose().
    at Object.throw_ [as throw] (http://localhost:54116/dart_sdk.js:5145:11)
    at http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11670:23    at platform_view$._PlatformViewLinkState.new.setState
    (http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11676:28) 
    at platform_view$._PlatformViewLinkState.new.[_onPlatformViewCreated]
    (http://localhost:54116/packages/flutter/src/widgets/platform_view.dart.lib.js:11    62:12)
    at http://localhost:54116/packages/url_launcher_web/src/link.dart.lib.js:277:12  
    at _RootZone.runUnary (http://localhost:54116/dart_sdk.js:40589:59)
    at _FutureListener.then.handleValue (http://localhost:54116/dart_sdk.js:35516:29)    at handleValueCallback (http://localhost:54116/dart_sdk.js:36077:49)
    at Function._propagateToListeners (http://localhost:54116/dart_sdk.js:36115:17)  
    at _Future.new.[_completeWithValue] (http://localhost:54116/dart_sdk.js:35950:23)    at async._AsyncCallbackEntry.new.callback
    (http://localhost:54116/dart_sdk.js:35984:35)
    at Object._microtaskLoop (http://localhost:54116/dart_sdk.js:40856:13)
    at _startMicrotaskLoop (http://localhost:54116/dart_sdk.js:40862:13)
    at http://localhost:54116/dart_sdk.js:36339:9
Error: setState() called after dispose(): _PlatformViewLinkState#505c5(lifecycle
state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no     
longer appears in the widget tree (e.g., whose parent widget no longer includes the  
widget in its build). This error can occur when code calls setState() from a timer oran animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in  
the dispose() callback. Another solution is to check the "mounted" property of this  
object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because anotherobject is retaining a reference to this State object after it has been removed from  
the tree. To avoid memory leaks, consider breaking the reference to this object      
during dispose().
    at Object.throw_ [as throw] (http://localhost:54116/dart_sdk.js:5145:11)
    at http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11670:23    at platform_view$._PlatformViewLinkState.new.setState
    (http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11676:28) 
    at platform_view$._PlatformViewLinkState.new.[_onPlatformViewCreated]
    (http://localhost:54116/packages/flutter/src/widgets/platform_view.dart.lib.js:11    62:12)
    at http://localhost:54116/packages/url_launcher_web/src/link.dart.lib.js:277:12  
    at _RootZone.runUnary (http://localhost:54116/dart_sdk.js:40589:59)
    at _FutureListener.then.handleValue (http://localhost:54116/dart_sdk.js:35516:29)    at handleValueCallback (http://localhost:54116/dart_sdk.js:36077:49)
    at Function._propagateToListeners (http://localhost:54116/dart_sdk.js:36115:17)  
    at _Future.new.[_completeWithValue] (http://localhost:54116/dart_sdk.js:35950:23)    at async._AsyncCallbackEntry.new.callback
    (http://localhost:54116/dart_sdk.js:35984:35)
    at Object._microtaskLoop (http://localhost:54116/dart_sdk.js:40856:13)
    at _startMicrotaskLoop (http://localhost:54116/dart_sdk.js:40862:13)
    at http://localhost:54116/dart_sdk.js:36339:9
Error: setState() called after dispose(): _PlatformViewLinkState#b878f(lifecycle
state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no     
longer appears in the widget tree (e.g., whose parent widget no longer includes the  
widget in its build). This error can occur when code calls setState() from a timer oran animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in  
the dispose() callback. Another solution is to check the "mounted" property of this  
object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because anotherobject is retaining a reference to this State object after it has been removed from  
the tree. To avoid memory leaks, consider breaking the reference to this object      
during dispose().
    at Object.throw_ [as throw] (http://localhost:54116/dart_sdk.js:5145:11)
    at http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11670:23    at platform_view$._PlatformViewLinkState.new.setState
    (http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11676:28) 
    at platform_view$._PlatformViewLinkState.new.[_onPlatformViewCreated]
    (http://localhost:54116/packages/flutter/src/widgets/platform_view.dart.lib.js:11    62:12)
    at http://localhost:54116/packages/url_launcher_web/src/link.dart.lib.js:277:12  
    at _RootZone.runUnary (http://localhost:54116/dart_sdk.js:40589:59)
    at _FutureListener.then.handleValue (http://localhost:54116/dart_sdk.js:35516:29)    at handleValueCallback (http://localhost:54116/dart_sdk.js:36077:49)
    at Function._propagateToListeners (http://localhost:54116/dart_sdk.js:36115:17)  
    at _Future.new.[_completeWithValue] (http://localhost:54116/dart_sdk.js:35950:23)    at async._AsyncCallbackEntry.new.callback
    (http://localhost:54116/dart_sdk.js:35984:35)
    at Object._microtaskLoop (http://localhost:54116/dart_sdk.js:40856:13)
    at _startMicrotaskLoop (http://localhost:54116/dart_sdk.js:40862:13)
    at http://localhost:54116/dart_sdk.js:36339:9
Error: setState() called after dispose(): _PlatformViewLinkState#92085(lifecycle
state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no     
longer appears in the widget tree (e.g., whose parent widget no longer includes the  
widget in its build). This error can occur when code calls setState() from a timer oran animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in  
the dispose() callback. Another solution is to check the "mounted" property of this  
object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because anotherobject is retaining a reference to this State object after it has been removed from  
the tree. To avoid memory leaks, consider breaking the reference to this object      
during dispose().
    at Object.throw_ [as throw] (http://localhost:54116/dart_sdk.js:5145:11)
    at http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11670:23    at platform_view$._PlatformViewLinkState.new.setState
    (http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11676:28) 
    at platform_view$._PlatformViewLinkState.new.[_onPlatformViewCreated]
    (http://localhost:54116/packages/flutter/src/widgets/platform_view.dart.lib.js:11    62:12)
    at http://localhost:54116/packages/url_launcher_web/src/link.dart.lib.js:277:12  
    at _RootZone.runUnary (http://localhost:54116/dart_sdk.js:40589:59)
    at _FutureListener.then.handleValue (http://localhost:54116/dart_sdk.js:35516:29)    at handleValueCallback (http://localhost:54116/dart_sdk.js:36077:49)
    at Function._propagateToListeners (http://localhost:54116/dart_sdk.js:36115:17)  
    at _Future.new.[_completeWithValue] (http://localhost:54116/dart_sdk.js:35950:23)    at async._AsyncCallbackEntry.new.callback
    (http://localhost:54116/dart_sdk.js:35984:35)
    at Object._microtaskLoop (http://localhost:54116/dart_sdk.js:40856:13)
    at _startMicrotaskLoop (http://localhost:54116/dart_sdk.js:40862:13)
    at http://localhost:54116/dart_sdk.js:36339:9
Error: setState() called after dispose(): _PlatformViewLinkState#ac32b(lifecycle
state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no     
longer appears in the widget tree (e.g., whose parent widget no longer includes the  
widget in its build). This error can occur when code calls setState() from a timer oran animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in  
the dispose() callback. Another solution is to check the "mounted" property of this  
object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because anotherobject is retaining a reference to this State object after it has been removed from  
the tree. To avoid memory leaks, consider breaking the reference to this object      
during dispose().
    at Object.throw_ [as throw] (http://localhost:54116/dart_sdk.js:5145:11)
    at http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11670:23    at platform_view$._PlatformViewLinkState.new.setState
    (http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11676:28) 
    at platform_view$._PlatformViewLinkState.new.[_onPlatformViewCreated]
    (http://localhost:54116/packages/flutter/src/widgets/platform_view.dart.lib.js:11    62:12)
    at http://localhost:54116/packages/url_launcher_web/src/link.dart.lib.js:277:12  
    at _RootZone.runUnary (http://localhost:54116/dart_sdk.js:40589:59)
    at _FutureListener.then.handleValue (http://localhost:54116/dart_sdk.js:35516:29)    at handleValueCallback (http://localhost:54116/dart_sdk.js:36077:49)
    at Function._propagateToListeners (http://localhost:54116/dart_sdk.js:36115:17)  
    at _Future.new.[_completeWithValue] (http://localhost:54116/dart_sdk.js:35950:23)    at async._AsyncCallbackEntry.new.callback
    (http://localhost:54116/dart_sdk.js:35984:35)
    at Object._microtaskLoop (http://localhost:54116/dart_sdk.js:40856:13)
    at _startMicrotaskLoop (http://localhost:54116/dart_sdk.js:40862:13)
    at http://localhost:54116/dart_sdk.js:36339:9
Error: setState() called after dispose(): _PlatformViewLinkState#d4615(lifecycle
state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no     
longer appears in the widget tree (e.g., whose parent widget no longer includes the  
widget in its build). This error can occur when code calls setState() from a timer oran animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in  
the dispose() callback. Another solution is to check the "mounted" property of this  
object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because anotherobject is retaining a reference to this State object after it has been removed from  
the tree. To avoid memory leaks, consider breaking the reference to this object      
during dispose().
    at Object.throw_ [as throw] (http://localhost:54116/dart_sdk.js:5145:11)
    at http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11670:23    at platform_view$._PlatformViewLinkState.new.setState
    (http://localhost:54116/packages/flutter/src/widgets/title.dart.lib.js:11676:28) 
    at platform_view$._PlatformViewLinkState.new.[_onPlatformViewCreated]
    (http://localhost:54116/packages/flutter/src/widgets/platform_view.dart.lib.js:11    62:12)
    at http://localhost:54116/packages/url_launcher_web/src/link.dart.lib.js:277:12  
    at _RootZone.runUnary (http://localhost:54116/dart_sdk.js:40589:59)
    at _FutureListener.then.handleValue (http://localhost:54116/dart_sdk.js:35516:29)    at handleValueCallback (http://localhost:54116/dart_sdk.js:36077:49)
    at Function._propagateToListeners (http://localhost:54116/dart_sdk.js:36115:17)  
    at _Future.new.[_completeWithValue] (http://localhost:54116/dart_sdk.js:35950:23)    at async._AsyncCallbackEntry.new.callback
    (http://localhost:54116/dart_sdk.js:35984:35)
    at Object._microtaskLoop (http://localhost:54116/dart_sdk.js:40856:13)
    at _startMicrotaskLoop (http://localhost:54116/dart_sdk.js:40862:13)
    at http://localhost:54116/dart_sdk.js:36339:9
flutter doctor -v (windows)
[√] Flutter (Channel stable, 2.10.5, on Microsoft Windows [Version 10.0.19044.1645], locale en-US)
    • Flutter version 2.10.5 at C:\flutter_sdk\stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5464c5bac7 (2 days ago), 2022-04-18 09:55:37 -0700
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\mahesh\AppData\Local\Android\sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java      
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)    
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.4)      
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.31727.386
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 11.0.10+0-b96-7249189)        

[√] VS Code (version 1.64.2)
    • VS Code at C:\Users\mahesh\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.38.1

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19044.1645]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 100.0.4896.127
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 100.0.1185.44

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
[√] Flutter (Channel master, 2.13.0-0.0.pre.808, on Microsoft Windows [Version 10.0.19044.1645], locale en-IN)
    • Flutter version 2.13.0-0.0.pre.808 at C:\flutter_sdk\master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2eed8cbf93 (5 days ago), 2022-04-28 22:29:06 -0400
    • Engine revision dfdfe0b3b0
    • Dart version 2.18.0 (build 2.18.0-66.0.dev)
    • DevTools version 2.12.2

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\mahesh\AppData\Local\Android\sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java      
    • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)    
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.4)      
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.31727.386
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2021.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 11.0.11+9-b60-7590822)        

[√] VS Code (version 1.64.2)
    • VS Code at C:\Users\mahesh\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.40.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19044.1645]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 100.0.4896.127
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 100.0.1185.50

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

@maheshj01 maheshj01 added framework flutter/packages/flutter repository. See also f: labels. a: error message Error messages from the Flutter framework has reproducible steps The issue has been confirmed reproducible and is ready to work on found in release: 2.10 Found to occur in 2.10 and removed in triage Presently being triaged by the triage team labels May 4, 2022
@maheshj01 maheshj01 added the found in release: 2.13 Found to occur in 2.13 label May 4, 2022
@maheshj01 maheshj01 changed the title The Link widget in the url_launcher plugin calls setState after dispose Error: setState() called after dispose(): _PlatformViewLinkState#946fb(lifecycle state: defunct, not mounted) May 4, 2022
@kristoffer-zliide
Copy link
Author

The logs don't seem to point at the issue in the URL launcher plugin, so labeling it as a framework issue.

@maheshmnj: sorry, what?

I just highlighted two crucial parts of the log that are from url_launcher.

Also, in the bug report, I link directly to the place in the code where the bug is: you cannot call onPlatformViewCreated after the PlatformViewController is disposed. I even gave you a fix in url_launcher along with updated example code that shows the issue is indeed fixed.

@maheshj01 maheshj01 added plugin p: url_launcher Plugin to launch external applications labels May 4, 2022
@maheshj01 maheshj01 changed the title Error: setState() called after dispose(): _PlatformViewLinkState#946fb(lifecycle state: defunct, not mounted) [url_launcher]Error: setState() called after dispose(): _PlatformViewLinkState#946fb(lifecycle state: defunct, not mounted) May 4, 2022
@goderbauer goderbauer removed the framework flutter/packages/flutter repository. See also f: labels. label May 4, 2022
@stuartmorgan stuartmorgan added the P2 Important issues not at the top of the work list label May 5, 2022
@maheshj01 maheshj01 added the r: fixed Issue is closed as already fixed in a newer version label Jun 21, 2022
@github-actions
Copy link

github-actions bot commented Jul 5, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 5, 2022
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: error message Error messages from the Flutter framework found in release: 2.10 Found to occur in 2.10 found in release: 2.13 Found to occur in 2.13 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: url_launcher Plugin to launch external applications P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
4 participants