【发布时间】:2022-03-14 20:19:45
【问题描述】:
在 firebase 模拟器上执行 https 调用时,我只会收到 FirebaseFunctionException。除 https 调用外,其他所有功能都可以正常工作。在没有模拟器的情况下连接到 firebase 时,一切正常。我在互联网上找不到解决方案,有人可以帮忙吗?
方法调用:
try {
HttpsCallable callable =
FirebaseFunctions.instance.httpsCallable('getBookData');
final results = await callable.call(parameters);
初始化:
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
...
final localHostString = Platform.isAndroid ? '10.0.2.2' : 'localhost';
// dotenv.get('HOST_IP');
FirebaseFunctions.instance
.useFunctionsEmulator('http://$localHostString', 5001);
FirebaseFirestore.instance.settings = Settings(
host: '$localHostString:8080',
sslEnabled: false,
persistenceEnabled: false,
);
await auth.FirebaseAuth.instance.useEmulator(
Platform.isAndroid ? 'http://localhost:9099' : 'http://0.0.0.0:9099');
}
例外:
code:"unavailable"
details:null
message:"UNAVAILABLE"
plugin:"firebase_functions"
stackTrace:#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
<asynchronous suspension>
#2 MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:23:24)
<asynchronous suspension>
#3 HttpsCallable.call (package:cloud_functions/src/https_callable.dart:35:37)
<asynchronous suspension>
#4 BookRequest._requestBooksFromCloudFunction (package:bookR/shared/bookRequest.dart:47:23)
<asynchronous suspension>
#5 BookRequest.getMoreBooksByTitle (package:bookR/shared/bookRequest.dart:23:24)
<asynchronous suspension>
#6 BookRequest.getBookInformationByTitle (package:bookR/shared/bookRequest.dart:37:13)
<asynchronous suspension>
#7 SearchBar.build.<anonymous closure> (package:bookR/widgets/searchBar.dart:34:28)
<asynchronous suspension>
hashCode:439854717
runtimeType:Type (FirebaseFunctionsException)
【问题讨论】:
-
你在模拟器上安装了 Google play 服务吗?
-
是的 Google play 服务已安装
-
不,我已经在 android 模拟器上工作,将 ip 更改为 localhost 也没有帮助
-
我仍然面临同样的问题。没有人有想法或建议吗?
标签: firebase flutter https google-cloud-functions firebase-tools