bizz84 / bizz84/async_notifier_example_riverpod

Question

Open
#1 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
32
Forks
7
PR merge metrics
No merged PRs in 30d

Description

One struggle I have with this new approach and Riverpod in general is the proliferation of providers. It may be my misunderstanding of the library but if FutureOr build() is void then is it true that all methods in the controller must return void as well if you want to use state?

@riverpod
class AuthController extends _$AuthController {
@override
FutureOr build() {
// return a value (or do nothing if the return type is void)
}

Future signInAnonymously() async {
final authRepository = ref.read(authRepositoryProvider);
state = const AsyncLoading();
state = await AsyncValue.guard(authRepository.signInAnonymously);
}

Future signOut() async {
final authRepository = ref.read(authRepositoryProvider);
state = const AsyncLoading();
state = await AsyncValue.guard(authRepository.signOut);
}

I'm new to Riverpod and Flutter in general but if I want to create a controller that encapsulates a class (Project) and all it's related methods like so that may return different types. How to accommodate w/out creating a bunch of providers?

`
part 'project_controller.g.dart';

@riverpod
class ProjectController extends _$ProjectController {
late String? _projectId = null;
late ProjectView? _projectView = null;
late List _projectContactView;

String? get ProjectId => _projectId;
ProjectView? get ProjectRecord => _projectView;
List get Contacts => _projectContactView;

@override
FutureOr build() async {
}

Future getProject({required String ProjectId}) async {
_projectId = ProjectId;
final projectsRepository = ref.read(projectsRepositoryProvider);
state = const AsyncLoading();
_projectView =
await projectsRepository.queryProjectDetails(id: _projectId!);

state = AsyncData(_projectView );
}

Future?> getProjectContacts() async {
final projectsRepository = ref.read(projectsRepositoryProvider);
state = const AsyncLoading();
_projectContactView =
await projectsRepository.queryProjectContacts(id: _projectId!);

state = AsyncData(_projectContactView);
}
}
`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.