Kavin Varnan
Kavin Varnan

Reputation: 1989

Flutter: GraphQL Unhandled Exception: NoSuchMethodError: The getter 'host' was called on null

Integrated Graphql graphql_flutter by following this documentation. Everything works fine on development mode for both Android and iOS but when i try to deploy Android in release mode, i'm able to generate APK. Once i run on the phone i see this error on Logcat

2020-03-03 12:15:09.822 7384-7408/? E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The getter 'host' was called on null.
Receiver: null
Tried calling: host
#0      translateNetworkFailure (package:graphql/src/exceptions/io_network_exception.dart:14)
#1      translateFailure (package:graphql/src/exceptions/exceptions.dart:13)
#2      new HttpLink.<anonymous closure>.onListen (package:graphql/src/link/http/link_http.dart:104)
<asynchronous suspension>
#3      _runGuarded (dart:async/stream_controller.dart:807)
#4      _StreamController._subscribe.<anonymous closure> (dart:async/stream_controller.dart:686)
#5      _BufferingStreamSubscription._guardCallback (dart:async/stream_impl.dart:416)
#6      _StreamController._subscribe (dart:async/stream_controller.dart:685)
#7      _ControllerStream._createSubscription (dart:async/stream_controller.dart:820)
#8      _StreamImpl.listen (dart:async/stream_impl.dart:474)
#9      Stream.first (dart:async/stream.dart:1251)
#10     QueryManager._resolveQueryOnNetwork (package:graphql/src/core/query_manager.dart:119)
#11     QueryManager.fetchQueryAsMultiSourceResult (package:graphql/src/core/query_manager.dart:97)
#12     ObservableQuery.fetchResults (package:graphql/src/core/observable_query.dart:123)
#13     new ObservableQuery (package:graphql/src/core/observable_query.dart:32)
#14     QueryManager.watchQuery (package:graphql/src/core/query_manager.dart:35)
#15     GraphQLClient.watchQuery (package:graphql/src/graphql_client.dart:99)
#16     QueryState._initQuery (package:graphql_flutter/src/widgets/query.dart:60)
#17     QueryState.didChangeDependencies (package:graphql_flutter/src/widgets/query.dart:66)
#18     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4376)
#19     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201)
#20     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194)
#21     Element.updateChild (package:flutter/src/widgets/framework.dart:2988)
#22     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243)
#23     Element.rebuild (package:flutter/src/widgets/framework.dart:3947)
#24     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206)
#25     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201)
#26     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194)
#27     Element.updateChild (package:flutter/src/widgets/framework.dart:2988)
#28     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243)
#29     Element.rebuild (package:flutter/src/widgets/framework.dart:3947)
#30     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206)
#31     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201)
#32     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194)
#33     Element.updateChild (package:flutter/src/widgets/framework.dart:2988)
#34     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243)
#35     Element.rebuild (package:flutter/src/widgets/framework.dart:3947)
#36     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206)
#37     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201)
#38     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194)
#39     Element.updateChild (package:flutter/src/widgets/framework.dart:2988)
#40     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243)
#41     Element.rebuild (package:flutter/src/widgets/framework.dart:3947)
#42     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206)
#43     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201)
#44     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194)
#45     Element.updateChild (package:flutter/src/widgets/framework.dart:2988)
#46     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243)
#47     Ele

Upvotes: 1

Views: 632

Answers (1)

Kavin Varnan
Kavin Varnan

Reputation: 1989

Figured it out. Its because of permission issue. By default when an Android app runs on development it will have INTERNET permission.

Once you do a release the INTERNET permission will not be available anymore. You can check the official documentation here

Solution: Open android manifest

./android/app/src/main/AndroidManifest.xml

Add internet permission to your manifest

<manifest xlmns:android...>
...
  <uses-permission android:name="android.permission.INTERNET" />
  <application ...
</manifest>

Upvotes: 0

Related Questions