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

must_be_immutable and Mock #200

Open
vitor-gyant opened this issue Jul 15, 2019 · 3 comments
Open

must_be_immutable and Mock #200

vitor-gyant opened this issue Jul 15, 2019 · 3 comments
Labels
P2 A bug or feature request we're likely to work on S2 type-enhancement A request for a change that isn't a bug

Comments

@vitor-gyant
Copy link

Hi,

With the latest flutter version from master I'm seeing this lint errors:

This class (or a class which this class inherits from) is marked as '@immutable', but one or more of its instance fields are not final: Mock._givenName, Mock._givenHashCode, Mock._defaultResponsedart(must_be_immutable)

These are the classes involved here. Equatable is also marked with immutable macro.

class MockWrongTypeChatWidgetModel extends Mock implements ChatWidgetModel {}

abstract class ChatWidgetModel extends Equatable {
  /// Identifies the type of widget.
  ChatWidgetModelType get type;

  /// Unique identifier that allows to identify which models are added/removed.
  String get id;

  /// Boolean that indicates if the model was sent
  /// from the server or the client.
  bool get incoming;

  /// Boolean that indicates if the user could undo the previous response.
  bool get undoable;

  /// Returns one of [ChatWidgetInputType].
  ///
  /// Default implementation returns [ChatWidgetModelInputType.none].
  ChatWidgetModelInputType get inputType => ChatWidgetModelInputType.none;

  /// [Equatable] helper that retrieves the fields that will be used to compare.
  Iterable get equatableFields;

  @override
  List get props =>
      [id, type, incoming, undoable, inputType]..addAll(equatableFields);
}
@srawlins
Copy link
Member

I agree the Mock class should more-or-less be immutable. This will fit with some planned upcoming work.

For now, you should be able to ignore the Hint in your tests:

// ignore: must_be_immutable
class MockWrongTypeChatWidgetModel extends Mock implements ChatWidgetModel {}

@srawlins srawlins added P2 A bug or feature request we're likely to work on S2 type-enhancement A request for a change that isn't a bug labels Jul 16, 2019
@vitor-gyant
Copy link
Author

@srawlins Great. Thanks!

auto-submit bot pushed a commit to flutter/packages that referenced this issue Jul 14, 2023
Marks all Dart-wrapped Android native classes as `@immutable`. They are all immutable anyway because they extend `JavaObject` which is immutable, but marking them as immutable explicitly avoids lint warnings caused by [`must_be_immutable`](https://dart.dev/tools/diagnostic-messages#must_be_immutable) when generated mocks of these classes are used (see dart-lang/mockito#200).

Also, updates `CONTRIBUTING.md` to include marking wrapped classes as immutable and extending `JavaObject` as requirements for adding new wrapped classes.

cc @ChristianEdwardPadilla: this should fix the internal lint errors caused by `JavaObject` being immutable.
@Nikzed
Copy link

Nikzed commented Nov 25, 2023

Will it be fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on S2 type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants