从laravel获取图像并显示在flutter中

9ceoxa92  于 2023-06-07  发布在  Flutter
关注(0)|答案(1)|浏览(235)

我得到一个错误无效的参数:URI file:///jsonlist%5Bindex%5D%5B 'image'%5D中未指定主机,前导小部件占用整个平铺宽度。请使用一个大小的小部件,或考虑使用自定义小部件替换ListTile

LARAVEL 
code for get data from database dan sent those to flutter

public function getData(){
        $images=imageModel::orderBy('id','DESC')->get();
        return response()->json($images);
       
}
FLUTTER
and this is my code in flutter

  void getData() async{
    try{
    var response =await Dio().get("http://192.168.1.10:80/api/getdata");
    // print(response.data);//i try to print the response and those successed recieved by flutter
    if(response.statusCode==200){
      setState(() {
        jsonlist=response.data as List;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView.builder(itemBuilder: (BuildContext context, int index){
        return Card(
          child: ListTile(
            leading: ClipRRect(
              borderRadius: BorderRadius.circular(80),
              child: Image.network(jsonlist[index]['image'],fit: BoxFit.fitHeight,width: 50,height: 50,),
            ),
            title: Text(jsonlist[index]['title']),

          ),
        );
      },
        itemCount: jsonlist==null ? 0:jsonlist.length,
      ),
    );
  }
}

与上面的数据的代码已经发送到Flutter,但它不工作显示在listile的图像,有人可以帮助我…如何显示图像?

wixjitnu

wixjitnu1#

您的代码是正确的,但当您将图像URL传递给Image.network()时,您需要删除双引号。

Image.network(jsonlist[index]['image'].toString(),
  fit: BoxFit.fitHeight,
  width: 50, 
  height: 50,
),

试试这个

相关问题