Created
April 13, 2021 09:29
-
-
Save Jimmy-Prime/12f7d2c81a8d65e09119095b692243c5 to your computer and use it in GitHub Desktop.
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
class Channel { | |
final int id; | |
bool isStarred; | |
bool isJoined; | |
bool isEncrypted; | |
Channel.fromJson(Map<String, dynamic> json) | |
: id = json['channel_id'], | |
isStarred = json['is_star'], | |
isJoined = json['is_joined'], | |
isEncrypted = json['encrypted']; | |
} | |
class Conversation extends Channel { | |
List<int> members; | |
Conversation.fromJson(Map<String, dynamic> json) | |
: members = json['members'].cast<int>(), | |
super.fromJson(json); | |
} | |
class NamedChannel extends Channel { | |
String name; | |
String purpose; | |
NamedChannel.fromJson(Map<String, dynamic> json) | |
: name = json['name'], | |
purpose = json['purpose'], | |
super.fromJson(json); | |
} | |
class PublicChannel extends NamedChannel { | |
PublicChannel.fromJson(Map<String, dynamic> json) : super.fromJson(json); | |
} | |
class PrivateChannel extends NamedChannel { | |
PrivateChannel.fromJson(Map<String, dynamic> json) : super.fromJson(json); | |
} | |
class ChatBotChannel extends NamedChannel { | |
ChatBotChannel.fromJson(Map<String, dynamic> json) : super.fromJson(json); | |
} | |
// make a factory class? | |
Channel createChannelFromJSONObject(dynamic json) { | |
switch (json['type']) { | |
case 'public': | |
return PublicChannel.fromJson(json); | |
case 'private': | |
return PublicChannel.fromJson(json); | |
case 'anonymous': | |
return Conversation.fromJson(json); | |
case 'chatbot': | |
return ChatBotChannel.fromJson(json); | |
default: | |
return Channel.fromJson(json); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment