to_string_pretty 1.0.1
to_string_pretty: ^1.0.1 copied to clipboard
Prints an object pretty.
toStringPretty #
Prints an object pretty.
Installing #
dependencies:
to_string_pretty:
import 'package:to_string_pretty/to_string_pretty.dart';
Usage #
-
Basic
var data = ['google', 'apple', 'thanks']; print(toStringPretty(data));
// stdout [ google, apple, thanks, ],
-
toString()
class ChatMessage { // member variables, methods... @override String toString() => toStringPretty(this, { 'body': message 'sentBy': sentBy, 'sentAt': sentAt, 'group': group, }); } print(ChatMessage());
// stdout ChatMessage { body: Thanks, sentBy: ChatUser { email: hello@example.com, name: Liam, }, sentAt: ChatDateTime { datetime: 2021-02-21 19:07:00.000, }, group: Flutter Community, },
Limitations #
-
You have to manually specify the values to be displayed.
toStringPretty(someInstance, <String, Object>{ 'key1': value1, 'key2': value2, });
-
It is recommended to use toStringPretty() in the toString() method of all Classes.
In my case, I am using toStringPretty() as the standard logging format for my project.