Skip to content

Commit

Permalink
Merge pull request #16 from acterglobal/kumar/parent-badge-click
Browse files Browse the repository at this point in the history
Added click event for parent badges
  • Loading branch information
kumarpalsinh25 authored Aug 21, 2024
2 parents d43adc5 + fb7d02a commit 244fe5a
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 47 deletions.
40 changes: 24 additions & 16 deletions lib/src/acter_avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ class _ActerAvatar extends State<ActerAvatar> {
Widget renderWithAvatar(BuildContext context, ImageProvider avatar) {
return widget.options.when(
// default render .i.e. Group Chat/Space
(avatarInfo, parentBadges, size, badgesSize) =>
_renderDefault(avatar, parentBadges, size, badgesSize),
(avatarInfo, parentBadges, onTapParentBadges, size, badgesSize) =>
_renderDefault(
avatar, parentBadges, onTapParentBadges, size, badgesSize),
// render for DM
DM: (avatarInfo, size) => _renderDM(avatar, size),
// render for Group DM
Expand All @@ -153,6 +154,7 @@ class _ActerAvatar extends State<ActerAvatar> {
Widget _renderDefault(
ImageProvider avatar,
List<AvatarInfo>? badges,
Function()? onTapParentBadges,
double? size,
double? badgesSize,
) {
Expand Down Expand Up @@ -252,26 +254,32 @@ class _ActerAvatar extends State<ActerAvatar> {
List<Widget> children = badges
.getRange(0, thresholdCount)
.map(
(badge) => ActerAvatar(
options: AvatarOptions(badge, size: size),
(badge) => GestureDetector(
onTap: options.onTapParentBadges,
child: ActerAvatar(
options: AvatarOptions(badge, size: size),
),
),
)
.cast<Widget>()
.toList();

if (badgesLength > 3) {
children.add(Container(
width: 10,
height: 10,
alignment: Alignment.center,
decoration: const BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
child: Text(
'+${badgesLength - 3}',
style: const TextStyle(fontSize: 8),
textScaler: TextScaler.linear(0.7),
children.add(GestureDetector(
onTap: options.onTapParentBadges,
child: Container(
width: 10,
height: 10,
alignment: Alignment.center,
decoration: const BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
child: Text(
'+${badgesLength - 3}',
style: const TextStyle(fontSize: 8),
textScaler: TextScaler.linear(0.7),
),
),
));
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/models/avatar_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ abstract class AvatarOptions with _$AvatarOptions {
/// Default usage .i.e. Space/Group Chat. Group avatars will appear as secondary badges.
const factory AvatarOptions(AvatarInfo avatar,
{List<AvatarInfo>? parentBadges,
Function()? onTapParentBadges,
double? size,
double? badgesSize}) = DefaultAvatarOptions;

Expand Down
132 changes: 101 additions & 31 deletions lib/src/models/avatar_options.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ mixin _$AvatarOptions {
double? get size => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function(AvatarInfo avatar, List<AvatarInfo>? parentBadges,
double? size, double? badgesSize)
TResult Function(
AvatarInfo avatar,
List<AvatarInfo>? parentBadges,
dynamic Function()? onTapParentBadges,
double? size,
double? badgesSize)
$default, {
required TResult Function(AvatarInfo avatar, double? size) DM,
required TResult Function(AvatarInfo avatar, List<AvatarInfo>? groupAvatars,
Expand All @@ -31,8 +35,12 @@ mixin _$AvatarOptions {
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function(AvatarInfo avatar, List<AvatarInfo>? parentBadges,
double? size, double? badgesSize)?
TResult? Function(
AvatarInfo avatar,
List<AvatarInfo>? parentBadges,
dynamic Function()? onTapParentBadges,
double? size,
double? badgesSize)?
$default, {
TResult? Function(AvatarInfo avatar, double? size)? DM,
TResult? Function(AvatarInfo avatar, List<AvatarInfo>? groupAvatars,
Expand All @@ -42,8 +50,12 @@ mixin _$AvatarOptions {
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function(AvatarInfo avatar, List<AvatarInfo>? parentBadges,
double? size, double? badgesSize)?
TResult Function(
AvatarInfo avatar,
List<AvatarInfo>? parentBadges,
dynamic Function()? onTapParentBadges,
double? size,
double? badgesSize)?
$default, {
TResult Function(AvatarInfo avatar, double? size)? DM,
TResult Function(AvatarInfo avatar, List<AvatarInfo>? groupAvatars,
Expand Down Expand Up @@ -129,6 +141,7 @@ abstract class _$$DefaultAvatarOptionsImplCopyWith<$Res>
$Res call(
{AvatarInfo avatar,
List<AvatarInfo>? parentBadges,
dynamic Function()? onTapParentBadges,
double? size,
double? badgesSize});
}
Expand All @@ -146,6 +159,7 @@ class __$$DefaultAvatarOptionsImplCopyWithImpl<$Res>
$Res call({
Object? avatar = null,
Object? parentBadges = freezed,
Object? onTapParentBadges = freezed,
Object? size = freezed,
Object? badgesSize = freezed,
}) {
Expand All @@ -158,6 +172,10 @@ class __$$DefaultAvatarOptionsImplCopyWithImpl<$Res>
? _value._parentBadges
: parentBadges // ignore: cast_nullable_to_non_nullable
as List<AvatarInfo>?,
onTapParentBadges: freezed == onTapParentBadges
? _value.onTapParentBadges
: onTapParentBadges // ignore: cast_nullable_to_non_nullable
as dynamic Function()?,
size: freezed == size
? _value.size
: size // ignore: cast_nullable_to_non_nullable
Expand All @@ -174,7 +192,10 @@ class __$$DefaultAvatarOptionsImplCopyWithImpl<$Res>
class _$DefaultAvatarOptionsImpl implements DefaultAvatarOptions {
const _$DefaultAvatarOptionsImpl(this.avatar,
{final List<AvatarInfo>? parentBadges, this.size, this.badgesSize})
{final List<AvatarInfo>? parentBadges,
this.onTapParentBadges,
this.size,
this.badgesSize})
: _parentBadges = parentBadges;

@override
Expand All @@ -189,14 +210,16 @@ class _$DefaultAvatarOptionsImpl implements DefaultAvatarOptions {
return EqualUnmodifiableListView(value);
}

@override
final dynamic Function()? onTapParentBadges;
@override
final double? size;
@override
final double? badgesSize;

@override
String toString() {
return 'AvatarOptions(avatar: $avatar, parentBadges: $parentBadges, size: $size, badgesSize: $badgesSize)';
return 'AvatarOptions(avatar: $avatar, parentBadges: $parentBadges, onTapParentBadges: $onTapParentBadges, size: $size, badgesSize: $badgesSize)';
}

@override
Expand All @@ -207,14 +230,21 @@ class _$DefaultAvatarOptionsImpl implements DefaultAvatarOptions {
(identical(other.avatar, avatar) || other.avatar == avatar) &&
const DeepCollectionEquality()
.equals(other._parentBadges, _parentBadges) &&
(identical(other.onTapParentBadges, onTapParentBadges) ||
other.onTapParentBadges == onTapParentBadges) &&
(identical(other.size, size) || other.size == size) &&
(identical(other.badgesSize, badgesSize) ||
other.badgesSize == badgesSize));
}

@override
int get hashCode => Object.hash(runtimeType, avatar,
const DeepCollectionEquality().hash(_parentBadges), size, badgesSize);
int get hashCode => Object.hash(
runtimeType,
avatar,
const DeepCollectionEquality().hash(_parentBadges),
onTapParentBadges,
size,
badgesSize);

@JsonKey(ignore: true)
@override
Expand All @@ -227,36 +257,49 @@ class _$DefaultAvatarOptionsImpl implements DefaultAvatarOptions {
@override
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function(AvatarInfo avatar, List<AvatarInfo>? parentBadges,
double? size, double? badgesSize)
TResult Function(
AvatarInfo avatar,
List<AvatarInfo>? parentBadges,
dynamic Function()? onTapParentBadges,
double? size,
double? badgesSize)
$default, {
required TResult Function(AvatarInfo avatar, double? size) DM,
required TResult Function(AvatarInfo avatar, List<AvatarInfo>? groupAvatars,
double? size, double? groupAvatarSize)
GroupDM,
}) {
return $default(avatar, parentBadges, size, badgesSize);
return $default(avatar, parentBadges, onTapParentBadges, size, badgesSize);
}

@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function(AvatarInfo avatar, List<AvatarInfo>? parentBadges,
double? size, double? badgesSize)?
TResult? Function(
AvatarInfo avatar,
List<AvatarInfo>? parentBadges,
dynamic Function()? onTapParentBadges,
double? size,
double? badgesSize)?
$default, {
TResult? Function(AvatarInfo avatar, double? size)? DM,
TResult? Function(AvatarInfo avatar, List<AvatarInfo>? groupAvatars,
double? size, double? groupAvatarSize)?
GroupDM,
}) {
return $default?.call(avatar, parentBadges, size, badgesSize);
return $default?.call(
avatar, parentBadges, onTapParentBadges, size, badgesSize);
}

@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function(AvatarInfo avatar, List<AvatarInfo>? parentBadges,
double? size, double? badgesSize)?
TResult Function(
AvatarInfo avatar,
List<AvatarInfo>? parentBadges,
dynamic Function()? onTapParentBadges,
double? size,
double? badgesSize)?
$default, {
TResult Function(AvatarInfo avatar, double? size)? DM,
TResult Function(AvatarInfo avatar, List<AvatarInfo>? groupAvatars,
Expand All @@ -265,7 +308,8 @@ class _$DefaultAvatarOptionsImpl implements DefaultAvatarOptions {
required TResult orElse(),
}) {
if ($default != null) {
return $default(avatar, parentBadges, size, badgesSize);
return $default(
avatar, parentBadges, onTapParentBadges, size, badgesSize);
}
return orElse();
}
Expand Down Expand Up @@ -308,12 +352,14 @@ class _$DefaultAvatarOptionsImpl implements DefaultAvatarOptions {
abstract class DefaultAvatarOptions implements AvatarOptions {
const factory DefaultAvatarOptions(final AvatarInfo avatar,
{final List<AvatarInfo>? parentBadges,
final dynamic Function()? onTapParentBadges,
final double? size,
final double? badgesSize}) = _$DefaultAvatarOptionsImpl;

@override
AvatarInfo get avatar;
List<AvatarInfo>? get parentBadges;
dynamic Function()? get onTapParentBadges;
@override
double? get size;
double? get badgesSize;
Expand Down Expand Up @@ -398,8 +444,12 @@ class _$AvatarOptionsDMImpl implements AvatarOptionsDM {
@override
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function(AvatarInfo avatar, List<AvatarInfo>? parentBadges,
double? size, double? badgesSize)
TResult Function(
AvatarInfo avatar,
List<AvatarInfo>? parentBadges,
dynamic Function()? onTapParentBadges,
double? size,
double? badgesSize)
$default, {
required TResult Function(AvatarInfo avatar, double? size) DM,
required TResult Function(AvatarInfo avatar, List<AvatarInfo>? groupAvatars,
Expand All @@ -412,8 +462,12 @@ class _$AvatarOptionsDMImpl implements AvatarOptionsDM {
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function(AvatarInfo avatar, List<AvatarInfo>? parentBadges,
double? size, double? badgesSize)?
TResult? Function(
AvatarInfo avatar,
List<AvatarInfo>? parentBadges,
dynamic Function()? onTapParentBadges,
double? size,
double? badgesSize)?
$default, {
TResult? Function(AvatarInfo avatar, double? size)? DM,
TResult? Function(AvatarInfo avatar, List<AvatarInfo>? groupAvatars,
Expand All @@ -426,8 +480,12 @@ class _$AvatarOptionsDMImpl implements AvatarOptionsDM {
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function(AvatarInfo avatar, List<AvatarInfo>? parentBadges,
double? size, double? badgesSize)?
TResult Function(
AvatarInfo avatar,
List<AvatarInfo>? parentBadges,
dynamic Function()? onTapParentBadges,
double? size,
double? badgesSize)?
$default, {
TResult Function(AvatarInfo avatar, double? size)? DM,
TResult Function(AvatarInfo avatar, List<AvatarInfo>? groupAvatars,
Expand Down Expand Up @@ -603,8 +661,12 @@ class _$AvatarOptionsGroupDMImpl implements AvatarOptionsGroupDM {
@override
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function(AvatarInfo avatar, List<AvatarInfo>? parentBadges,
double? size, double? badgesSize)
TResult Function(
AvatarInfo avatar,
List<AvatarInfo>? parentBadges,
dynamic Function()? onTapParentBadges,
double? size,
double? badgesSize)
$default, {
required TResult Function(AvatarInfo avatar, double? size) DM,
required TResult Function(AvatarInfo avatar, List<AvatarInfo>? groupAvatars,
Expand All @@ -617,8 +679,12 @@ class _$AvatarOptionsGroupDMImpl implements AvatarOptionsGroupDM {
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function(AvatarInfo avatar, List<AvatarInfo>? parentBadges,
double? size, double? badgesSize)?
TResult? Function(
AvatarInfo avatar,
List<AvatarInfo>? parentBadges,
dynamic Function()? onTapParentBadges,
double? size,
double? badgesSize)?
$default, {
TResult? Function(AvatarInfo avatar, double? size)? DM,
TResult? Function(AvatarInfo avatar, List<AvatarInfo>? groupAvatars,
Expand All @@ -631,8 +697,12 @@ class _$AvatarOptionsGroupDMImpl implements AvatarOptionsGroupDM {
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function(AvatarInfo avatar, List<AvatarInfo>? parentBadges,
double? size, double? badgesSize)?
TResult Function(
AvatarInfo avatar,
List<AvatarInfo>? parentBadges,
dynamic Function()? onTapParentBadges,
double? size,
double? badgesSize)?
$default, {
TResult Function(AvatarInfo avatar, double? size)? DM,
TResult Function(AvatarInfo avatar, List<AvatarInfo>? groupAvatars,
Expand Down

0 comments on commit 244fe5a

Please sign in to comment.