Flutter:GraphQL未处理的异常:NoSuchMethodError:在空调用getter“主机”

时间:2020-03-03 06:51:29

标签: flutter graphql

通过遵循此documentation,可以集成Graphql graphql_flutter。在Android和iOS的开发模式下,一切正常,但是当我尝试在发布模式下部署Android时,我能够生成APK。在手机上运行后,我在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

1 个答案:

答案 0 :(得分:0)

弄清楚了。这是因为权限问题。默认情况下,当Android应用程序在开发中运行时,它将具有INTERNET权限。

发布后,INTERNET权限将不再可用。您可以检查官方的documentation here

解决方案: 打开android清单

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

为清单添加Internet权限

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