Freezed: Does this is a valid usage of Freezed?

Created on 14 May 2020  Â·  13Comments  Â·  Source: rrousselGit/freezed

I have the following class:

@freezed
abstract class Transaction with _$Transaction implements Entity {
  const factory Transaction({
    @required UniqueId id,
    @required Money amount,
    @required PhoneNumber phoneNumber,
  }) = _Transaction;

  String getMaskedPhoneNumber() {
    return RegExpUtil.replaceAndKeepLastThreeDigits(phoneNumber.getOrElse(''));
  }
}

Is this a valid usage of Freezed? I'm receiving the following error (at compile time):

Compiler message:
lib/src/domain/transactions/entities/transaction.freezed.dart:35:7: Error: The non-abstract class '_$_Transaction' is missing implementations for these members:
 - Transaction.getMaskedPhoneNumber
Try to either
 - provide an implementation,
 - inherit an implementation from a superclass or mixin,
 - mark the class as abstract, or
 - provide a 'noSuchMethod' implementation.

class _$_Transaction implements _Transaction {
      ^^^^^^^^^^^^^^
lib/src/domain/transactions/entities/transaction.dart:23:10: Context: 'Transaction.getMaskedPhoneNumber' is defined here.
  String getMaskedPhoneNumber() {
         ^^^^^^^^^^^^^^^^^^^^

Compiler message:
lib/src/domain/transactions/entities/transaction.freezed.dart:35:7: Error: The non-abstract class '_$_Transaction' is missing implementations for these members:
 - Transaction.getMaskedPhoneNumber
Try to either
 - provide an implementation,
 - inherit an implementation from a superclass or mixin,
 - mark the class as abstract, or
 - provide a 'noSuchMethod' implementation.

class _$_Transaction implements _Transaction {
      ^^^^^^^^^^^^^^
lib/src/domain/transactions/entities/transaction.dart:23:10: Context: 'Transaction.getMaskedPhoneNumber' is defined here.
  String getMaskedPhoneNumber() {
         ^^^^^^^^^^^^^^^^^^^^
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.

FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 882

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 23s
Exception: Gradle task assembleDebug failed with exit code 1

question

All 13 comments

Currently fixed it by adding the method in a extension of my class:

extension TransactionExt on Transaction {
  String getMaskedPhoneNumber() {
    return RegExpUtil.replaceAndKeepLastThreeDigits(phoneNumber.getOrElse(''));
  }
}

The problem and solution is explained in the README here:
https://github.com/rrousselGit/freezed#custom-getters-and-methods

If there is something that you do not understand, feel free to let me know,
so that I can update the readme :)

Le jeu. 14 mai 2020 à 13:24, Pedro Massango notifications@github.com a
écrit :

Currently fixed it by adding the method in a extension of my class:

extension TransactionExt on Transaction {
String getMaskedPhoneNumber() {
return RegExpUtil.replaceAndKeepLastThreeDigits(phoneNumber.getOrElse(''));
}
}

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/rrousselGit/freezed/issues/171#issuecomment-628598862,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AEZ3I3J5KACPIUIGL5V5C7LRRPPIBANCNFSM4NAUMNKA
.

I've updated as follow:


part 'transaction.freezed.dart';

@freezed
abstract class Transaction implements _$Transaction {
  const factory Transaction({
    @required UniqueId id,
    @required Money amount,
    @required PhoneNumber phoneNumber,
  }) = _Transaction;

  String getMaskedPhoneNumber() {
    return RegExpUtil.replaceAndKeepLastThreeDigits(phoneNumber.getOrElse(''));
  }
}

but I keep receiving the error

You are missing on the Transaction._(); constructor

On Thu, 14 May 2020, 15:30 Pedro Massango, notifications@github.com wrote:

I've updated as follow:

part 'transaction.freezed.dart';

@freezed
abstract class Transaction implements _$Transaction {
const factory Transaction({
@required UniqueId id,
@required Money amount,
@required PhoneNumber phoneNumber,
}) = _Transaction;

String getMaskedPhoneNumber() {
return RegExpUtil.replaceAndKeepLastThreeDigits(phoneNumber.getOrElse(''));
}
}

but I keep receiving the error

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/rrousselGit/freezed/issues/171#issuecomment-628673815,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AEZ3I3INEMMZ2U27DC6MOZ3RRP57PANCNFSM4NAUMNKA
.

Sorry, I copied the wrong code, please take a look at the image

image

Have you re-generated your source code?

You should have class _$_Transaction extends _Transaction instead

Le jeu. 14 mai 2020 à 15:39, Pedro Massango notifications@github.com a
écrit :

Sorry, I copied the wrong code, please take a look at the image

[image: image]
https://user-images.githubusercontent.com/33294549/81947920-04e91180-95f9-11ea-856a-4909166adf8a.png

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/rrousselGit/freezed/issues/171#issuecomment-628679307,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AEZ3I3K2VKCRCG5DZE7SSPDRRP7CLANCNFSM4NAUMNKA
.

Yes. I also deleted the previus geerated files

Do you still have the problem?

Do you still have the problem?

Let me try it tomorrow

So is this working?

So is this working?

It does not work, am I missing something?

Here is my packages version:

freezed: ^0.9.2
freezed_annotation: ^0.7.1

Freezed in on version 10

Freezed in on version 10

Wow, I was using a realy old version. It works now. Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

linhdogg picture linhdogg  Â·  4Comments

orestesgaolin picture orestesgaolin  Â·  6Comments

samandmoore picture samandmoore  Â·  4Comments

narcodico picture narcodico  Â·  6Comments

pblinux picture pblinux  Â·  4Comments