我在我的运行控制台上收到这个警告。基本上,我的chatRoomTile没有显示在屏幕上。它只显示空白屏幕,即使我已经与10个人聊天。
它只是显示主屏幕和红色容器2秒,如条件语句中所示。
这是run -
Performing hot restart...
Syncing files to device sdk gphone x86...
Restarted application in 1,522ms.
W/eyansh.whatsap( 6057): Accessing hidden method Ldalvik/system/CloseGuard;->close()V (greylist,core-platform-api, linking, allowed)
W/DynamiteModule( 6057): Local module descriptor class for providerinstaller not found.
I/DynamiteModule( 6057): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller( 6057): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
Lost connection to device.
这是我的代码-
import 'package:flutter/material.dart';
import 'package:whatsapp/helper/authenticate.dart';
import 'package:whatsapp/helper/constants.dart';
import 'package:whatsapp/helper/helperFunctions.dart';
import 'package:whatsapp/screens/search.dart';
import 'package:whatsapp/services/auth.dart';
import 'package:whatsapp/services/database.dart';
class ChatRoom extends StatefulWidget {
@override
_ChatRoomState createState() => _ChatRoomState();
}
class _ChatRoomState extends State<ChatRoom> {
AuthMethods authMethods = new AuthMethods();
DatabaseMethods databaseMethods = new DatabaseMethods();
Stream chatRoomStream;
Widget chatRoomList(){
return StreamBuilder(
stream: chatRoomStream,
builder: (context, snapshot) {
return snapshot.hasData ? ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
return ChatRoomTile(
snapshot.data.documents[index]["chatRoomId"],
);
}) : Container(color: Colors.red,);
},
);
}
@override
void initState() {
getUserInfo();
super.initState();
}
getUserInfo() async{
Constants.myName = await HelperFunctions.getUserNameSharedPreference();
databaseMethods.getChatRooms(Constants.myName).then((val){
setState(() {
chatRoomStream = val;
});
});
setState(() {
});
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
backgroundColor: Color(0xff161517),
title: Text(
'WhatsApp',
style: TextStyle(
color: Colors.white54,
fontSize: 20.0,
),
),
actions: [
Container(
height: 25.0,
width: 25.0,
child: FloatingActionButton(
heroTag: "btn1",
backgroundColor: Color(0xff161517),
child: Icon(Icons.search, color: Colors.white54,),
onPressed: (){
},
),
),
GestureDetector(
onTap: (){
authMethods.signOut();
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => Authenticate()));
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 15.0),
child: Icon(
Icons.exit_to_app,
color: Colors.white54,
),
),
),
GestureDetector(
onTap: (){
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 1.0),
child: Icon(
Icons.more_vert,
color: Colors.white54,
),
),
),
],
),
body: chatRoomList(),
floatingActionButton: FloatingActionButton(
heroTag: "btn2",
backgroundColor: Colors.green[700],
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => SearchScreen()));
},
child: Icon(
Icons.message,
color: Colors.white,
),
),
),
);
}
}
class ChatRoomTile extends StatelessWidget {
final String userName;
ChatRoomTile(this.userName);
@override
Widget build(BuildContext context) {
return Container(
child: Row(
children: [
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: AssetImage("assets/images/DefaultPhoto.png"),
fit: BoxFit.fill,
),
borderRadius: BorderRadius.circular(40.0),
),
),
SizedBox(width: 8.0,),
Text(
userName,
style: TextStyle(
color: Colors.white,
),
),
],
),
);
}
}
如果有人想知道任何小部件的细节,你可以问我。
6条答案
按热度按时间gijlo24d1#
在
<application>
启动之前,将下列使用权限加入android/app/src/main/AndroidManifest.xml
:n3schb8v2#
我遇到了同样的错误。我检查了我的代码,发现我在调用firebasefirestore时给出了错误的集合名称。请务必检查您是否为集合和文档提供了正确的引用名称。
e5nszbig3#
"为什么会来"
这是因为你的模拟器没有互联网连接。虽然它显示wifi连接。
解决方案:
1.首先检查你的互联网连接状态。
1.转到Emulator并关闭wifi,然后再次打开wifi。就是这样。
另外,不要忘记将下面的代码添加到
AndroidManifest.xml
在
<android>
之前ccrfmcuu4#
当无线处于活动状态但与Firestore的连接失败时,我看到此错误。例如,在调试时,我连接到本地模拟器,如果我忘记启动模拟器,我会收到此消息,但应用程序仍然从缓存中工作。
sulc1iza5#
请确保您从firestore调用了正确的示例名称。我在instace中调用了medicine product,并且在firebase数据库中定义了MedicineProductData,因此将其更正为MedicineProductData解决了我的问题
如果您有任何问题,请与我们联系。
t0ybt7op6#