show image from database that has backslash instead slash in path in flutter

401 Views Asked by At

I save my image in database with backslash (\) in address like this:

\image\carimage\2021_123test.jpg

Ok, when I want to show it in Image.network('imageurl') in flutter it is not possible to show that, because of backslash in path, I update one of iamge from database maunulay like this

/image/carimage/2021_123test.jpg

It work fine. In webpage I can see my images with previous path but in flutter I must change path, how can I do that dynamically

Update:

 return Scaffold(
  appBar: AppBar(
    title: const Text('car pro '),
  ),
  body: controller.obx(
    (data) => Center(
      child: (Card(
        child: Column(
          children: [
            Image.network('http://mywebsite.com/' + data!['image']),

          ],
        ),
      )),
    ),
  ),
);
1

There are 1 best solutions below

2
On

You can replace all backlashes with the replaceAll method:

String newImage = image.replaceAll(r'\', r'/');

Edit:

This solution wouldn't work since your image path would need to be a raw string, or contain double backlashes (\\). See this question. But if you add a double backslash to your image path when creating it in the database, then you can use:

Image.network("http://mywebsite.com/" +
                    data!['image'].replaceAll(r'\', r'/'))