-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fefa70
commit 4b21269
Showing
6 changed files
with
128 additions
and
85 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
packages/app/lib/src/features/home/application/avatar_service.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
import '../data/avatar_repository.dart'; | ||
|
||
part 'avatar_service.g.dart'; | ||
|
||
/// Get the user's avatar. | ||
@riverpod | ||
FutureOr<Uint8List> avatarService(AvatarServiceRef ref, [String? name]) { | ||
final avatarRepo = ref.watch(avatarProvider); | ||
|
||
return avatarRepo.getAvatar(name: name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/app/lib/src/features/home/data/avatar_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// This library contains the authentication feature's avatar data fetchers. | ||
library; | ||
|
||
import 'dart:typed_data'; | ||
|
||
import 'package:appwrite/appwrite.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
import '../../../utils/api.dart'; | ||
|
||
part 'avatar_repository.g.dart'; | ||
|
||
/// A repository for getting avatars. | ||
abstract interface class AvatarRepository { | ||
/// Get the avatar for the current user. | ||
Future<Uint8List> getAvatar({String? name}); | ||
} | ||
|
||
/// The default implementation of [AvatarRepository]. | ||
base class _AppwriteAvatarRepository implements AvatarRepository { | ||
/// Create a new instance of [_AppwriteAvatarRepository]. | ||
const _AppwriteAvatarRepository(Avatars avatars) : _avatars = avatars; | ||
|
||
final Avatars _avatars; | ||
|
||
@override | ||
Future<Uint8List> getAvatar({String? name}) => | ||
_avatars.getInitials(name: name); | ||
} | ||
|
||
/// Get the current user's avatar. | ||
@Riverpod(keepAlive: true) | ||
AvatarRepository avatar(AvatarRef ref) { | ||
final avatars = ref.watch(avatarsProvider); | ||
|
||
return _AppwriteAvatarRepository(avatars); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters