how to solved : type 'List' is not a subtype of type 'String'

The error message "type 'List<dynamic>' is not a subtype of type 'String'" occurs when you try to assign a value of type `List<dynamic>` to a variable of type `String`.

In the code you provided, it seems like you are trying to read data from the `box` and assign it to a variable of type `String`, but the data in the `box` is of type `List<dynamic>`, which cannot be directly assigned to a `String` variable.

To resolve this issue, you need to ensure that the data stored in the `box` is of the correct type. If you expect the data to be a `String`, you can convert the `List<dynamic>` to a `String` before assigning it to the variable. Here's an example of how you can do that:

Solved :       CategoryModel is a model class and categoryList is a list type of CategoryModel. 

var list1 = box.read("categoryList1")?? [];
categoryList = List<CategoryModel>.from(
list1!.map((x) => CategoryModel.fromJson(x)));

In this example, the `dataList` is a `List<dynamic>` that you read from the `box`. We use the `join()` method to convert the list elements to a single comma-separated `String` value. This `String` value can then be assigned to your `yourVariable` variable.

Make sure to adapt the code according to your specific data and requirements. If the data in the `box` is not actually supposed to be a `String`, you'll need to handle it accordingly based on the correct data type.

Post a Comment

Thank you

Previous Post Next Post