fluffychat/lib/pages/chat/chat_app_bar_title.dart

88 lines
3 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';
2023-11-11 18:54:31 +00:00
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat/chat.dart';
2023-11-11 16:56:23 +00:00
import 'package:fluffychat/utils/date_time_extension.dart';
2022-12-30 16:54:01 +00:00
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/widgets/avatar.dart';
2023-11-11 16:56:23 +00:00
import 'package:fluffychat/widgets/presence_builder.dart';
class ChatAppBarTitle extends StatelessWidget {
final ChatController controller;
const ChatAppBarTitle(this.controller, {super.key});
@override
Widget build(BuildContext context) {
2022-01-29 11:35:03 +00:00
final room = controller.room;
if (controller.selectedEvents.isNotEmpty) {
return Text(controller.selectedEvents.length.toString());
}
2022-02-17 11:52:58 +00:00
return InkWell(
2023-08-12 10:33:01 +00:00
hoverColor: Colors.transparent,
2022-02-17 11:52:58 +00:00
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: controller.isArchived
? null
: () => context.go('/rooms/${room.id}/details'),
2022-02-17 11:52:58 +00:00
child: Row(
children: [
2022-07-08 08:41:36 +00:00
Hero(
tag: 'content_banner',
child: Avatar(
mxContent: room.avatar,
2023-01-20 15:59:50 +00:00
name: room.getLocalizedDisplayname(
MatrixLocals(L10n.of(context)!),
),
2022-07-08 08:41:36 +00:00
size: 32,
),
2022-02-17 11:52:58 +00:00
),
const SizedBox(width: 12),
2022-02-17 13:16:39 +00:00
Expanded(
2023-11-11 18:54:31 +00:00
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
room.getLocalizedDisplayname(MatrixLocals(L10n.of(context)!)),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 16,
),
2023-11-11 16:56:23 +00:00
),
2023-11-11 18:54:31 +00:00
AnimatedSize(
duration: FluffyThemes.animationDuration,
child: PresenceBuilder(
userId: room.directChatMatrixID,
builder: (context, presence) {
final lastActiveTimestamp = presence?.lastActiveTimestamp;
final style = Theme.of(context).textTheme.bodySmall;
if (presence?.currentlyActive == true) {
return Text(
L10n.of(context)!.currentlyActive,
style: style,
);
}
if (lastActiveTimestamp != null) {
return Text(
L10n.of(context)!.lastActiveAgo(
lastActiveTimestamp.localizedTimeShort(context),
),
style: style,
);
}
return const SizedBox.shrink();
},
),
),
],
2022-02-17 11:52:58 +00:00
),
),
],
),
);
}
}