From e5f822dc6df7a122eee32b35963bed668cfcde72 Mon Sep 17 00:00:00 2001 From: "1148648777@qq.com" <1148648777@qq.com> Date: Fri, 14 Apr 2023 10:31:00 +0800 Subject: [PATCH 1/3] fix(message-format): Remove extra space at the beginning of each line in received messages. --- lib/flutter_client_sse.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/flutter_client_sse.dart b/lib/flutter_client_sse.dart index d6fc31e..67c1107 100644 --- a/lib/flutter_client_sse.dart +++ b/lib/flutter_client_sse.dart @@ -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) ?? ''; } From 4ce1664ef4d264203a97e6869f26d5ced67af65e Mon Sep 17 00:00:00 2001 From: "1148648777@qq.com" <1148648777@qq.com> Date: Fri, 14 Apr 2023 11:51:09 +0800 Subject: [PATCH 2/3] refactor(types): Change type of fields from to for non-nullable initialization. --- lib/sse_event_model.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/sse_event_model.dart b/lib/sse_event_model.dart index 6faacef..8c94a56 100644 --- a/lib/sse_event_model.dart +++ b/lib/sse_event_model.dart @@ -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]; From 8b7fa3d44c7440fb24aa0f70dfb23e4a4a5ad18d Mon Sep 17 00:00:00 2001 From: "1148648777@qq.com" <1148648777@qq.com> Date: Fri, 14 Apr 2023 12:00:22 +0800 Subject: [PATCH 3/3] fix(message-format): Remove trailing newline characters in received messages. --- lib/flutter_client_sse.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/flutter_client_sse.dart b/lib/flutter_client_sse.dart index 67c1107..758bc44 100644 --- a/lib/flutter_client_sse.dart +++ b/lib/flutter_client_sse.dart @@ -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;