felangel / bloc

A predictable state management library that helps implement the BLoC design pattern
https://bloclibrary.dev
MIT License
11.76k stars 3.39k forks source link

style: Move the "props" getter to the parent (sealed) class #4186

Closed warioddly closed 3 months ago

warioddly commented 3 months ago

Description

Hello everyone, I have a question why in the plugin in jetbrains in which we have snippets using Equatable, if we create a new Event or State, we must and must use the props property, since in many cases I do not need it, but only in some parts. and most importantly, why don't we put it in the parent class (sealed class) of the props property, and we don't need to inherit it, but we will inherit only in the right places.

felangel commented 3 months ago

This was done intentionally so you don't forget to specify the props in subclasses. It's very easy to forget to update props otherwise for example:

class MyBase extends Equatable {
  @override
  List<Object> get props => [];
}

class MySub extends MyBase {
  const MySub(this.value);
  final String value;
}

The above example will not behave correctly because props for MySub does not include value. Hope that helps 👍