-
Notifications
You must be signed in to change notification settings - Fork 3
/
chat_screen.dart
98 lines (87 loc) · 2.66 KB
/
chat_screen.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import 'package:flutter/material.dart';
import 'chat_message.dart';
import 'chat_interface.dart';
import 'home_page.dart';
class ChatScreen extends StatefulWidget {
@override
State createState() => new ChatScreenState();
}
class ChatScreenState extends State<ChatScreen>{
TextEditingController _textController = new TextEditingController();
List<ChatMessage> _messages = <ChatMessage> [];
void _handleSubmitted(String text){
_textController.clear();
ChatMessage message = new ChatMessage(
text: text,
);
setState((){
_messages.insert(0, message);
});
}
Widget _textComposerWidget(){
return new IconTheme(
data: new IconThemeData(
color: Colors.purpleAccent ),
child: new Container(
margin: const EdgeInsets.symmetric(horizontal: 8.0),
child: new Row(
children: <Widget>[
new Flexible(
child: new TextField(
decoration: new InputDecoration.collapsed( hintText: "Send a message"),
controller: _textController,
onSubmitted: _handleSubmitted,
),
),
new Container(
margin: const EdgeInsets.symmetric(horizontal: 4.0),
child: new IconButton(
icon: new Icon(Icons.send),
onPressed: ()=> _handleSubmitted(_textController.text)
),
),
],
),
),
);
}
@override
Widget build(BuildContext context){
return new Scaffold(
body: new Column(
children: <Widget>[
new Flexible(
child: new ListView.builder(
padding: new EdgeInsets.all(8.0),
reverse: true,
itemBuilder: (_,int index) => _messages[index],
itemCount: _messages.length,
),
),
new Divider(height: 1.0,),
new Container(
decoration: new BoxDecoration(
color: Theme.of(context).cardColor,
),
child: _textComposerWidget(),
)
],
),
// floatingActionButton: Padding(
// padding: const EdgeInsets.only(top: 570, right: 300),
// child: FloatingActionButton(
// child: Icon(Icons.navigation),
// backgroundColor: Colors.green,
// onPressed: () {
// {
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) => HomePage()),
// );
// }
// },
// )
// )
);
}
}