How to convert String List to String in flutter?

Prashant Katoch picture Prashant Katoch · Jun 4, 2019 · Viewed 28.1k times · Source

I need to convert List into a string in the dart.

I want to extract the value of the list from preferences. I have tried this implementation but it is only giving me the last value.

   Future<List<String>> 
    services=SharedPrefSignUp.getSelectedServices();
     services.then((onValue){
  List<String>servicesList=onValue;
  selectServicesText=servicesList.join(",");
});

Answer

Harsh Prajapati picture Harsh Prajapati · Jun 12, 2020

if you know you have List<String> then you can use join() function provided by a flutter.

    var list = ['one', 'two', 'three'];
    var stringList = list.join("");
    print(stringList); //Prints "onetwothree"

Simple and short. ;)

And you can use it like this:

 List<String>servicesList=["one", "Two", "Thee"]; 
 print(servicesList.join(""));