import 'package:async_tools/async_tools.dart'; import 'package:flutter/material.dart'; import 'package:flutter_translate/flutter_translate.dart'; import '../../proto/proto.dart' as proto; import '../../theme/theme.dart'; const _kOnTap = 'onTap'; const _kOnDelete = 'onDelete'; class ContactItemWidget extends StatelessWidget { const ContactItemWidget( {required proto.Contact contact, required bool disabled, required bool selected, Future Function(proto.Contact)? onTap, Future Function(proto.Contact)? onDoubleTap, Future Function(proto.Contact)? onDelete, super.key}) : _disabled = disabled, _selected = selected, _contact = contact, _onTap = onTap, _onDoubleTap = onDoubleTap, _onDelete = onDelete; @override // ignore: prefer_expression_function_bodies Widget build( BuildContext context, ) { final theme = Theme.of(context); final scale = theme.extension()!; final scaleConfig = theme.extension()!; final name = _contact.nameOrNickname; final title = _contact.displayName; final subtitle = _contact.profile.status; final avatar = AvatarWidget( name: name, size: 34, borderColor: _disabled ? scale.grayScale.primaryText : scale.primaryScale.primaryText, foregroundColor: _disabled ? scale.grayScale.primaryText : scale.primaryScale.primaryText, backgroundColor: _disabled ? scale.grayScale.primary : scale.primaryScale.primary, scaleConfig: scaleConfig, textStyle: theme.textTheme.titleLarge!, ); return SliderTile( key: ObjectKey(_contact), disabled: _disabled, selected: _selected, tileScale: ScaleKind.primary, title: title, subtitle: subtitle, leading: avatar, onDoubleTap: _onDoubleTap == null ? null : () => singleFuture((this, _kOnTap), () async { await _onDoubleTap(_contact); }), onTap: _onTap == null ? null : () => singleFuture((this, _kOnTap), () async { await _onTap(_contact); }), endActions: [ if (_onDelete != null) SliderTileAction( icon: Icons.delete, label: translate('button.delete'), actionScale: ScaleKind.tertiary, onPressed: (_context) => singleFuture((this, _kOnDelete), () async { await _onDelete(_contact); }), ), ], ); } //////////////////////////////////////////////////////////////////////////// final proto.Contact _contact; final bool _disabled; final bool _selected; final Future Function(proto.Contact contact)? _onTap; final Future Function(proto.Contact contact)? _onDoubleTap; final Future Function(proto.Contact contact)? _onDelete; }