http包在flutter中从api获取错误的图像url

Posted

技术标签:

【中文标题】http包在flutter中从api获取错误的图像url【英文标题】:http package get wrong image url from api in flutter 【发布时间】:2020-10-23 02:24:18 【问题描述】:

我有一个与 API 连接的 Flutter 应用程序,当我在 Flutter 中使用 http 包发出 Get 请求时,它会毫无问题地检索所有数据,除了图像 url:例如,这是来自浏览器的图像的 url:

http://192.168.43.106:3000/upload\\139585975-e-learning-concept-with-blurred-city-abstract-lights-background.jpg

但是从颤动的响应来看是这样的:

http://192.168.43.106:3000/upload%5C139585975-e-learning-concept-with-blurred-city-abstract-lights-background.jpg

如您所见,url中上传部分后的问题>>>>

这是API中的图像代码

const storage = multer.diskStorage(
    destination: (req, file, cb)=>
   cb(null, 'upload');
    ,

    filename: (req, file, cb)=>
        cb(null, file.originalname);
         
);
const filter = (req, file, cb)=>
    if(file.mimetype == "image/jpg" || file.mimetype == "image/jpeg" || file.mimetype == "image/png")
        cb(null, true)
    else
        cb(null, false);
    


const upload = multer(
    storage: storage,
    filter: filter
);
app.post('/service' ,upload.single('file'));
app.use('/upload', express.static('upload'));

这是获取所有数据,包括图片网址:

 getAllServices : async (req, res)=>
        try 
        const result = await SERVICES.find();
        res.json(
            result : result.map(result =>
                return 
                    id : result._id,
                    name : result.name,
                    file : 'http://192.168.43.106:3000:3000/'+result.file,
                    desc : result.desc,
                    price : result.price,
                    cat : result.cat,
                    url : 'http://192.168.43.106:3000:3000/service/'+result._id
                
            )
            );
        catch(err)result.json(err)
        
        ,

在颤振方面,我正在使用此代码获取数据:

class ServicesState extends State<Services>
  getCategories() async 
    var res = await http.get("http://192.168.43.106:3000/service/cat/$widget.cid");
    if(res.statusCode == 200)
      var jsonObject = json.decode(res.body);
      return jsonObject['result'];
    
  

  @override
  void initState() 
    getCategories();
    super.initState();
  
  @override
  Widget build(BuildContext context) 
    return Scaffold(
      appBar: AppBar(title: Text(widget.name), actions: <Widget>[
        IconButton(icon: Icon(Icons.arrow_back),
          onPressed: ()=>
        Navigator.pushReplacementNamed(context, '/cat'),
      ,)],),
      body: Center(
        child: FutureBuilder(
          future: getCategories(),
          builder: (context, snapshot)
            if(snapshot.data != null)
              return ListView.builder(
                itemCount: snapshot.data.length,
                itemBuilder: (context, index)
                  return ListTile(
                    onTap: ()
                      Navigator.pushReplacement(context,
                      MaterialPageRoute(builder: (context)=>ServiceDetails(
                        details: ServicesModel(
                          id: snapshot.data[index]['id'],
                          name: snapshot.data[index]['name'],
                          desc: snapshot.data[index]['desc'],
                          price: snapshot.data[index]['price'],
                          file: snapshot.data[index]['file']
                        ) ,)));
                    ,
                      leading:Image.network(snapshot.data[index]['file']),
                    title: Text(snapshot.data[index]['name']),
                    subtitle: Text(snapshot.data[index]['price']),
                  );
                ,
              );
            else
              return Center(child: CircularProgressIndicator(),);
            

请记住,除了图片网址之外,所有数据都没有任何问题>>>>

这是我得到的错误:如你所见,我从下面的 api 获得了所有数据>>

I/flutter (15351): [id: 5ef73963f8f4f552704eb5fb, name: momen, desc: uni, img: http://192.168.43.106:3000/mo11111, id: 5ef755aa9011f235d007d432, name: c1, desc: d1, img: http://192.168.43.106:3000/m1, id: 5ef755bb9011f235d007d433, name: c11, desc: d11, img: http://192.168.43.106:3000/m11, id: 5ef755e59011f235d007d434, name: c11, desc: d11, img: http://192.168.43.106:3000/m11, id: 5ef755f39011f235d007d435, name: c1, desc: d1, img: http://192.168.43.106:3000/m1, id: 5ef7567b215f705ec00d439a, name: c1, desc: d1, img: http://192.168.43.106:3000/m1, id: 5ef759d4167fb241b82fcfcd, name: newcat, desc: unimmm5n, img: http://192.168.43.106:3000/upload\500_F_216231494_oJFKyTVOUoiFMzvhhetAcSPktyZwhp7L.jpg, id: 5ef75ae8d313d64f4cecbfc5, name: c1, desc: d1, img: http://192.168.43.106:3000/cupload\Capture.PNG, id: 5ef75f15231fcc4edc13b3b9, name: c1y, desc: d1, img: http://192.168.43.106:3000/cupload\1_ir8j2Ag89QZFAKBZDZWEUw.png, id: 5efa29ba17c0672b88fb6ae8, name: catauth, desc: auth cat desc, img: http://192.168.43.106:30
I/flutter (15351): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter (15351): The following NetworkImageLoadException was thrown resolving an image codec:
I/flutter (15351): HTTP request failed, statusCode: 404, http://192.168.43.106:3000/mo11111
I/flutter (15351): 
I/flutter (15351): When the exception was thrown, this was the stack:
I/flutter (15351): #0      NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:90:9)
I/flutter (15351): <asynchronous suspension>
I/flutter (15351): #1      NetworkImage.load (package:flutter/src/painting/_network_image_io.dart:47:14)
I/flutter (15351): #2      ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:327:17)
I/flutter (15351): #3      ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:160:22)
I/flutter (15351): #4      ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:325:84)
I/flutter (15351): #5      SynchronousFuture.then (package:flutter/src/foundation/synchronous_future.dart:38:29)
I/flutter (15351): #6      ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:323:11)
I/flutter (15351): #10     ImageProvider.resolve (package:flutter/src/painting/image_provider.dart:315:16)
I/flutter (15351): #11     _ImageState._resolveImage (package:flutter/src/widgets/image.dart:1010:20)
I/flutter (15351): #12     _ImageState.didChangeDependencies (package:flutter/src/widgets/image.dart:967:5)
I/flutter (15351): #13     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4376:12)
I/flutter (15351): #14     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #15     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #16     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #17     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #18     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #19     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #20     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #21     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #22     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #23     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #24     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #25     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #26     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #27     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #28     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #29     _ListTileElement._mountChild (package:flutter/src/material/list_tile.dart:999:30)
I/flutter (15351): #30     _ListTileElement.mount (package:flutter/src/material/list_tile.dart:1013:5)
I/flutter (15351): #31     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #32     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #33     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #34     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #35     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #36     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #37     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #38     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #39     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
I/flutter (15351): #40     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #41     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #42     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #43     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #44     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #45     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #46     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #47     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #48     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
I/flutter (15351): #49     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #50     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #51     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
I/flutter (15351): #52     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #53     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #54     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #55     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #56     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #57     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #58     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #59     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #60     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
I/flutter (15351): #61     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #62     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #63     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #64     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #65     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #66     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
I/flutter (15351): #67     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #68     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #69     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #70     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #71     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #72     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #73     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #74     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #75     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #76     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
I/flutter (15351): #77     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #78     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #79     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
I/flutter (15351): #80     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #81     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #82     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #83     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #84     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #85     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #86     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #87     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #88     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #89     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #90     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #91     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
I/flutter (15351): #92     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #93     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #94     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #95     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #96     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #97     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #98     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #99     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #100    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #101    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #102    Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #103    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #104    StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
I/flutter (15351): #105    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #106    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #107    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #108    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #109    Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #110    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #111    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #112    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #113    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #114    SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
I/flutter (15351): #115    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #116    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #117    SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
I/flutter (15351): #118    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #119    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #120    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #121    Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #122    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #123    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #124    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #125    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #126    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #127    Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #128    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #129    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #130    ParentDataElement.mount (package:flutter/src/widgets/framework.dart:4617:11)
I/flutter (15351): #131    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #132    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #133    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #134    Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #135    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #136    StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
I/flutter (15351): #137    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (15351): #138    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #139    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #140    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (15351): #141    Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (15351): #142    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (15351): #143    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)

════════ Exception caught by image resource service ════════════════════════════════════════════════
The following NetworkImageLoadException was thrown resolving an image codec:
HTTP request failed, statusCode: 404, http://192.168.43.106:3000/m1

When the exception was thrown, this was the stack: 
#0      NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:90:9)
<asynchronous suspension>
#1      NetworkImage.load (package:flutter/src/painting/_network_image_io.dart:47:14)
#2      ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:327:17)
#3      ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:160:22)
...
Image provider: NetworkImage("http://192.168.43.106:3000/m1", scale: 1.0)
Image key: NetworkImage("http://192.168.43.106:3000/m1", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ (2) Exception caught by image resource service ════════════════════════════════════════════
HTTP request failed, statusCode: 404, http://192.168.43.106:3000/m11
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ (3) Exception caught by image resource service ════════════════════════════════════════════
HTTP request failed, statusCode: 404, http://192.168.43.106:3000/upload%5C500_F_216231494_oJFKyTVOUoiFMzvhhetAcSPktyZwhp7L.jpg
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ (4) Exception caught by image resource service ════════════════════════════════════════════
HTTP request failed, statusCode: 404, http://192.168.43.106:3000/cupload%5CCapture.PNG
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ (5) Exception caught by image resource service ════════════════════════════════════════════
HTTP request failed, statusCode: 404, http://192.168.43.106:3000/cupload%5C1_ir8j2Ag89QZFAKBZDZWEUw.png
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ (6) Exception caught by image resource service ════════════════════════════════════════════
HTTP request failed, statusCode: 404, http://192.168.43.106:3000/cupload%5C0157d41e-4db9-4d9a-9632-84c8a4cc15f1.png
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ (7) Exception caught by image resource service ════════════════════════════════════════════
HTTP request failed, statusCode: 404, http://192.168.43.106:3000/cupload%5Cdownload%20(1).jfif
════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (15351): [id: 5ef73963f8f4f552704eb5fb, name: momen, desc: uni, img: http://192.168.43.106:3000/mo11111, id: 5ef755aa9011f235d007d432, name: c1, desc: d1, img: http://192.168.43.106:3000/m1, id: 5ef755bb9011f235d007d433, name: c11, desc: d11, img: http://192.168.43.106:3000/m11, id: 5ef755e59011f235d007d434, name: c11, desc: d11, img: http://192.168.43.106:3000/m11, id: 5ef755f39011f235d007d435, name: c1, desc: d1, img: http://192.168.43.106:3000/m1, id: 5ef7567b215f705ec00d439a, name: c1, desc: d1, img: http://192.168.43.106:3000/m1, id: 5ef759d4167fb241b82fcfcd, name: newcat, desc: unimmm5n, img: http://192.168.43.106:3000/upload\500_F_216231494_oJFKyTVOUoiFMzvhhetAcSPktyZwhp7L.jpg, id: 5ef75ae8d313d64f4cecbfc5, name: c1, desc: d1, img: http://192.168.43.106:3000/cupload\Capture.PNG, id: 5ef75f15231fcc4edc13b3b9, name: c1y, desc: d1, img: http://192.168.43.106:3000/cupload\1_ir8j2Ag89QZFAKBZDZWEUw.png, id: 5efa29ba17c0672b88fb6ae8, name: catauth, desc: auth cat desc, img: http://192.168.43.106:30
I/flutter (15351): #144    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (15351): #145    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (15351): #146    SliverMultiBoxAdaptorElement.updateChild (package:flutter/src/widgets/sliver.dart:1288:36)
I/flutter (15351): #147    SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1273:20)
I/flutter (15351): #148    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2412:19)
I/flutter (15351): #149    SliverMultiBoxAdaptorElement.createChild (package:flutter/src/widgets/sliver.dart:1266:11)
I/flutter (15351): #150    RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure> (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:354:23)
I/flutter (15351): #151    RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:1823:58)
I/flutter (15351): #152    PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:875:15)
I/flutter (15351): #153    RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1823:13)
I/flutter (15351): #154    RenderSliverMultiBoxAdaptor._createOrObtainChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:343:5)
I/flutter (15351): #155    RenderSliverMultiBoxAdaptor.addInitialChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:427:5)
I/flutter (15351): #156    RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:78:12)
I/flutter (15351): #157    RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (15351): #158    RenderSliverEdgeInsetsPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:134:11)
I/flutter (15351): #159    RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:373:11)
I/flutter (15351): #160    RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (15351): #161    RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:410:13)
I/flutter (15351): #162    RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1367:12)
I/flutter (15351): #163    RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1285:20)
I/flutter (15351): #164    RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (15351): #165    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (15351): #166    RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (15351): #167    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (15351): #168    RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (15351): #169    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (15351): #170    RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (15351): #171    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (15351): #172    RenderObject.layout 

【问题讨论】:

网址错误... 192.168.43.106:3000/upload\\ 应该是 192.168.43.106:3000/upload/。这是在哪里生成的? 不,它是正确的,当我将它粘贴到浏览器或flutter Image.network中时,它会给我正确的图像,这个api是我电脑中的本地api,它与手机连接,一切都如我所说,除了图片的网址 【参考方案1】:

%5C 是问题见。每当在 dart 中使用 '\something' 时,\ 是旁边的转义序列,它被视为特殊字符。现在你有两个\,所以你知道\的字符值或编码版本是十六进制的5C。

所以你所要做的就是把它当作原始字符串,所以在r'' 中获取字符串,你的工作就完成了

您所能做的就是做一些代码来获取 url 拆分字符串。但这将是一条漫长的道路 希望这可以帮助:)

【讨论】:

您能说明一下如何解决吗?我不明白 在图片网络url中使用这个:r'snapshot.data[index]['file']'

以上是关于http包在flutter中从api获取错误的图像url的主要内容,如果未能解决你的问题,请参考以下文章

Flutter中从api获取数据时出错

如何在 Flutter 中从 API 获取 JSON 数据

在 Flutter 中从 API 获取数据

Flutter中从API获取数据时出现格式异常

为啥 HTTP 包在 Flutter web 中不起作用?

在 Flutter/Dart 中从字节加载图像的问题