-3

The following regex allows for extraction of all dates (XXXX-XX-XX XX:XX) from a particular key (Key1).

RegExp regExp = new RegExp(
  r'(?<=Text\("key1:\[[^\][]*?)\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}(?=[^\][]*])',
);
var match = regExp.allMatches(decrypted).map((z) => z.group(0));
    
prefs.setStringList("mykey",match);

With this code I have in output from match

(2000-00-00 00:00, 2020-09-02 04:30, 2020-09-03 00:30, ..., 2020-09-03 10:00, 2020-09-03 10:02)

The problem is prefs.setStringList is a List and accept only this format ["","","",""]. How can I adapt my output to be compatible?

Christopher Moore
  • 15,626
  • 10
  • 42
  • 52
Nitneuq
  • 3,866
  • 13
  • 41
  • 64

1 Answers1

1

allMatches returns an Iterable, which is not the List that SharedPreferences requires. Use the toList method to pass the correct data type.

prefs.setStringList("mykey",match.toList());
Christopher Moore
  • 15,626
  • 10
  • 42
  • 52