pretty_string 0.1.1 copy "pretty_string: ^0.1.1" to clipboard
pretty_string: ^0.1.1 copied to clipboard

A tool to convert ugly toString() generated by such as Equatable or Freezed to be prettier.

Pretty String #

style: very good analysis License: MIT

A simple way to log strings to be awesome!

Installation 💻 #

Add pretty_string to your pubspec.yaml:

dependencies:
  pretty_string: 0.1.0

Install it:

flutter pub get

Motivation #

Almost every application, we need to log APIs, BLoc state transitions, ..etc to debug what is happening there. But models in dart using such as Equatable, Freezed and Plain dart object has not "very" kind toString() implementation. Compare between equatable-toString() and equatable-toPrettier(). Pretty powerful right? This also works with freezed too. Remember this examples are very simple case. In real world, there are very complicated object that has dozens of properties which makes you crazy to see log without toPrettier().

Usage💯 #

  • This packages has very simple extension method named .toPrettier(). This makes every strings to be awesome to read! What only you need to do is calling .toPrettier() to an object or a string.
final object = VeryComplicatedObject(.....);
log(object.toPrettier())

final someVeryComplicatedString = '{..., ..., ...}'
log(someVeryComplicatedString.toPrettier())

Examples🌏 #

Equatable model

class Dog extends Equatable {
  const Dog({
    required this.hasTail,
    required this.age,
    required this.parents,
    required this.friend,
  });

  final bool hasTail;
  final int age;
  final List<Dog> parents;
  final Dog? friend;

  @override
  List<Object?> get props => [hasTail, age, parents, friend];
}
with toString() {#equatable-toString}
Dog(true, 10, [Dog(true, 100, [], null), Dog(true, 100, [], null)], Dog(true, 100, [], null))
with toPrettier() {#equatable-toPrettier}
Dog(
  true,
  10,
  [
    Dog(
      true,
      100,
      [],
      null
    ),
    Dog(
      true,
      100,
      [],
      null
    )
  ],
  Dog(
    true,
    100,
    [],
    null
  )
)

Freezed model {#freezed-model}

@freezed
class Member with _$Member {
  const factory Member({
    required int id,
    required String name,
    required List<Member> friends,
  }) = _Member;

  const Member._();
}
with toString()
Member(id: 1, name: John, friends: [Member(id: 10, name: Amy, friends: []), Member(id: 30, name: Barth, friends: []), Member(id: 50, name: Irene, friends: [])])
with toPrettier()
Member(
  id: 1,
  name: John,
  friends: [
    Member(
      id: 10,
      name: Amy,
      friends: []
    ),
    Member(
      id: 30,
      name: Barth,
      friends: []
    ),
    Member(
      id: 50,
      name: Irene,
      friends: []
    )
  ]
)

Advanced #

Custom

  • .toPrettier() has a following defaults. If you want to change the behavior, pass it as a argument.
/// Changes intent width or characters.
String indent = '  ',
/// Needed to use a special separators instead of ','
List<String> separators = const <String>[','],
/// Needed to use brackets rather than followings
Map<String, String> brackets = const {
  '{': '}',
  '[': ']',
  '(': ')',
},

Contribute🤖 #

  • Feel free to open pull request to improve this project!

Running Tests 🧪 #

To run all unit tests:

very_good test --coverage
14
likes
0
pub points
61%
popularity

Publisher

unverified uploader

A tool to convert ugly toString() generated by such as Equatable or Freezed to be prettier.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on pretty_string