mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-08-03 03:36:23 -04:00
account management update
This commit is contained in:
parent
01c6490ec4
commit
5e4f47d5a1
42 changed files with 1663 additions and 831 deletions
|
@ -1,34 +1,36 @@
|
|||
import 'package:async_tools/async_tools.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
import '../../chat_list/chat_list.dart';
|
||||
import '../../layout/layout.dart';
|
||||
import '../../proto/proto.dart' as proto;
|
||||
import '../../theme/theme.dart';
|
||||
import '../contacts.dart';
|
||||
|
||||
const _kOnTap = 'onTap';
|
||||
const _kOnDelete = 'onDelete';
|
||||
|
||||
class ContactItemWidget extends StatelessWidget {
|
||||
const ContactItemWidget(
|
||||
{required proto.Contact contact, required bool disabled, super.key})
|
||||
{required proto.Contact contact,
|
||||
required bool disabled,
|
||||
required bool selected,
|
||||
Future<void> Function(proto.Contact)? onTap,
|
||||
Future<void> Function(proto.Contact)? onDoubleTap,
|
||||
Future<void> Function(proto.Contact)? onDelete,
|
||||
super.key})
|
||||
: _disabled = disabled,
|
||||
_contact = contact;
|
||||
_selected = selected,
|
||||
_contact = contact,
|
||||
_onTap = onTap,
|
||||
_onDoubleTap = onDoubleTap,
|
||||
_onDelete = onDelete;
|
||||
|
||||
@override
|
||||
// ignore: prefer_expression_function_bodies
|
||||
Widget build(
|
||||
BuildContext context,
|
||||
) {
|
||||
final localConversationRecordKey =
|
||||
_contact.localConversationRecordKey.toVeilid();
|
||||
|
||||
const selected = false; // xxx: eventually when we have selectable contacts:
|
||||
// activeContactCubit.state == localConversationRecordKey;
|
||||
|
||||
final tileDisabled = _disabled || context.watch<ContactListCubit>().isBusy;
|
||||
|
||||
late final String title;
|
||||
late final String subtitle;
|
||||
|
||||
if (_contact.nickname.isNotEmpty) {
|
||||
title = _contact.nickname;
|
||||
if (_contact.profile.pronouns.isNotEmpty) {
|
||||
|
@ -47,41 +49,33 @@ class ContactItemWidget extends StatelessWidget {
|
|||
|
||||
return SliderTile(
|
||||
key: ObjectKey(_contact),
|
||||
disabled: tileDisabled,
|
||||
selected: selected,
|
||||
disabled: _disabled,
|
||||
selected: _selected,
|
||||
tileScale: ScaleKind.primary,
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
icon: Icons.person,
|
||||
onTap: () async {
|
||||
// Start a chat
|
||||
final chatListCubit = context.read<ChatListCubit>();
|
||||
|
||||
await chatListCubit.getOrCreateChatSingleContact(contact: _contact);
|
||||
// Click over to chats
|
||||
if (context.mounted) {
|
||||
await MainPager.of(context)
|
||||
?.pageController
|
||||
.animateToPage(1, duration: 250.ms, curve: Curves.easeInOut);
|
||||
}
|
||||
},
|
||||
onDoubleTap: _onDoubleTap == null
|
||||
? null
|
||||
: () => singleFuture<void>((this, _kOnTap), () async {
|
||||
await _onDoubleTap(_contact);
|
||||
}),
|
||||
onTap: _onTap == null
|
||||
? null
|
||||
: () => singleFuture<void>((this, _kOnTap), () async {
|
||||
await _onTap(_contact);
|
||||
}),
|
||||
endActions: [
|
||||
SliderTileAction(
|
||||
if (_onDelete != null)
|
||||
SliderTileAction(
|
||||
icon: Icons.delete,
|
||||
label: translate('button.delete'),
|
||||
actionScale: ScaleKind.tertiary,
|
||||
onPressed: (context) async {
|
||||
final contactListCubit = context.read<ContactListCubit>();
|
||||
final chatListCubit = context.read<ChatListCubit>();
|
||||
|
||||
// Delete the contact itself
|
||||
await contactListCubit.deleteContact(
|
||||
localConversationRecordKey: localConversationRecordKey);
|
||||
|
||||
// Remove any chats for this contact
|
||||
await chatListCubit.deleteChat(
|
||||
localConversationRecordKey: localConversationRecordKey);
|
||||
})
|
||||
onPressed: (_context) =>
|
||||
singleFuture<void>((this, _kOnDelete), () async {
|
||||
await _onDelete(_contact);
|
||||
}),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -90,4 +84,8 @@ class ContactItemWidget extends StatelessWidget {
|
|||
|
||||
final proto.Contact _contact;
|
||||
final bool _disabled;
|
||||
final bool _selected;
|
||||
final Future<void> Function(proto.Contact contact)? _onTap;
|
||||
final Future<void> Function(proto.Contact contact)? _onDoubleTap;
|
||||
final Future<void> Function(proto.Contact contact)? _onDelete;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue