2021-11-14 09:36:35 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
|
|
|
import 'package:fluffychat/config/themes.dart';
|
|
|
|
import 'package:fluffychat/pages/chat/chat.dart';
|
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
|
|
|
|
|
|
|
class TypingIndicators extends StatelessWidget {
|
|
|
|
final ChatController controller;
|
|
|
|
const TypingIndicators(this.controller, {Key key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final typingUsers = controller.room.typingUsers
|
|
|
|
..removeWhere((u) => u.stateKey == Matrix.of(context).client.userID);
|
2021-11-14 11:18:33 +01:00
|
|
|
const topPadding = 20.0;
|
2021-11-14 09:36:35 +01:00
|
|
|
const bottomPadding = 4.0;
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
width: double.infinity,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: AnimatedContainer(
|
|
|
|
constraints:
|
|
|
|
const BoxConstraints(maxWidth: FluffyThemes.columnWidth * 2.5),
|
2021-11-14 11:18:33 +01:00
|
|
|
height: typingUsers.isEmpty ? 0 : Avatar.defaultSize + bottomPadding,
|
2021-11-14 09:36:35 +01:00
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
curve: Curves.bounceInOut,
|
|
|
|
alignment: controller.filteredEvents.isNotEmpty &&
|
|
|
|
controller.filteredEvents.first.senderId ==
|
|
|
|
Matrix.of(context).client.userID
|
|
|
|
? Alignment.topRight
|
|
|
|
: Alignment.topLeft,
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
decoration: const BoxDecoration(),
|
2021-11-22 15:35:51 +01:00
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 8.0,
|
2021-11-14 09:36:35 +01:00
|
|
|
bottom: bottomPadding,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: Avatar.defaultSize,
|
|
|
|
width: typingUsers.length < 2
|
|
|
|
? Avatar.defaultSize
|
2021-11-22 15:35:51 +01:00
|
|
|
: Avatar.defaultSize + 16,
|
2021-11-14 09:36:35 +01:00
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
if (typingUsers.isNotEmpty)
|
|
|
|
Avatar(
|
2021-11-20 10:42:23 +01:00
|
|
|
mxContent: typingUsers.first.avatarUrl,
|
|
|
|
name: typingUsers.first.calcDisplayname(),
|
2021-11-14 09:36:35 +01:00
|
|
|
),
|
|
|
|
if (typingUsers.length == 2)
|
|
|
|
Padding(
|
2021-11-22 15:35:51 +01:00
|
|
|
padding: const EdgeInsets.only(left: 16),
|
2021-11-14 09:36:35 +01:00
|
|
|
child: Avatar(
|
2021-11-20 10:42:23 +01:00
|
|
|
mxContent: typingUsers.length == 2
|
2021-11-14 09:36:35 +01:00
|
|
|
? typingUsers.last.avatarUrl
|
|
|
|
: null,
|
2021-11-20 10:42:23 +01:00
|
|
|
name: typingUsers.length == 2
|
2021-11-14 09:36:35 +01:00
|
|
|
? typingUsers.last.calcDisplayname()
|
|
|
|
: '+${typingUsers.length - 1}',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: topPadding),
|
|
|
|
child: Material(
|
2021-11-15 13:23:47 +01:00
|
|
|
color: Theme.of(context).appBarTheme.backgroundColor,
|
2021-11-14 09:36:35 +01:00
|
|
|
elevation: 6,
|
|
|
|
shadowColor:
|
|
|
|
Theme.of(context).secondaryHeaderColor.withAlpha(100),
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(2),
|
|
|
|
topRight: Radius.circular(AppConfig.borderRadius),
|
|
|
|
bottomLeft: Radius.circular(AppConfig.borderRadius),
|
|
|
|
bottomRight: Radius.circular(AppConfig.borderRadius),
|
|
|
|
),
|
|
|
|
child: Padding(
|
2021-11-14 11:18:33 +01:00
|
|
|
padding: const EdgeInsets.all(8),
|
2021-11-14 09:36:35 +01:00
|
|
|
child: typingUsers.isEmpty
|
|
|
|
? null
|
|
|
|
: Image.asset('assets/typing.gif', height: 12),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|