-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationneeds triage
Description
Sometimes there are a couple of providers that work together to achieve a function.
For example:
final registrationButtonEnabledProvider = Provider.autoDispose<bool>((ref) {
var email = ref.watch(registrationEmailStateProvider).state;
var password = ref.watch(registrationPasswordStateProvider).state;
var passwordConfirm = ref.watch(registrationPasswordConfirmStateProvider).state;
if(email.isEmpty || password.isEmpty || passwordConfirm.isEmpty) {
return false;
}
if(!PasswordValidator.checkPassword(password).conformsToRequirements) {
return false;
}
return ref.watch(registrationStateNotifierProvider).canRegister;
});
/// The [StateProvider] to set the email state
///
/// This is supposed to be only used by the [RegistrationPage]
final registrationEmailStateProvider = StateProvider.autoDispose<String>((ref) {
return '';
});
/// The [StateProvider] to set the password state
///
/// This is supposed to be only used by the [RegistrationPage]
final registrationPasswordStateProvider = StateProvider.autoDispose<String>((ref) {
return '';
});
/// The [StateProvider] to set the password confirm state
///
/// This is supposed to be only used by the [RegistrationPage]
final registrationPasswordConfirmStateProvider = StateProvider.autoDispose<String>((ref) {
return '';
});handles TextFields and whether to enable the register button. These are only meant to be used by one class.
If I create a lot of such providers, my concern is that it might convolute the global namespace and make API discovery harder when the project grows.
I was thinking of putting these in a static class, purely for the sake of namespace.
class RegistrationForm {
static final registrationButtonEnabledProvider = Provider.autoDispose<bool>((ref) {
var email = ref.watch(registrationEmailStateProvider).state;
var password = ref.watch(registrationPasswordStateProvider).state;
var passwordConfirm = ref.watch(registrationPasswordConfirmStateProvider).state;
if(email.isEmpty || password.isEmpty || passwordConfirm.isEmpty) {
return false;
}
if(!PasswordValidator.checkPassword(password).conformsToRequirements) {
return false;
}
return ref.watch(registrationStateNotifierProvider).canRegister;
});
/// The [StateProvider] to set the email state
///
/// This is supposed to be only used by the [RegistrationPage]
static final registrationEmailStateProvider = StateProvider.autoDispose<String>((ref) {
return '';
});
/// The [StateProvider] to set the password state
///
/// This is supposed to be only used by the [RegistrationPage]
static final registrationPasswordStateProvider = StateProvider.autoDispose<String>((ref) {
return '';
});
/// The [StateProvider] to set the password confirm state
///
/// This is supposed to be only used by the [RegistrationPage]
static final registrationPasswordConfirmStateProvider = StateProvider.autoDispose<String>((ref) {
return '';
});
}I haven't seen this done yet, and I'd love to hear opinions.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationneeds triage