5

in this below code when i try to set value to ValueNotifier i get the analysis info,

info: Use a setter for operations that conceptually change a property. (use_setters_to_change_properties at 
[XXXXX] lib\service\providers\value_notifier_scroll_to_selected_page_position.dart:6) 

my code:

class ScrollToSelectedPagePosition {
  final ValueNotifier<int> position = ValueNotifier<int>(0);

  void scrollToPosition(int selectedPagePosition){
    position.value = selectedPagePosition; // <--- Getting info here
  }
}

how can i define setter for that?

DolDurma
  • 15,753
  • 51
  • 198
  • 377

1 Answers1

3

I guess it wants you to do:

set scrollToPosition(int selectedPagePosition) {
  position.value = selectedPagePosition;
}

and then callers would use scrollToPosition = position instead of scrollToPosition(position).

Assuming that scrollToPosition() performs some scrolling action, personally I prefer it looking like a function call, and I'd suppress the lint with

// ignore: use_setters_to_change_properties

(However, if it were named position, a setter might be more fitting.)

jamesdlin
  • 81,374
  • 13
  • 159
  • 204