diff --git a/lib/src/acter_avatar.dart b/lib/src/acter_avatar.dart index 2ea95b1..37a912f 100644 --- a/lib/src/acter_avatar.dart +++ b/lib/src/acter_avatar.dart @@ -141,8 +141,9 @@ class _ActerAvatar extends State { 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 @@ -153,6 +154,7 @@ class _ActerAvatar extends State { Widget _renderDefault( ImageProvider avatar, List? badges, + Function()? onTapParentBadges, double? size, double? badgesSize, ) { @@ -252,26 +254,32 @@ class _ActerAvatar extends State { List 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() .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), + ), ), )); } diff --git a/lib/src/models/avatar_options.dart b/lib/src/models/avatar_options.dart index 3de20c5..68c1854 100644 --- a/lib/src/models/avatar_options.dart +++ b/lib/src/models/avatar_options.dart @@ -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? parentBadges, + Function()? onTapParentBadges, double? size, double? badgesSize}) = DefaultAvatarOptions; diff --git a/lib/src/models/avatar_options.freezed.dart b/lib/src/models/avatar_options.freezed.dart index 1425d33..aa52173 100644 --- a/lib/src/models/avatar_options.freezed.dart +++ b/lib/src/models/avatar_options.freezed.dart @@ -20,8 +20,12 @@ mixin _$AvatarOptions { double? get size => throw _privateConstructorUsedError; @optionalTypeArgs TResult when( - TResult Function(AvatarInfo avatar, List? parentBadges, - double? size, double? badgesSize) + TResult Function( + AvatarInfo avatar, + List? parentBadges, + dynamic Function()? onTapParentBadges, + double? size, + double? badgesSize) $default, { required TResult Function(AvatarInfo avatar, double? size) DM, required TResult Function(AvatarInfo avatar, List? groupAvatars, @@ -31,8 +35,12 @@ mixin _$AvatarOptions { throw _privateConstructorUsedError; @optionalTypeArgs TResult? whenOrNull( - TResult? Function(AvatarInfo avatar, List? parentBadges, - double? size, double? badgesSize)? + TResult? Function( + AvatarInfo avatar, + List? parentBadges, + dynamic Function()? onTapParentBadges, + double? size, + double? badgesSize)? $default, { TResult? Function(AvatarInfo avatar, double? size)? DM, TResult? Function(AvatarInfo avatar, List? groupAvatars, @@ -42,8 +50,12 @@ mixin _$AvatarOptions { throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen( - TResult Function(AvatarInfo avatar, List? parentBadges, - double? size, double? badgesSize)? + TResult Function( + AvatarInfo avatar, + List? parentBadges, + dynamic Function()? onTapParentBadges, + double? size, + double? badgesSize)? $default, { TResult Function(AvatarInfo avatar, double? size)? DM, TResult Function(AvatarInfo avatar, List? groupAvatars, @@ -129,6 +141,7 @@ abstract class _$$DefaultAvatarOptionsImplCopyWith<$Res> $Res call( {AvatarInfo avatar, List? parentBadges, + dynamic Function()? onTapParentBadges, double? size, double? badgesSize}); } @@ -146,6 +159,7 @@ class __$$DefaultAvatarOptionsImplCopyWithImpl<$Res> $Res call({ Object? avatar = null, Object? parentBadges = freezed, + Object? onTapParentBadges = freezed, Object? size = freezed, Object? badgesSize = freezed, }) { @@ -158,6 +172,10 @@ class __$$DefaultAvatarOptionsImplCopyWithImpl<$Res> ? _value._parentBadges : parentBadges // ignore: cast_nullable_to_non_nullable as List?, + 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 @@ -174,7 +192,10 @@ class __$$DefaultAvatarOptionsImplCopyWithImpl<$Res> class _$DefaultAvatarOptionsImpl implements DefaultAvatarOptions { const _$DefaultAvatarOptionsImpl(this.avatar, - {final List? parentBadges, this.size, this.badgesSize}) + {final List? parentBadges, + this.onTapParentBadges, + this.size, + this.badgesSize}) : _parentBadges = parentBadges; @override @@ -189,6 +210,8 @@ class _$DefaultAvatarOptionsImpl implements DefaultAvatarOptions { return EqualUnmodifiableListView(value); } + @override + final dynamic Function()? onTapParentBadges; @override final double? size; @override @@ -196,7 +219,7 @@ class _$DefaultAvatarOptionsImpl implements DefaultAvatarOptions { @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 @@ -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 @@ -227,36 +257,49 @@ class _$DefaultAvatarOptionsImpl implements DefaultAvatarOptions { @override @optionalTypeArgs TResult when( - TResult Function(AvatarInfo avatar, List? parentBadges, - double? size, double? badgesSize) + TResult Function( + AvatarInfo avatar, + List? parentBadges, + dynamic Function()? onTapParentBadges, + double? size, + double? badgesSize) $default, { required TResult Function(AvatarInfo avatar, double? size) DM, required TResult Function(AvatarInfo avatar, List? groupAvatars, double? size, double? groupAvatarSize) GroupDM, }) { - return $default(avatar, parentBadges, size, badgesSize); + return $default(avatar, parentBadges, onTapParentBadges, size, badgesSize); } @override @optionalTypeArgs TResult? whenOrNull( - TResult? Function(AvatarInfo avatar, List? parentBadges, - double? size, double? badgesSize)? + TResult? Function( + AvatarInfo avatar, + List? parentBadges, + dynamic Function()? onTapParentBadges, + double? size, + double? badgesSize)? $default, { TResult? Function(AvatarInfo avatar, double? size)? DM, TResult? Function(AvatarInfo avatar, List? 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 Function(AvatarInfo avatar, List? parentBadges, - double? size, double? badgesSize)? + TResult Function( + AvatarInfo avatar, + List? parentBadges, + dynamic Function()? onTapParentBadges, + double? size, + double? badgesSize)? $default, { TResult Function(AvatarInfo avatar, double? size)? DM, TResult Function(AvatarInfo avatar, List? groupAvatars, @@ -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(); } @@ -308,12 +352,14 @@ class _$DefaultAvatarOptionsImpl implements DefaultAvatarOptions { abstract class DefaultAvatarOptions implements AvatarOptions { const factory DefaultAvatarOptions(final AvatarInfo avatar, {final List? parentBadges, + final dynamic Function()? onTapParentBadges, final double? size, final double? badgesSize}) = _$DefaultAvatarOptionsImpl; @override AvatarInfo get avatar; List? get parentBadges; + dynamic Function()? get onTapParentBadges; @override double? get size; double? get badgesSize; @@ -398,8 +444,12 @@ class _$AvatarOptionsDMImpl implements AvatarOptionsDM { @override @optionalTypeArgs TResult when( - TResult Function(AvatarInfo avatar, List? parentBadges, - double? size, double? badgesSize) + TResult Function( + AvatarInfo avatar, + List? parentBadges, + dynamic Function()? onTapParentBadges, + double? size, + double? badgesSize) $default, { required TResult Function(AvatarInfo avatar, double? size) DM, required TResult Function(AvatarInfo avatar, List? groupAvatars, @@ -412,8 +462,12 @@ class _$AvatarOptionsDMImpl implements AvatarOptionsDM { @override @optionalTypeArgs TResult? whenOrNull( - TResult? Function(AvatarInfo avatar, List? parentBadges, - double? size, double? badgesSize)? + TResult? Function( + AvatarInfo avatar, + List? parentBadges, + dynamic Function()? onTapParentBadges, + double? size, + double? badgesSize)? $default, { TResult? Function(AvatarInfo avatar, double? size)? DM, TResult? Function(AvatarInfo avatar, List? groupAvatars, @@ -426,8 +480,12 @@ class _$AvatarOptionsDMImpl implements AvatarOptionsDM { @override @optionalTypeArgs TResult maybeWhen( - TResult Function(AvatarInfo avatar, List? parentBadges, - double? size, double? badgesSize)? + TResult Function( + AvatarInfo avatar, + List? parentBadges, + dynamic Function()? onTapParentBadges, + double? size, + double? badgesSize)? $default, { TResult Function(AvatarInfo avatar, double? size)? DM, TResult Function(AvatarInfo avatar, List? groupAvatars, @@ -603,8 +661,12 @@ class _$AvatarOptionsGroupDMImpl implements AvatarOptionsGroupDM { @override @optionalTypeArgs TResult when( - TResult Function(AvatarInfo avatar, List? parentBadges, - double? size, double? badgesSize) + TResult Function( + AvatarInfo avatar, + List? parentBadges, + dynamic Function()? onTapParentBadges, + double? size, + double? badgesSize) $default, { required TResult Function(AvatarInfo avatar, double? size) DM, required TResult Function(AvatarInfo avatar, List? groupAvatars, @@ -617,8 +679,12 @@ class _$AvatarOptionsGroupDMImpl implements AvatarOptionsGroupDM { @override @optionalTypeArgs TResult? whenOrNull( - TResult? Function(AvatarInfo avatar, List? parentBadges, - double? size, double? badgesSize)? + TResult? Function( + AvatarInfo avatar, + List? parentBadges, + dynamic Function()? onTapParentBadges, + double? size, + double? badgesSize)? $default, { TResult? Function(AvatarInfo avatar, double? size)? DM, TResult? Function(AvatarInfo avatar, List? groupAvatars, @@ -631,8 +697,12 @@ class _$AvatarOptionsGroupDMImpl implements AvatarOptionsGroupDM { @override @optionalTypeArgs TResult maybeWhen( - TResult Function(AvatarInfo avatar, List? parentBadges, - double? size, double? badgesSize)? + TResult Function( + AvatarInfo avatar, + List? parentBadges, + dynamic Function()? onTapParentBadges, + double? size, + double? badgesSize)? $default, { TResult Function(AvatarInfo avatar, double? size)? DM, TResult Function(AvatarInfo avatar, List? groupAvatars,