Skip to content

Commit 9faf5ac

Browse files
author
Fernando Aguilar
committed
Add a UI for displaying messages
1 parent c80f03c commit 9faf5ac

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

friendlychat/lib/chatMessage.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'package:flutter/material.dart';
2+
3+
class ChatMessage extends StatelessWidget {
4+
ChatMessage({this.text});
5+
final String text;
6+
static const String _name = "Fraguilar";
7+
8+
@override
9+
Widget build(BuildContext context) {
10+
return new Container(
11+
margin: const EdgeInsets.symmetric(vertical:10.0),
12+
child: new Row(
13+
crossAxisAlignment: CrossAxisAlignment.start,
14+
children: <Widget>[
15+
new Container(
16+
margin: const EdgeInsets.only(right: 16.0),
17+
child: new CircleAvatar(
18+
child: new Text(_name[0].toUpperCase() + _name[1].toUpperCase())
19+
),
20+
),
21+
new Column(
22+
crossAxisAlignment: CrossAxisAlignment.start,
23+
children: <Widget>[
24+
new Text(_name, style: Theme.of(context).textTheme.subhead),
25+
new Container(
26+
margin: const EdgeInsets.only(top: 5.0),
27+
child: new Text(text),
28+
),
29+
],
30+
)
31+
],
32+
),
33+
);
34+
}
35+
}

friendlychat/lib/chatscreen.dart renamed to friendlychat/lib/chatScreen.dart

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'chatMessage.dart';
23

34
class ChatScreen extends StatefulWidget {
45
@override
@@ -7,12 +8,30 @@ class ChatScreen extends StatefulWidget {
78

89
class ChatScreenState extends State<ChatScreen> {
910
final TextEditingController _textController = new TextEditingController();
11+
final List<ChatMessage> _messages = <ChatMessage>[];
1012

1113
@override
1214
Widget build(BuildContext context) {
1315
return new Scaffold(
1416
appBar: new AppBar(title: new Text("FriendlyChat")),
15-
body: _buildTextComposer(),
17+
body: new Column(
18+
children: <Widget>[
19+
new Flexible(
20+
child: new ListView.builder(
21+
padding: new EdgeInsets.all(8.0),
22+
reverse: true,
23+
itemBuilder: (_, int index) => _messages[index],
24+
itemCount: _messages.length,
25+
),
26+
),
27+
new Divider(height: 1.0),
28+
new Container(
29+
decoration: new BoxDecoration(
30+
color: Theme.of(context).cardColor),
31+
child: _buildTextComposer(),
32+
),
33+
],
34+
),
1635
);
1736
}
1837

@@ -47,5 +66,11 @@ class ChatScreenState extends State<ChatScreen> {
4766

4867
void _handleSubmitted(String text) {
4968
_textController.clear();
69+
ChatMessage message = new ChatMessage(
70+
text: text,
71+
);
72+
setState(() {
73+
_messages.insert(0, message);
74+
});
5075
}
5176
}

friendlychat/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:flutter/material.dart';
2-
import 'chatscreen.dart';
2+
import 'chatScreen.dart';
33

44
void main() {
55
runApp(new FriendlyChatApp());

0 commit comments

Comments
 (0)