vikrant yadav
vikrant yadav

Reputation: 37

Invalid argument(s): No host specified in URI file:///

i am using a stream builder to receive image and other things here is the code of that but the image is loaded after a few seconds with this error (Invalid argument(s): No host specified in URI file:///)

   Widget chatRoomsLists() {
         return StreamBuilder<QuerySnapshot<Map<String, dynamic>>>(
             stream:  FirebaseFirestore.instance
                 .collection('chatrooms').orderBy("lastMessageSendTs", descending: true)
                 .where("users", arrayContains:myUserName)
    
    
                 .withConverter<Map<String, dynamic>>(
               fromFirestore: (snapshot, _) =>
               snapshot.data() ?? Map<String, dynamic>(),
               toFirestore: (model, _) => Map<String, dynamic>.from(model),
             )
                 .snapshots(),
             builder: (context, snapshot){
           return snapshot.hasData ? ListView.builder(
               shrinkWrap: true,
             itemCount: snapshot.data?.docs.length,
               itemBuilder: (context,index){
                 DocumentSnapshot ds = snapshot.data!.docs[index];
    
                 return  ChatRoomListTile(ds['lastMessage'], ds.id,myUserName );
    
               }) : Center(child: CircularProgressIndicator());
         }) ;
       }

after receiving the image i am showing it inside a container

class ChatRoomListTile extends StatefulWidget {

  final String lastMessage , chatRoomId, myUsername;
  ChatRoomListTile(this.lastMessage, this.chatRoomId, this.myUsername,);

  @override
  _ChatRoomListTileState createState() => _ChatRoomListTileState();
}

class _ChatRoomListTileState extends State<ChatRoomListTile> {
  String profilePicUrl = "", name = '', username = "";

  getThisUserInfo() async {

    username =
        widget.chatRoomId.replaceAll(widget.myUsername, "").replaceAll("_", "");
    QuerySnapshot querySnapshot = await DatabaseMethods().getUserInfo(username);
    name = "${querySnapshot.docs[0]["name"]}";
     profilePicUrl = "${querySnapshot.docs[0]["profileURL"]}";
    setState(() {});
  }


    @override
  void initState() {

    super.initState();
    getThisUserInfo().whenComplete((){
      setState(() {});
    });
  }




  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => Chatting(username, widget.myUsername)));
      },
      child: Container(
        margin: EdgeInsets.symmetric(vertical: 8),
        child: Row(
          children: [
            ClipRRect(
              borderRadius: BorderRadius.circular(30),
              child: Image.network(profilePicUrl,
                height: 40,
                width: 40,
              ),
            ),
            SizedBox(width: 12),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  name,
                  style: TextStyle(fontSize: 16),
                ),
                SizedBox(height: 3),
                SizedBox(width: 220,
                    child: Text(widget.lastMessage,overflow: TextOverflow.ellipsis))
              ],
            )
          ],
        ),
      ),
    );
  }
}

here are the errors that i am receiving in the console

======== Exception caught by image resource service ================================================ The following ArgumentError was thrown resolving an image codec:

Invalid argument(s): No host specified in URI file:///

When the exception was thrown, this was the stack: 
#0      _HttpClient._openUrl (dart:_http/http_impl.dart:2636:9)
#1      _HttpClient.getUrl (dart:_http/http_impl.dart:2565:48)
#2      NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:89:59)
#3      NetworkImage.load (package:flutter/src/painting/_network_image_io.dart:50:14)
#4      ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:503:13)
...
Image provider: NetworkImage("", scale: 1.0)
Image key: NetworkImage("", scale: 1.0)

and this is the image url which i am getting from firebase https://lh3.googleusercontent.com/a/AATXAJwLWYH-rx8sDZs_LvMSUTp-ezpVdJwo0m7n-D7v=s96-c

Upvotes: 0

Views: 365

Answers (1)

Jos&#233; David Ortega
Jos&#233; David Ortega

Reputation: 434

Perhaps you can wrap your build method with a FutureBuilder and wait for that data instead of calling the getThisUserInfo() method in the initState(). The problem is that you are trying to build the imageNetwork before the data arrives.

Upvotes: 1

Related Questions