You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I'm using the functional_ref lint as a codemod to Rivepod v2.6.0, but it only works sometimes.
It often corrupts large files (the repro below), but also the message is wrong,1 and it always imports "package:riverpod" (once per fix when fix-all-ing!) even if only "package:hooks_riverpod" is in my dependencies.
It doesn't corrupt it using fix-all in the editor, but the other issues still trigger.
To Reproduce
(I picked a smallish file, I tried to minimize it a bit but it seems to be size-dependent)
Before
/// This library contains the authentication feature's business logic.library;
import"dart:typed_data";
import"package:riverpod_annotation/riverpod_annotation.dart";
import"../data/auth_repository.dart";
import"../domain/account_type.dart";
import"../domain/pirate_auth_model.dart";
import"../domain/pirate_user_entity.dart";
part"auth_service.g.dart";
/// Get the current user.@Riverpod(keepAlive:true)
baseclassPirateAuthServiceextends_$PirateAuthService {
@overrideFutureOr<PirateAuthModel> build() async {
return_createSession(anonymous:true);
}
/// Authenticate the current user.Future<void> authenticate() async {
state =awaitAsyncValue.guard(_createSession);
}
Future<PirateAuthModel> _createSession({bool anonymous =false}) async {
final auth = ref.read(authProvider);
final account =await auth.authenticate(anonymous: anonymous);
returnPirateAuthModel(
user: account,
);
}
/// Create a new anonymous session for the user.Future<void> anonymous() async {
state =awaitAsyncValue.guard(() =>_createSession(anonymous:true));
}
}
/// Get the current user with minimal fuss.////// Use [pirateAuthServiceProvider] for more granular output.@Riverpod(keepAlive:true)
Future<PirateUserEntity> user(UserRef ref) async=>await ref.watch(
pirateAuthServiceProvider.selectAsync((value) => value.user),
);
/// Get the current user's name.////// Named as such to prevent a naming conflict with riverpod.@riverpodFuture<String> username(UsernameRef ref) async=>await ref.watch(userProvider.selectAsync((value) => value.name));
/// Get the current user's email address.@riverpodFuture<String> email(EmailRef ref) async=>await ref.watch(userProvider.selectAsync((value) => value.email));
/// Get the current user's avatar.@riverpodFuture<Uint8List> avatar(AvatarRef ref) async=>await ref.watch(userProvider.selectAsync((value) => value.avatar));
/// Get the current user's account type.@riverpodFuture<AccountType> accountType(AccountTypeRef ref) async=>await ref.watch(userProvider.selectAsync((value) => value.accountType));
/// Get the current user's ID.@riverpodFuture<int> id(IdRef ref) async=>await ref.watch(userProvider.selectAsync((value) => value.id));
After
/// This library contains the authentication feature's business logic.
library;
import "dart:typed_data";
import "package:riverpod/riverpod.dart";
import "package:riverpod/riverpod.dart";
import "package:riverpod/riverpod.dart";
import "package:riverpod/riverpod.dart";
import "package:riverpod/riverpod.dart";
import "package:riverpod/riverpod.dart";
import "package:riverpod_annotation/riverpod_annotation.dart";
import "../data/auth_repository.dart";
import "../domain/account_type.dart";
import "../domain/pirate_auth_model.dart";
import "../domain/pirate_user_entity.dart";
part "auth_service.g.dart";
/// Get the current user.
@Riverpod(keepAlive: true)
base class PirateAuthService extends _$PirateAuthService {
@override
FutureOr<PirateAuthModel> build() async {
return _createSession(anonymous: true);
}
/// Authenticate the current user.
Future<void> authenticate() async {
state = await AsyncValue.guard(_createSession);
}
Future<PirateAuthModel> _createSession({bool anonymous = false}) async {
final auth = ref.read(authProvider);
final account = await auth.authenticate(anonymous: anonymous);
return PirateAuthModel(
user: account,
);
}
/// Create a new anonymous session for the user.
Future<void> anonymous() async {
state = await AsyncValue.guard(() => _crRef ion(anonymous: true));
}
}
/// Get the current user with minimal fuss.
///
/// Use [pirateAuthServiceProvider] for more granular output.
@Riverpod(keepAlive: true)
Future<PirateUserEntity> user(UserRef ref) async => await ref.watch(
pirateAuthServiceProvider.selectAsync((Ref lue.user),
);
/// Get the current user's name.
///
/// Named as such to prevent a naming conflict with riverpod.
@riverpod
Future<String> username(UsernameRef ref) async =>
await ref.watch(uRef er.selectAsync((value) => value.name));
/// Get the current user's email address.
@riverpod
Future<String> email(EmailRef ref) async =>
await ref.watch(userProvider.selectAsync((value) => valuRef
/// Get the current user's avatar.
@riverpod
Future<Uint8List> avatar(AvatarRef ref) async =>
await ref.watch(userProvider.selectAsync((value) => value.avatar));
/// Get the current user's account type.
@Ref <AccountType> accountType(AccountTypeRef ref) async =>
await ref.watch(userProvider.selectAsync((value) => value.accountType));
/// Get the current user's ID.
@riverpod
Future<int> id(Ref ref) async =>
await ref.watch(userProvider.selectAsync((value) => value.id));
Diff
diff --git a/lib/features/auth/application/auth_service.dart b/lib/features/auth/application/auth_service.dart
index 6f8355d..f3a934a 100644
--- a/lib/features/auth/application/auth_service.dart+++ b/lib/features/auth/application/auth_service.dart@@ -3,6 +3,12 @@ library;
import "dart:typed_data";
+import "package:riverpod/riverpod.dart";+import "package:riverpod/riverpod.dart";+import "package:riverpod/riverpod.dart";+import "package:riverpod/riverpod.dart";+import "package:riverpod/riverpod.dart";+import "package:riverpod/riverpod.dart";
import "package:riverpod_annotation/riverpod_annotation.dart";
import "../data/auth_repository.dart";
@@ -36,7 +42,7 @@ base class PirateAuthService extends _$PirateAuthService {
/// Create a new anonymous session for the user.
Future<void> anonymous() async {
- state = await AsyncValue.guard(() => _createSession(anonymous: true));+ state = await AsyncValue.guard(() => _crRef ion(anonymous: true));
}
}
@@ -45,7 +51,7 @@ base class PirateAuthService extends _$PirateAuthService {
/// Use [pirateAuthServiceProvider] for more granular output.
@Riverpod(keepAlive: true)
Future<PirateUserEntity> user(UserRef ref) async => await ref.watch(
- pirateAuthServiceProvider.selectAsync((value) => value.user),+ pirateAuthServiceProvider.selectAsync((Ref lue.user),
);
/// Get the current user's name.
@@ -53,12 +59,12 @@ Future<PirateUserEntity> user(UserRef ref) async => await ref.watch(
/// Named as such to prevent a naming conflict with riverpod.
@riverpod
Future<String> username(UsernameRef ref) async =>
- await ref.watch(userProvider.selectAsync((value) => value.name));+ await ref.watch(uRef er.selectAsync((value) => value.name));
/// Get the current user's email address.
@riverpod
Future<String> email(EmailRef ref) async =>
- await ref.watch(userProvider.selectAsync((value) => value.email));+ await ref.watch(userProvider.selectAsync((value) => valuRef
/// Get the current user's avatar.
@riverpod
@@ -66,11 +72,10 @@ Future<Uint8List> avatar(AvatarRef ref) async =>
await ref.watch(userProvider.selectAsync((value) => value.avatar));
/// Get the current user's account type.
-@riverpod-Future<AccountType> accountType(AccountTypeRef ref) async =>+@Ref <AccountType> accountType(AccountTypeRef ref) async =>
await ref.watch(userProvider.selectAsync((value) => value.accountType));
/// Get the current user's ID.
@riverpod
-Future<int> id(IdRef ref) async =>+Future<int> id(Ref ref) async =>
await ref.watch(userProvider.selectAsync((value) => value.id));
Expected behavior
It'd work fine.
Footnotes
"Functional providers must receive a ref matching the provider name as their first positional parameter." (Not anymore) ↩
The text was updated successfully, but these errors were encountered:
Describe the bug
I'm using the
functional_ref
lint as a codemod to Rivepod v2.6.0, but it only works sometimes.It often corrupts large files (the repro below), but also the message is wrong,1 and it always imports "package:riverpod" (once per fix when fix-all-ing!) even if only "package:hooks_riverpod" is in my dependencies.
It doesn't corrupt it using fix-all in the editor, but the other issues still trigger.
To Reproduce
(I picked a smallish file, I tried to minimize it a bit but it seems to be size-dependent)
Before
After
Diff
Expected behavior
It'd work fine.
Footnotes
"Functional providers must receive a ref matching the provider name as their first positional parameter." (Not anymore) ↩
The text was updated successfully, but these errors were encountered: