Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
feat!: merge messages by the same author (#27)
Browse files Browse the repository at this point in the history
* Merge messages by the same author

* fix: pr

Co-authored-by: teaishealthy <76410798+teaishealthy@users.noreply.github.com>
Co-authored-by: teaishealthy <teaishealthy@protonmail.com>
  • Loading branch information
3 people authored Oct 7, 2022
1 parent b2ddf1e commit 21973d6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
6 changes: 5 additions & 1 deletion lib/routes/loggedin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ class _LoggedInState extends State<LoggedIn> {
controller: _scrollController,
itemBuilder: (context, index) {
final message = _messages[index];
return Message(message: message);
return Message(
message: message,
displayAuthor: index != 0 &&
_messages[index - 1].author != message.author,
);
},
),
),
Expand Down
60 changes: 32 additions & 28 deletions lib/widgets/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,48 @@ import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:markdown/markdown.dart' as markdown;

class Message extends StatelessWidget {
final MessageData message;
final bool displayAuthor;

const Message({
Key? key,
required this.displayAuthor,
required this.message,
}) : super(key: key);

final MessageData message;

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
message.author,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
Theme(
data: Theme.of(context).copyWith(
textTheme: Theme.of(context).textTheme.apply(
bodyColor: message.optimistic ? Colors.grey : null,
padding: const EdgeInsets.only(left: 10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: ([
displayAuthor
? Padding(
padding: const EdgeInsets.only(top: 10, bottom: 4),
child: Text(
message.author,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
child: MarkdownBody(
data: message.content,
extensionSet: markdown.ExtensionSet(
markdown.ExtensionSet.gitHubFlavored.blockSyntaxes, [
...markdown.ExtensionSet.gitHubFlavored.inlineSyntaxes,
markdown.EmojiSyntax()
])),
),
)
: Container(),
Theme(
data: Theme.of(context).copyWith(
textTheme: Theme.of(context).textTheme.apply(
bodyColor: message.optimistic ? Colors.grey : null,
),
),
],
),
child: MarkdownBody(
data: message.content,
extensionSet: markdown.ExtensionSet(
markdown.ExtensionSet.gitHubFlavored.blockSyntaxes, [
...markdown.ExtensionSet.gitHubFlavored.inlineSyntaxes,
markdown.EmojiSyntax()
])),
),
]),
),
);
}
Expand Down

0 comments on commit 21973d6

Please sign in to comment.