Home > database >  FLUUTER How to convert List <string>to List<custom type>? Event type
FLUUTER How to convert List <string>to List<custom type>? Event type

Time:01-09

I try to persist Event data type in my project

  loadEventList() async {
        await _init();
        final _ev = _prefs.getStringList('eventList');
        List<Event> listToEvent = _ev as List<Event>;
        return _events = listToEvent;
      }

I ve got this error:

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type 'List' is not a subtype of type 'List' in type cast

could somebody help me find a way to convert my list into a event list thank you.

CodePudding user response:

I think using the map function would help

_events = _ev.map((String element){return  Event(param);});
  •  Tags:  
  • Related