getMap static method

Future<Map<String, dynamic>> getMap(
  1. String key, {
  2. ValueChanged<Map<String, dynamic>>? callback,
})

Implementation

static Future<Map<String, dynamic>> getMap( String key,  {   ValueChanged<Map<String, dynamic>>? callback} ) async {
  // Map<String, Object> values = <String, Object>{'counter': 1};

  //get string of json from cache
  SharedPreferences prefs = await SharedPreferences.getInstance();
  String jsonString = prefs.getString(key) ?? "";

  // Log.k( "save class",  "getString() - key: " + key + " /value: " + result );
  if( ToolsValidation.isEmpty( jsonString ) ) {
    jsonString = "";
  }
  // Log.k( tag,  "getObject() jsonString: " + jsonString  );

  //convert to mapJson
  Map<String, dynamic> mapJson  = jsonDecode(jsonString);
  // Log.k( tag,  "getObject() Map<String, dynamic>: " + mapJson.toString()  );

  //callback
  if(callback != null ) callback(mapJson);
  return mapJson;
}