Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to override the toString method with toPrettier of the classes generated by freezed? #2

Open
MiniSuperDev opened this issue Mar 31, 2023 · 2 comments

Comments

@MiniSuperDev
Copy link

When a test reports it uses toString, so it would be great to be able to use toPrettier.

Thank you

import 'package:freezed_annotation/freezed_annotation.dart';

part 'device.freezed.dart';

@freezed
class Device with _$Device {
  const factory Device({
    required String id,
    required String platform,
    required String version,
    required bool isRooted,
  }) = _Device;

  const Device._();
  
    @override
  String toString() {
    // I want this to work, also with union classes, but it don't work
    return toPrettier();
  }
}
@Hwan-seok
Copy link
Owner

Hwan-seok commented Mar 31, 2023

Hi @MiniSuperDev 🤚! Thanks for filling up the issue!
Unfortunately, overriding the toString() of the freezed class is impossible because of their code generation system.

If you want to apply pretty_string to freezed class, you can do it by device.toString().toPrettier().

Sorry for the inconvenience.

@Hwan-seok
Copy link
Owner

Hi @MiniSuperDev ,
Do you bearable if it's available by using mixin?

class Device with _$Device, FreezedPrettier {...}

Device(...).toPrettier() 
instead of 
Device(...).toString()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants