2020-02-11 11:49:39 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
|
2020-10-03 11:11:07 +00:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
import 'package:matrix/matrix.dart';
|
2020-02-11 11:49:39 +00:00
|
|
|
|
2022-12-30 16:54:01 +00:00
|
|
|
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
2021-11-09 20:32:16 +00:00
|
|
|
import '../../../config/app_config.dart';
|
2020-05-09 11:36:41 +00:00
|
|
|
|
2020-02-11 11:49:39 +00:00
|
|
|
class ReplyContent extends StatelessWidget {
|
|
|
|
final Event replyEvent;
|
2022-05-27 13:13:24 +00:00
|
|
|
final bool ownMessage;
|
2022-01-29 11:35:03 +00:00
|
|
|
final Timeline? timeline;
|
2024-04-01 08:32:11 +00:00
|
|
|
final Color? backgroundColor;
|
2020-02-11 11:49:39 +00:00
|
|
|
|
2022-01-29 11:35:03 +00:00
|
|
|
const ReplyContent(
|
|
|
|
this.replyEvent, {
|
2022-05-27 13:13:24 +00:00
|
|
|
this.ownMessage = false,
|
2023-10-28 11:03:16 +00:00
|
|
|
super.key,
|
2022-01-29 11:35:03 +00:00
|
|
|
this.timeline,
|
2024-04-01 08:32:11 +00:00
|
|
|
this.backgroundColor,
|
2023-10-28 11:03:16 +00:00
|
|
|
});
|
2020-02-11 11:49:39 +00:00
|
|
|
|
2023-12-23 06:06:38 +00:00
|
|
|
static const BorderRadius borderRadius = BorderRadius.only(
|
|
|
|
topRight: Radius.circular(AppConfig.borderRadius / 2),
|
|
|
|
bottomRight: Radius.circular(AppConfig.borderRadius / 2),
|
|
|
|
);
|
|
|
|
|
2020-02-11 11:49:39 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-01-29 11:35:03 +00:00
|
|
|
final timeline = this.timeline;
|
|
|
|
final displayEvent =
|
|
|
|
timeline != null ? replyEvent.getDisplayEvent(timeline) : replyEvent;
|
2021-11-13 12:06:36 +00:00
|
|
|
final fontSize = AppConfig.messageFontSize * AppConfig.fontSizeFactor;
|
2024-03-10 14:18:36 +00:00
|
|
|
final color = ownMessage
|
|
|
|
? Theme.of(context).colorScheme.primaryContainer
|
|
|
|
: Theme.of(context).colorScheme.primary;
|
2023-05-17 10:26:59 +00:00
|
|
|
|
2023-12-23 06:06:38 +00:00
|
|
|
return Material(
|
2024-04-01 08:32:11 +00:00
|
|
|
color: backgroundColor ??
|
|
|
|
Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.background
|
|
|
|
.withOpacity(ownMessage ? 0.2 : 0.33),
|
2023-12-23 06:06:38 +00:00
|
|
|
borderRadius: borderRadius,
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
width: 3,
|
2023-12-26 15:41:02 +00:00
|
|
|
height: fontSize * 2 + 16,
|
2024-03-10 14:18:36 +00:00
|
|
|
color: color,
|
2023-12-23 06:06:38 +00:00
|
|
|
),
|
|
|
|
const SizedBox(width: 6),
|
|
|
|
Flexible(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
FutureBuilder<User?>(
|
|
|
|
future: displayEvent.fetchSenderUser(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return Text(
|
|
|
|
'${snapshot.data?.calcDisplayname() ?? displayEvent.senderFromMemoryOrFallback.calcDisplayname()}:',
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
2024-03-10 14:18:36 +00:00
|
|
|
color: color,
|
2023-12-23 06:06:38 +00:00
|
|
|
fontSize: fontSize,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
displayEvent.calcLocalizedBodyFallback(
|
|
|
|
MatrixLocals(L10n.of(context)!),
|
|
|
|
withSenderNamePrefix: false,
|
|
|
|
hideReply: true,
|
|
|
|
),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 1,
|
|
|
|
style: TextStyle(
|
|
|
|
color: ownMessage
|
2024-03-10 14:18:36 +00:00
|
|
|
? Theme.of(context).colorScheme.onPrimary
|
2023-12-23 06:06:38 +00:00
|
|
|
: Theme.of(context).colorScheme.onBackground,
|
|
|
|
fontSize: fontSize,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-02-11 11:49:39 +00:00
|
|
|
),
|
2023-12-23 06:06:38 +00:00
|
|
|
const SizedBox(width: 6),
|
|
|
|
],
|
|
|
|
),
|
2020-02-11 11:49:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|