1

All of the values from the response are showing except for the image. One weird thing is that when I try to build it from my laptop, the images show. but when I try to build it on my PC, it doesn't.

No errors found in debug.

here is the sample of the response:

[
  {
    "id": 7,
    "user_id": 1,
    "caption": "Ambot ya",
    "image": "storage\/images\/posts\/image\/20190927UTC163833894.jpeg",
    "type": "image",
    "created_at": "2019-09-27 16:38:33",
    "updated_at": "2019-09-27 16:38:33",
    "deleted_at": null,
    "likes_count": 1,
    "isLiked": 0,
    "comments": [],
    "likes": [

here is how I get the response;

  Future<List<Feed>> getFeedAll() async {
    var res = await http.get(
        Uri.encodeFull(APIServices.HTTP_DOMAIN + APIServices.POST_GET_ALL),
        headers: {"Authorization": "Bearer " + Constants.token});
    print(res.body);
    if (res.statusCode == 200) {
      var data = json.decode(res.body);

      print(data);

      feedList = data.map<Feed>((json) => Feed.fromJson(json)).toList();
      print(feedList);
    }
    print("List Size: ${feedList.length}");

    return feedList;
  }

and here is how I display it:

Image.network("${APIServices.HTTP_DOMAIN}${feed[index].image}",
                                            fit: BoxFit.cover,
                                          )

EDIT: I'm using an actual device to test. SAMSUNG J7 PRO

4

1 回答 1

0

首先检查颤振文档 ,然后如果这两种方式无法解决您的问题,请使用此小部件

 if (kIsWeb) {
      return Stack(
        children: [
          SizedBox(
              height: 300,
              width: 450,
              child: Image.asset('Assets/Images/placeHolder.png',
                  fit: BoxFit.fill)),
          Container(
            height: 300,
            width: 450,
            decoration: BoxDecoration(
                image: DecorationImage(
                    image: NetworkImage(imageUrl ?? ""), fit: BoxFit.fill)),
          ),
        ],
      );
    }
于 2021-11-22T11:03:53.557 回答