Home > Software design >  Flutter String Interpolation remain dolloar sign after compiled
Flutter String Interpolation remain dolloar sign after compiled

Time:10-11

I'm using code like below

get('/api/products/detail/$name/')

it seems working fine for most of cases as I expected like below

// If variable value is 'apple'
get('/api/products/detail/apple/')

but sometimes error are catched by sentry and sentry says

My request's url was '/api/products/detail/$apple/'

This happens not all the time and it makes me so unstable

Is there anybody why this is happening and how to prevent this?

I'm using flutter 2.8.1 and dart version 2.15.1

CodePudding user response:

You can make all api requests in one method and check it with url replace before sending the one you want.

something like this

class HttpService{
  static void  get(String path){
    path=path.replaceAll("\$","");
    // your api request
  }
}


void main() {
 var name="apple";
   var url="/api/products/detail/$name/";
  HttpService.get(url);
}

CodePudding user response:

Try below code: refer string-interpolation

var fruitName = "apple";
var apiURL = "/api/products/detail/$fruitName/";
print(apiURL);

your URL- /api/products/detail/apple/

  • Related