Can i store a Map inside a Shared Preferences in dart?

前端 未结 3 2015
离开以前
离开以前 2020-12-29 03:56

Is there a way that we could save a map object into shared preferences so that we can fetch the data from shared preferences rather than listening to the database all the ti

3条回答
  •  孤独总比滥情好
    2020-12-29 04:20

    If you convert it to a string, you can store it

    import 'dart:convert';
    ...
    var s = json.encode(myMap);
    // or var s = jsonEncode(myMap);
    

    json.decode(...)/jsonDecode(...) makes a map from a string when you load it.

提交回复
热议问题