You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import'package:flutter/material.dart';
import'package:web_socket_channel/web_socket_channel.dart';
import'dart:convert';
import'dart:math';
voidmain() =>runApp(MyApp());
classMyAppextendsStatelessWidget {
@overrideWidgetbuild(BuildContext context) =>MaterialApp(home:MyHomePage());
}
classMyHomePageextendsStatefulWidget {
@override_MyHomePageStatecreateState() =>_MyHomePageState();
}
class_MyHomePageStateextendsState<MyHomePage> {
var test =0;
lateint randomInt;
var random =Random();
var uri =Uri.parse('wss://ws-feed-public.sandbox.pro.coinbase.com');
lateWebSocketChannel channel;
String request = json.encode({
"type":"subscribe",
"product_ids": ["BTC-USD"],
"channels": ["heartbeat"],
});
@overridevoidinitState() {
randomInt = random.nextInt(1000);
channel =WebSocketChannel.connect(uri);
channel.sink.add(request);
channel.stream.listen((event) {
print('$randomInt: $test');
test = test +1;
});
super.initState();
}
@overrideWidgetbuild(BuildContext context) =>Container();
}
pubspec.yaml
name: echowebsocketdescription: A new Flutter project.version: 1.0.0+1environment:
sdk: ">=2.12.0 <3.0.0"dependencies:
flutter:
sdk: flutterweb_socket_channel: ^2.1.0dev_dependencies:
flutter_test:
sdk: flutterflutter:
uses-material-design: true
When I run the above code in flutter web and I do a hot restart (the green play button in android studio) the stream .listen() function survives the restart leaving two listening functions running.
An example output after running from cold (Chrome closed):
This application is not configured to build on the web.
To add web support to a project, run `flutter create .`.
Launching lib/main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
This app is linked to the debug service: ws://127.0.0.1:56738/yLBcQjxMep4=/ws
Debug service listening on ws://127.0.0.1:56738/yLBcQjxMep4=/ws
💪 Running with sound null safety 💪
Debug service listening on ws://127.0.0.1:56738/yLBcQjxMep4=/ws
582: 0
582: 1
582: 2
582: 3
582: 4
582: 5
582: 6
582: 7
582: 8
Then after a hot restart:
Performing hot restart...
Waiting for connection from debug service on Chrome...
582: 30
Restarted application in 155ms.
876: 0
876: 1
582: 31
876: 2
582: 32
876: 3
582: 33
582: 34
876: 4
582: 35
876: 5
582: 36
876: 6
582: 37
876: 7
876: 8
As you can see there are now two listen functions being executed. I was under the impression that no state is supposed to survive a hot restart. I have sometimes been able to recreate this problem on emulators but it seems to work every time on web. It seems like its some kind of memory leak but dispose() doesn't get called when I do a hot restart so it doesn't matter what i do there. Here is the output of flutter doctor:
[✓] Flutter (Channel stable, 2.5.2, on macOS 11.6 20G165 darwin-x64, locale en)
• Flutter version 2.5.2 at /Users/pcrady/Documents/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 3595343e20 (7 weeks ago), 2021-09-30 12:58:18 -0700
• Engine revision 6ac856380f
• Dart version 2.14.3
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/pcrady/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 at /Applications/Xcode.app/Contents/Developer
• Xcode 13.1, Build version 13A1030d
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3)
• 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.10+0-b96-7281165)
[✓] Connected device (1 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.45
! Doctor found issues in 1 category.
The text was updated successfully, but these errors were encountered:
HI @pcrady
From what I can see, the issue is related to a 3rd party plugin rather than to Flutter itself. Please open the issue in the dedicated repository.
Closing, as this isn't an issue with Flutter itself.
If you disagree, please write in the comments,
providing your flutter doctor -v, your flutter run -v, your pubspec.yaml, a minimal reproducible code sample that does not use 3rd party plugins, your complete flutter run -v logs running the minimal code sample
and I will reopen it.
Thank you
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.
main.dart
pubspec.yaml
When I run the above code in flutter web and I do a hot restart (the green play button in android studio) the stream .listen() function survives the restart leaving two listening functions running.
An example output after running from cold (Chrome closed):
Then after a hot restart:
As you can see there are now two listen functions being executed. I was under the impression that no state is supposed to survive a hot restart. I have sometimes been able to recreate this problem on emulators but it seems to work every time on web. It seems like its some kind of memory leak but dispose() doesn't get called when I do a hot restart so it doesn't matter what i do there. Here is the output of flutter doctor:
The text was updated successfully, but these errors were encountered: