![](/img/trans.png)
[英]Flutter -Firebase/FireStore - Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds
[英]unable to reach firebase backend with flutter app
我從 firebase 和 flutter 開始。 我想從工作代碼開始,所以我實現了嬰兒名字代碼實驗室。 有效。 然后停止工作。 我嘗試更新 codelab 以使用最新版本的 firestore。 仍然不再工作。 這發生在我身上,有一個不同的應用程序。 即使我住在泰國,我的互聯網連接也很好。
這是更新的嬰兒名字代碼實驗室
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
final dummySnapshot = [
{"name": "Filip", "votes": 15},
{"name": "Abraham", "votes": 14},
{"name": "Richard", "votes": 11},
{"name": "Ike", "votes": 10},
{"name": "Justin", "votes": 1},
];
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Baby Names',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() {
return _MyHomePageState();
}
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Baby Name Votes')),
body: _buildBody(context),
);
}
Widget _buildBody(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection('baby').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator();
return _buildList(context, snapshot.data.docs);
},
);
}
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
return ListView(
padding: const EdgeInsets.only(top: 20.0),
children: snapshot.map((data) => _buildListItem(context, data)).toList(),
);
}
Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
final record = Record.fromSnapshot(data);
return Padding(
key: ValueKey(record.name),
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(5.0),
),
child: ListTile(
title: Text(record.name),
trailing: Text(record.votes.toString()),
onTap: () => record.reference.update({'votes': FieldValue.increment(1)})
),
),
);
}
}
class Record {
final String name;
final int votes;
final DocumentReference reference;
Record.fromMap(Map<String, dynamic> map, {this.reference})
: assert(map['name'] != null),
assert(map['votes'] != null),
name = map['name'],
votes = map['votes'];
Record.fromSnapshot(DocumentSnapshot snapshot)
: this.fromMap(snapshot.data(), reference: snapshot.reference);
@override
String toString() => "Record<$name:$votes>";
}
這是 pubspec.yaml 的相關部分
依賴項:顫振:sdk:顫振
cupertino_icons:^1.0.0 cloud_firestore:^0.14.3 firebase_core:^0.5.2
這是 flutter run --verbose 的相關(我希望)部分
[ ] I/ProviderInstaller(30660): Installed default security provider GmsCore_OpenSSL
[ +91 ms] D/ConnectivityManager(30660): requestNetwork; CallingUid : 10182, CallingPid : 30660
[ +76 ms] W/ware.baby_name(30660): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
[ ] W/ware.baby_name(30660): Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
[+5234 ms] D/ViewRootImpl@7513633[MainActivity](30660): ViewPostIme pointer 0
[ +73 ms] D/ViewRootImpl@7513633[MainActivity](30660): ViewPostIme pointer 1
[+4565 ms] W/Firestore(30660): (22.0.0) [OnlineStateTracker]: Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds
[ ] W/Firestore(30660):
[ ] W/Firestore(30660): This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
[+5138 ms] D/ConnectivityManager(30660): unregisterNetworkCallback; CallingUid : 10182, CallingPid : 30660
[ +28 ms] W/Firestore(30660): (22.0.0) [WriteStream]: (eed8101) Stream closed with status: Status{code=UNAVAILABLE, description=Channel shutdownNow invoked, cause=null}.
[ +12 ms] W/DynamiteModule(30660): Local module descriptor class for providerinstaller not found.
[ ] W/Firestore(30660): (22.0.0) [WatchStream]: (78299e7) Stream closed with status: Status{code=UNAVAILABLE, description=Channel shutdownNow invoked, cause=null}.
[ +11 ms] I/DynamiteModule(30660): Considering local module providerinstaller:0 and remote module providerinstaller:0
[ ] W/ProviderInstaller(30660): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
[ +9 ms] D/ConnectivityManager(30660): requestNetwork; CallingUid : 10182, CallingPid : 30660
[+15025 ms] D/ConnectivityManager(30660): unregisterNetworkCallback; CallingUid : 10182, CallingPid : 30660
[ +10 ms] W/Firestore(30660): (22.0.0) [WriteStream]: (eed8101) Stream closed with status: Status{code=UNAVAILABLE, description=Channel shutdownNow invoked, cause=null}.
[ +4 ms] W/Firestore(30660): (22.0.0) [WatchStream]: (78299e7) Stream closed with status: Status{code=UNAVAILABLE, description=Channel shutdownNow invoked, cause=null}.
我看到它說后端在 30 秒內沒有響應並且可能表明互聯網連接不良的部分。 但我的互聯網沒有任何問題。 它一直工作正常。 為了嘗試解決此問題,我最初將其設置在東南亞 2 中,因為我在泰國。 當它在第二天停止工作時。 我從 firebase 中刪除了我的項目,並在美國西海岸重建了它。 我也用我的 vpn 運行它以防萬一。 然后我刪除了該項目並將其放回東南亞。 這些都沒有對這個錯誤產生任何影響。
您可能只是忽略了某個步驟或在某些時候弄亂了配置。 嘗試從頭開始另一個項目,看看問題是否仍然存在。
問題解決了。 我試着用我的手機作為熱點來測試它是否是我的網絡。 一旦我這樣做了,它就開始工作了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.