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

Operator overloading #1135

Closed
jimmyff opened this issue Nov 21, 2024 · 1 comment
Closed

Operator overloading #1135

jimmyff opened this issue Nov 21, 2024 · 1 comment
Assignees
Labels
bug Something isn't working needs triage

Comments

@jimmyff
Copy link

jimmyff commented Nov 21, 2024

Having difficulties figuring out how to add artihmetic operators to a freezed class. See below:

@freezed
class ImageOffset with _$ImageSize {
  const ImageOffset._();
  const factory ImageOffset({
    required double dx,
    required double dy,
  }) = _ImageOffset;

  factory ImageOffset.fromJson(Map<String, Object?> json) =>
      _$ImageOffsetFromJson(json);

  static ImageOffset get zero => const ImageOffset(dx: 0, dy: 0);

  // Problematic code
  @override
  ImageOffset operator +(covariant ImageOffset other) =>
      ImageOffset(dx: this.dx + other.dx, dy: this.dy + other.dy);
}

Gives the following errors:

[{

	"owner": "_generated_diagnostic_collection_name_#5",
	"code": {
		"value": "undefined_getter",
		"target": {
			"$mid": 1,
			"path": "/diagnostics/undefined_getter",
			"scheme": "https",
			"authority": "dart.dev"
		}
	},
	"severity": 8,
	"message": "The getter 'dx' isn't defined for the type 'ImageOffset'.\nTry importing the library that defines 'dx', correcting the name to the name of an existing getter, or defining a getter or field named 'dx'.",
	"source": "dart",
	"startLineNumber": 170,
	"startColumn": 28,
	"endLineNumber": 170,
	"endColumn": 30
},{
	"owner": "_generated_diagnostic_collection_name_#5",
	"code": {
		"value": "undefined_getter",
		"target": {
			"$mid": 1,
			"path": "/diagnostics/undefined_getter",
			"scheme": "https",
			"authority": "dart.dev"
		}
	},
	"severity": 8,
	"message": "The getter 'dx' isn't defined for the type 'ImageOffset'.\nTry importing the library that defines 'dx', correcting the name to the name of an existing getter, or defining a getter or field named 'dx'.",
	"source": "dart",
	"startLineNumber": 170,
	"startColumn": 39,
	"endLineNumber": 170,
	"endColumn": 41
},{
	"owner": "_generated_diagnostic_collection_name_#5",
	"code": {
		"value": "undefined_getter",
		"target": {
			"$mid": 1,
			"path": "/diagnostics/undefined_getter",
			"scheme": "https",
			"authority": "dart.dev"
		}
	},
	"severity": 8,
	"message": "The getter 'dy' isn't defined for the type 'ImageOffset'.\nTry importing the library that defines 'dy', correcting the name to the name of an existing getter, or defining a getter or field named 'dy'.",
	"source": "dart",
	"startLineNumber": 170,
	"startColumn": 52,
	"endLineNumber": 170,
	"endColumn": 54
},{
	"owner": "_generated_diagnostic_collection_name_#5",
	"code": {
		"value": "undefined_getter",
		"target": {
			"$mid": 1,
			"path": "/diagnostics/undefined_getter",
			"scheme": "https",
			"authority": "dart.dev"
		}
	},
	"severity": 8,
	"message": "The getter 'dy' isn't defined for the type 'ImageOffset'.\nTry importing the library that defines 'dy', correcting the name to the name of an existing getter, or defining a getter or field named 'dy'.",
	"source": "dart",
	"startLineNumber": 170,
	"startColumn": 63,
	"endLineNumber": 170,
	"endColumn": 65
}]

Thanks

@jimmyff jimmyff added bug Something isn't working needs triage labels Nov 21, 2024
@jimmyff
Copy link
Author

jimmyff commented Nov 21, 2024

My bad, typo in with - wrong class part!

@jimmyff jimmyff closed this as completed Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants