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?> _projectContactView;
String? get ProjectId => _projectId;
ProjectView? get ProjectRecord => _projectView;
List<ProjectContactView?> get Contacts => _projectContactView;
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?> _projectContactView;
String? get ProjectId => _projectId; ProjectView? get ProjectRecord => _projectView; List<ProjectContactView?> get Contacts => _projectContactView;
@override FutureOr<String?> build() async { }
Future<ProjectView?> getProject({required String ProjectId}) async { _projectId = ProjectId; final projectsRepository = ref.read(projectsRepositoryProvider); state = const AsyncLoading(); _projectView = await projectsRepository.queryProjectDetails(id: _projectId!);
}
Future<List?> getProjectContacts() async {
final projectsRepository = ref.read(projectsRepositoryProvider);
state = const AsyncLoading();
_projectContactView =
await projectsRepository.queryProjectContacts(id: _projectId!);
} } `