parseItems function Null safety

List<Map<String, dynamic>> parseItems(
  1. dynamic itemsString
)

Implementation

List<Map<String, dynamic>> parseItems(dynamic itemsString){
  List<Map<String, dynamic>> items = [];
  if(itemsString is String){
    List<dynamic> rawItems = jsonDecode(itemsString);
    for (var i = 0; i < rawItems.length; i++) {
      items.add(rawItems[i] as Map<String, dynamic>);
    }
  }else if(itemsString is List<dynamic>){
    for (var i = 0; i < itemsString.length; i++) {
      items.add(itemsString[i] as Map<String, dynamic>);
    }
  }else if(itemsString is List<Map<String, dynamic>>){
    for (var i = 0; i < itemsString.length; i++) {
      items.add(itemsString[i]);
    }
  }
  return items;
}