-
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add shared model for chat messages
We'll reuse it for studies.
- Loading branch information
1 parent
910fac2
commit 2c3c52a
Showing
2 changed files
with
61 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:deep_pick/deep_pick.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'chat.freezed.dart'; | ||
part 'chat.g.dart'; | ||
|
||
@Freezed(fromJson: true) | ||
class ChatMessage with _$ChatMessage { | ||
const ChatMessage._(); | ||
|
||
const factory ChatMessage({ | ||
@JsonKey(name: 'u') required String username, | ||
@JsonKey(name: 't') required String message, | ||
@JsonKey(name: 'f') required String? flair, | ||
}) = _ChatMessage; | ||
|
||
factory ChatMessage.fromJson(Map<String, Object?> json) => | ||
_$ChatMessageFromJson(json); | ||
|
||
factory ChatMessage.fromPick(RequiredPick pick) => | ||
ChatMessage.fromJson(pick.asMapOrThrow()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters