adplus-dvertising

How to split a string from rest api? flutter

Asked 2 days ago
Viewed 13 times

i have a list of string from rest API like this

response

i try to split it using this code e.review!.map((e) => e).join(" "),

and i get this result current result

but my expectation result is

expected result

how do i do that? Thank you

model.dart

  RatingDataModel({
    this.rating,
    this.review,
  });

  int? rating;
  List<String>? review;

  factory RatingDataModel.fromJson(Map<String, dynamic> json) =>
      RatingDataModel(
        rating: json["rating"],
        //separate the review by space

        review: json["review"] != null
            ? List<String>.from(json["review"].map((x) => x))
            : null,
      );

  Map<String, dynamic> toJson() => {
        "rating": rating,
        "review": List<dynamic>.from(
          review!.map(
            (x) => x,
          ),
        ),
      };
}

asked 2 days ago

Correct Answer

You don't need to split since it's a list of strings,just iterate through with a 'listview'

answered 2 days ago