Skip to content

Commit

Permalink
introduce AvatarOptions for simplifying APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
gtalha07 committed May 1, 2024
1 parent 29ecf75 commit a90c04c
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/src/models/avatar_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:acter_avatar/acter_avatar.dart';

/// Abstract class representing the set of avatars.
abstract class AvatarOptions {
AvatarInfo? get avatar;
List<AvatarInfo>? get parentAvatars;
double? get size;
double? get parentSize;
}
21 changes: 21 additions & 0 deletions lib/src/models/dm_avatar_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:acter_avatar/src/models/avatar_info.dart';
import 'package:acter_avatar/src/models/avatar_options.dart';

/// Class representing avatar for Direct Message/Private Chat (DM).
class DMAvatarOptions extends AvatarOptions {
DMAvatarOptions({required this.dmAvatar, this.avatarSize});
@override
AvatarInfo get avatar => dmAvatar;

@override
List<AvatarInfo>? get parentAvatars => null;

@override
double? get size => avatarSize ?? 24.0;

@override
double? get parentSize => null;

final AvatarInfo dmAvatar;
final double? avatarSize;
}
29 changes: 29 additions & 0 deletions lib/src/models/group_chat_avatar_option.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:acter_avatar/src/models/avatar_info.dart';
import 'package:acter_avatar/src/models/avatar_options.dart';

/// Class representing set of avatars for group chat/room.
class GroupChatAvatarOptions extends AvatarOptions {
GroupChatAvatarOptions({
required this.groupAvatar,
required this.parentGroupAvatars,
this.avatarSize,
this.parentAvatarSize,
});

@override
AvatarInfo? get avatar => groupAvatar;

@override
List<AvatarInfo>? get parentAvatars => parentGroupAvatars;

@override
double? get size => avatarSize ?? 48.0;

@override
double? get parentSize => parentAvatarSize ?? 24.0;

final AvatarInfo groupAvatar;
final List<AvatarInfo> parentGroupAvatars;
final double? avatarSize;
final double? parentAvatarSize;
}
27 changes: 27 additions & 0 deletions lib/src/models/group_dm_avatar_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:acter_avatar/src/models/avatar_info.dart';
import 'package:acter_avatar/src/models/avatar_options.dart';

/// Class representing set of avatars for a group DM.
class GroupDMAvatarOptions extends AvatarOptions {
GroupDMAvatarOptions({
required this.groupAvatars,
this.avatarSize,
this.parentAvatarSize,
});

@override
AvatarInfo? get avatar => null;

@override
List<AvatarInfo> get parentAvatars => groupAvatars;

@override
double? get size => avatarSize ?? 48.0;

@override
double? get parentSize => parentAvatarSize ?? 24.0;

final List<AvatarInfo> groupAvatars;
final double? avatarSize;
final double? parentAvatarSize;
}
25 changes: 25 additions & 0 deletions lib/src/models/space_avatar_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:acter_avatar/src/models/avatar_info.dart';
import 'package:acter_avatar/src/models/avatar_options.dart';

/// Class representing set of avatars for a space.
class SpaceAvatarOptions extends AvatarOptions {
SpaceAvatarOptions(this.avatarSize, this.parentAvatarSize,
{required this.spaceAvatar, this.parentSpaceAvatars});

@override
AvatarInfo get avatar => spaceAvatar;

@override
List<AvatarInfo>? get parentAvatars => parentSpaceAvatars;

@override
double? get size => avatarSize ?? 48.0;

@override
double? get parentSize => parentAvatarSize ?? 24.0;

final AvatarInfo spaceAvatar;
final List<AvatarInfo>? parentSpaceAvatars;
final double? avatarSize;
final double? parentAvatarSize;
}

0 comments on commit a90c04c

Please sign in to comment.