Created
May 1, 2020 16:25
-
-
Save egulhan/83a856598bc64f291ddbcf9e4817b305 to your computer and use it in GitHub Desktop.
Dump function to print objects, variables in Flutter while debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// dumps object (mostly used while debugging) | |
void dump(dynamic object,{bool printIt: true, String key, dynamic context}) { | |
if (!printIt) { | |
return; | |
} | |
String str = key != null ? key + ': ' : ''; | |
if (!(object is String)) { | |
String strObject = ''; | |
if (object is Map) { | |
strObject = jsonEncode(object); | |
} else { | |
strObject = object.toString(); | |
} | |
str += ' ' + strObject; | |
} else { | |
str += ' ' + object; | |
} | |
if (context != null) { | |
String strContext = ''; | |
if (!(context is String)) { | |
if (context is Map) { | |
strContext = jsonEncode(context); | |
} else { | |
strContext = context.toString(); | |
} | |
} | |
str += ' ' + strContext; | |
} | |
print(str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment