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

Fix message format and refactor types in SSEModel #11

Closed
wants to merge 3 commits into from
Closed
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
11 changes: 6 additions & 5 deletions lib/flutter_client_sse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class SSEClient {
var value = '';
if (field == 'data') {
//If the field is data, we get the data through the substring
value = dataLine.substring(
5,
);
value = dataLine[5] == " "
? dataLine.substring(6)
: dataLine.substring(5);
} else {
value = match.group(2) ?? '';
}
Expand All @@ -65,8 +65,9 @@ class SSEClient {
currentSSEModel.event = value;
break;
case 'data':
currentSSEModel.data =
(currentSSEModel.data ?? '') + value + '\n';
currentSSEModel.data = currentSSEModel.data.isNotEmpty
? currentSSEModel.data + "\n" + value
: value;
break;
case 'id':
currentSSEModel.id = value;
Expand Down
6 changes: 3 additions & 3 deletions lib/sse_event_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ part of flutter_client_sse;

class SSEModel {
//Id of the event
String? id = '';
String id = '';
//Event name
String? event = '';
String event = '';
//Event data
String? data = '';
String data = '';
SSEModel({required this.data, required this.id, required this.event});
SSEModel.fromData(String data) {
id = data.split("\n")[0].split('id:')[1];
Expand Down