getTagsAsDictionaries method

Future<List<Map<String, String>>?> getTagsAsDictionaries()

Returns the tags saved as dictionaries/maps. @return A future that completes with the list of tags saved, as dictionaries/maps, ready to be sent to the APIs.

Implementation

Future<List<Map<String, String>>?> getTagsAsDictionaries() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  String? tags = prefs.getString('com.mumble.mburger.audience.tags');
  if (tags == null) {
    return null;
  }
  List tagsList = json.decode(tags);
  List<Map<String, String>> tagsToReturn = [];
  for (dynamic tagDynamic in tagsList) {
    if (tagDynamic is Map<String, dynamic>) {
      tagsToReturn.add(
        Map.castFrom<String, dynamic, String, String>(tagDynamic),
      );
    }
  }
  return tagsToReturn;
}