riverpod icon indicating copy to clipboard operation
riverpod copied to clipboard

Allow creating public Providers with private functions/classes

Open esenmx opened this issue 6 months ago • 1 comments

Is your feature request related to a problem? Please describe. Right now, providers created as:

/// public provider
@riverpod
Controller controller(ControllerRef ref) {
  return Controller();
}

/// private provider
@riverpod
Controller _controller(ControllerRef ref) {
  return Controller();
}

Since these functions are only used in their generated file, it doesn't make any sense to expose them publicly, and there is always a auto-completion overlap between the provider and the underlying function.

Describe the solution you'd like This way we will have more flexibility:

/// public provider with public function
@riverpod
Controller controller(ControllerRef ref) {
  return Controller();
}

/// public provider with private function
@riverpod
Controller _controller(ControllerRef ref) {
  return Controller();
}

/// private provider with private function
@riverpod
Controller __controller(ControllerRef ref) {
  return Controller();
}

Describe alternatives you've considered @riverpod annotation can include a feature for preventing IDE indexing for suggestions(similarly what @visibleForTesting or @internal do at package level).

Additional context functional_widget has this feature and it provides that flexibility with no drawback.

esenmx avatar Dec 24 '23 04:12 esenmx