Search code examples
iosios-simulatorflutter

Flutter : Crash on using "package:http/http.dart" on iOS simulator?


I am using the Flutter beta 0.15v with Android Studio.The crash only occurs on iOS simulator - IphoneX 11.2.

Unhandled exception:
NoSuchMethodError: The getter 'stdout' was called on null.
Receiver: null
Tried calling: stdout
#0      Object.noSuchMethod (dart:core-patch/dart:core/object_patch.dart:46)
#1      stdout (package:flutter_tools/src/base/io.dart:176)
#2      StdoutLogger.writeToStdOut (package:flutter_tools/src/base/logger.dart:100)
#3      StdoutLogger.printStatus (package:flutter_tools/src/base/logger.dart:95)
#4      _AppRunLogger.printStatus (package:flutter_tools/src/commands/daemon.dart:849)
#5      printStatus (package:flutter_tools/src/globals.dart:39)
#6      ResidentRunner._serviceDisconnected (package:flutter_tools/src/resident_runner.dart:756)
#7      _rootRun (dart:async/zone.dart:1122)
#8      _CustomZone.run (dart:async/zone.dart:1023)
#9      _FutureListener.handleWhenComplete (dart:async/future_impl.dart:151)
#10     _Future._propagateToListeners.handleWhenCompleteCallback (dart:async/future_impl.dart:603)
#11     _Future._propagateToListeners (dart:async/future_impl.dart:659)
#12     _Future._completeWithValue (dart:async/future_impl.dart:477)
#13     _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:507)
#14     _rootRun (dart:async/zone.dart:1126)
#15     _CustomZone.run (dart:async/zone.dart:1023)
#16     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:949)
#17     _microtaskLoop (dart:async/schedule_microtask.dart:41)
#18     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#19     _runPendingImmediateCallback (dart:isolate-patch/dart:isolate/isolate_patch.dart:113)
#20     _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:166)

API call code as follows that uses http.dart

 import 'package:http/http.dart' as http;

              _loadData() async {
            String dataURL = "https://api.github.com/orgs/abc/members";
            http.Response response = await http.get(dataURL);
            setState(() {
              final membersJSON = JSON.decode(response.body);

              for (var memberJSON in membersJSON) {
                final member = new Member(
                    memberJSON["login"], memberJSON["avatar_url"]);
                _members.add(member);
              }
            });
          }

When you run it on ios simulator, the above exception is thrown everytime.

Member data class

class Member {
  final String login;
  final String avatarUrl;

  Member(this.login, this.avatarUrl) {
    if (login == null) {
      throw new ArgumentError("login of Member cannot be null. "
          "Received: '$login'");
    }
    if (avatarUrl == null) {
      throw new ArgumentError("avatarUrl of Member cannot be null. "
          "Received: '$avatarUrl'");
    }
  }
}

Solution

  • The issue got resolved after creating the whole demo in a new project again. Probably the issue was with the build process for ios only, as the android counterpart of the old project was executing correctly. Such annoying issue will be resolved in future updates I hope.