Skip to content

Instantly share code, notes, and snippets.

@riscait
Last active February 3, 2023 01:36
Show Gist options
  • Save riscait/64bdbff28d010c8313da71df1c75ba15 to your computer and use it in GitHub Desktop.
Save riscait/64bdbff28d010c8313da71df1c75ba15 to your computer and use it in GitHub Desktop.
// Definition
@Riverpod(keepAlive: true)
_RefreshToken refreshToken(RefreshTokenRef ref) => _RefreshToken(ref);
class _RefreshToken {
const _RefreshToken(this.ref);
final Ref ref;
Future<RefreshTokenResponse> call({
required RefreshTokenBody body,
}) async {
final client = ref.watch(restClientProvider);
final response = await client.refreshToken(body);
return response.data;
}
}
/// call
Future<void> callToSingleProvider() async {
final container = ProviderContainer();
const body = RefreshTokenBody(userId: 'USER_001');
final response = await container.read(refreshTokenProvider)(body: body);
print(response);
}
// Definition
@Riverpod(keepAlive: true)
Future<RefreshTokenResponse> Function({
required RefreshTokenBody body,
}) refreshToken(
RefreshTokenRef ref,
) =>
({required body}) async {
final client = ref.watch(restClientProvider);
final response = await client.refreshToken(body);
return response.data;
};
/// call
Future<void> callToSingleProvider() async {
final container = ProviderContainer();
const body = RefreshTokenBody(userId: 'USER_001');
final response = await container.read(refreshTokenProvider)(body: body);
print(response);
}
/// call
Future<void> callDirectRestClient() async {
final container = ProviderContainer();
const body = RefreshTokenBody(userId: 'USER_001');
final response =
await container.read(favomatchRestClientProvider).refreshToken(body);
print(response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment