6

This issue has been submitted to the Flutter github issues: https://github.com/flutter/flutter/issues/27450

I am having some trouble with running and hot reloading flutter apps in Android studio.

When I run an app in Android studio, I get the following message every now and again(2 out of 3 runs) and the build fails.

Launching lib/main.dart on iPhone XR in debug mode...
Unhandled exception:
Bad state: Future already completed
#0      _AsyncCompleter.complete (dart:async/future_impl.dart:39:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io/runtime/binsocket_patch.dart:490:23)
#2      _NativeSocket.issueWriteEvent.issue (dart:io/runtime/binsocket_patch.dart:844:14)
#3      _NativeSocket.issueWriteEvent (dart:io/runtime/binsocket_patch.dart:851:12)
#4      _NativeSocket.multiplex (dart:io/runtime/binsocket_patch.dart:872:11)
#5      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)

I have not been able to get hot reload to work at all

Performing hot reload...
Syncing files to device iPhone XR...
Unhandled exception:
Bad state: Future already completed
#0      _AsyncCompleter.complete (dart:async/future_impl.dart:39:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io/runtime/binsocket_patch.dart:490:23)
#2      _NativeSocket.issueWriteEvent.issue (dart:io/runtime/binsocket_patch.dart:844:14)
#3      _NativeSocket.issueWriteEvent (dart:io/runtime/binsocket_patch.dart:851:12)
#4      _NativeSocket.multiplex (dart:io/runtime/binsocket_patch.dart:872:11)
#5      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)

I am working on the stable channel. Here is my output of flutter doctor:

[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14.1 18B75, locale en-AU)
• Flutter version 1.0.0 at /Users/rakshak/flutter
• Framework revision 5391447fae (9 weeks ago), 2018-11-29 19:41:26 -0800
• Engine revision 7375a0f414
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

⣽Unhandled exception:
Bad state: Future already completed
#0      _AsyncCompleter.complete (dart:async/future_impl.dart:39:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io/runtime/binsocket_patch.dart:490:23)
#2      _NativeSocket.issueWriteEvent.issue (dart:io/runtime/binsocket_patch.dart:844:14)
#3      _NativeSocket.issueWriteEvent (dart:io/runtime/binsocket_patch.dart:851:12)
#4      _NativeSocket.multiplex (dart:io/runtime/binsocket_patch.dart:872:11)
#5      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)

I am working from China at the moment, I have implemented the changes mentioned here: https://flutter.io/community/china. Here are the relevant parts of my .bash_profile file

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=$PATH:/Users/rakshak/flutter/bin

I am working on a Mac.

DrkStr
  • 1,752
  • 5
  • 38
  • 90

4 Answers4

2

This might look like a weird suggestion; however, did you try using vpn while completing this action? I once faced this problem, then using a vpn connection helped me. I guess, you may give it a try.

onosecond
  • 548
  • 6
  • 10
  • Yeh, I think ill comment out the PUB_HOSTED_URL and FLUTTER_STORAGE_BASE_URL from my bask profile and just use a VPN. – DrkStr Feb 10 '19 at 01:35
0

If you are using a proxy, set the environment variable

NO_PROXY=127.0.0.1,localhost
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

This seems to have been a network related issue.

My fix for this: I have removed PUB_HOSTED_URL and FLUTTER_STORAGE_BASE_URL from my .bash_profile file and turned on my VPN.

It looks like you need an active and stable internet connection to build and hot reload a flutter app in development.

Related links:

DrkStr
  • 1,752
  • 5
  • 38
  • 90
-1

I recommend you to install again flutter following the steps used in this popular flutter course video. I hope it will be worth watching for you and your error will be removed Flutter Installation Guide As you are from China, so you have to add these steps as mentioned in the link Using Flutter In China

creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402
Scaphae Studio
  • 503
  • 3
  • 3
  • Thanks for the reply. I have followed the installation steps from the Flutter dev site. I have also implemented the steps in the "Using flutter in China" link. It didn't seem to help. – DrkStr Feb 08 '19 at 03:24