Last active
November 8, 2018 13:07
-
-
Save graphicbeacon/8c1f6b16768ee1274ba5c78855117ed8 to your computer and use it in GitHub Desktop.
Code snippet from "Build a chat application in Dart 2 (Part 2)" article
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
// Absolute imports | |
import 'dart:html'; | |
// Relative imports | |
import './view.dart'; | |
class ChatRoomView implements View { | |
ChatRoomView(this.params) : _contents = DocumentFragment() { | |
onEnter(); | |
} | |
/// Properties | |
Map params; | |
DocumentFragment _contents; | |
DivElement chatRoomBox; | |
DivElement chatRoomLog; | |
InputElement messageField; | |
ButtonElement sendBtn; | |
@override | |
void onEnter() { | |
prepare(); | |
render(); | |
} | |
@override | |
void onExit() { | |
_removeEventListeners(); // TODO: Implement this method | |
// TODO: Transition to chat sign in screen | |
} | |
@override | |
void prepare() { | |
_contents.innerHtml = ''' | |
<div id="ChatRoom"> | |
<h1 class="title">Chatroom</h1> | |
<div class="tile is-ancestor"> | |
<div class="tile is-8 is-vertical is-parent"> | |
<div class="tile is-child box"> | |
<div id="ChatRoomLog"></div> | |
</div> | |
<div class="tile is-child"> | |
<div class="field has-addons"> | |
<div class="control is-expanded has-icons-left"> | |
<input id="ChatRoomMessageInput" class="input is-medium" type="text" placeholder="Enter message" /> | |
<span class="icon is-medium is-left"> | |
<i class="fas fa-keyboard"></i> | |
</span> | |
</div> | |
<div class="control"> | |
<button id="ChatRoomSendBtn" class="button is-medium is-primary"> | |
Send | |
<span class="icon is-medium"> | |
<i class="fas fa-paper-plane"></i> | |
</span> | |
</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
'''; | |
chatRoomBox = _contents.querySelector('#ChatRoom'); | |
chatRoomLog = chatRoomBox.querySelector('#ChatRoomLog'); | |
messageField = chatRoomBox.querySelector('#ChatRoomMessageInput'); | |
sendBtn = chatRoomBox.querySelector('#ChatRoomSendBtn'); | |
_addEventListeners(); // TODO: Implement this method | |
} | |
@override | |
void render() { | |
querySelector('#app') | |
..innerHtml = '' | |
..append(_contents); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
View full article: https://dev.to/graphicbeacon/build-a-chat-application-in-dart-2-part-2-48df