Skip to content

Instantly share code, notes, and snippets.

@egulhan
Created May 1, 2020 16:25
Show Gist options
  • Save egulhan/83a856598bc64f291ddbcf9e4817b305 to your computer and use it in GitHub Desktop.
Save egulhan/83a856598bc64f291ddbcf9e4817b305 to your computer and use it in GitHub Desktop.
Dump function to print objects, variables in Flutter while debugging
/// 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