Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: convert channel point events to StyledText #1271

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions lib/components/chat_history/twitch/channel_point_event.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:rtchat/components/chat_history/decorated_event.dart';
import 'package:rtchat/models/messages/twitch/channel_point_redemption_event.dart';
import 'package:styled_text/styled_text.dart';

class TwitchChannelPointRedemptionEventWidget extends StatelessWidget {
final TwitchChannelPointRedemptionEventModel model;
Expand All @@ -11,21 +12,12 @@ class TwitchChannelPointRedemptionEventWidget extends StatelessWidget {
Widget build(BuildContext context) {
return DecoratedEventWidget.icon(
icon: model.icon,
child: Text.rich(
TextSpan(
children: [
TextSpan(
text: model.redeemerUsername,
style: Theme.of(context).textTheme.titleSmall),
const TextSpan(text: " redeemed "),
TextSpan(
text: "${model.rewardName} ",
style: Theme.of(context).textTheme.titleSmall),
TextSpan(
text:
"for ${model.rewardCost} points. ${model.userInput ?? ''}"),
],
),
child: StyledText(
text:
'<b>${model.redeemerUsername}</b> redeemed <b>${model.rewardName}</b> for ${model.rewardCost} points. ${model.userInput ?? ''}',
tags: {
'b': StyledTextTag(style: Theme.of(context).textTheme.titleSmall),
},
),
);
}
Expand Down
19 changes: 11 additions & 8 deletions test/components/chat_history/twitch/channel_point_event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:provider/provider.dart';
import 'package:rtchat/components/chat_history/twitch/channel_point_event.dart';
import 'package:rtchat/models/messages/twitch/channel_point_redemption_event.dart';
import 'package:rtchat/models/style.dart';
import 'package:styled_text/styled_text.dart';

void main() {
testWidgets(
Expand All @@ -19,10 +20,11 @@ void main() {
userInput: null);
await tester.pumpWidget(buildWidget(model));

final findText = find.byWidgetPredicate((Widget widget) =>
widget is RichText &&
widget.text.toPlainText() ==
'automux redeemed Sprint for 100 points. ');
final findText = find.byWidgetPredicate((Widget widget) {
return widget is StyledText &&
widget.text ==
'<b>automux</b> redeemed <b>Sprint</b> for 100 points. ';
});

final findIcon = find.byIcon(Icons.done);

Expand All @@ -43,10 +45,11 @@ void main() {
userInput: "user input Kappa");
await tester.pumpWidget(buildWidget(model));

final findText = find.byWidgetPredicate((Widget widget) =>
widget is RichText &&
widget.text.toPlainText() ==
'automux redeemed WaTeER for 350 points. user input Kappa');
final findText = find.byWidgetPredicate((Widget widget) {
return widget is StyledText &&
widget.text ==
'<b>automux</b> redeemed <b>WaTeER</b> for 350 points. user input Kappa';
});

final findIcon = find.byIcon(Icons.timer);

Expand Down
Loading