felangel / equatable

A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.

Home Page:https://pub.dev/packages/equatable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Same object, same runtimeType but runtimeType== other.runtimeType is false

itaishalom opened this issue · comments

I encountered a strange issue during my tests.
I'm trying to verify a function call - to my logger:

 verify(() => logger.i(WorkflowButtonClicked(value: true))).called(1);

The test runs, and there is a call:

    logger.i(new WorkflowButtonClicked(value: true));

WorkflowButtonClicked class extends Equatable, but for some reason, the verify is false.
I checked the code on Equatable class and saw that:

 @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is Equatable &&
          runtimeType == other.runtimeType &&
          equals(props, other.props);

and the problem is that runtimeType == other.runtimeType is false,
and I can't understand why, because if the String representation of runtimeType is the same.
I tried overriding the runttimeType:

  Type get runtimeType {
    return WorkflowButtonClicked;
  }

but the "==" was still false;
Don't know how to fix this.

Screen Shot 2022-09-12 at 22 12 41

Hi @itaishalom 👋
Thanks for opening an issue!

Can you please provide a link to a minimal reproduction sample? Thanks!

Hi, I'm not sure if the issue is related directly to Equatable, I think maybe it's in Flutter itself,
what do you think?
Please check the image attached

Ok I found out what happened, the problem was the import:

bad:
import '../models/logger/log_types/workflow_button_clicked.dart';

good:
import 'package:APP/models/logger/log_types/workflow_button_clicked.dart';