-
Notifications
You must be signed in to change notification settings - Fork 52
/
chat_screen.dart
232 lines (220 loc) · 7.19 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:social/models/models.dart';
import 'package:social/screens/chat/widgets/message_info.dart';
import '../../common/common.dart';
import 'constants/constants.dart';
import 'widgets/bottom_input_field.dart';
import 'widgets/message_datelable.dart';
import 'widgets/message_tile.dart';
class ChatScreen extends ConsumerStatefulWidget {
final User userConversation;
const ChatScreen({Key? key, required this.userConversation})
: super(key: key);
// this is for navigation
static Route route(User data) => MaterialPageRoute(
builder: (context) => ChatScreen(
userConversation: data,
),
);
@override
ConsumerState<ConsumerStatefulWidget> createState() => _ChatScreenState();
}
class _ChatScreenState extends ConsumerState<ChatScreen> {
final bottomTextFeildController = TextEditingController();
final bottomTextFeildFocusNode = FocusNode();
@override
void dispose() {
super.dispose();
bottomTextFeildController.dispose();
}
@override
Widget build(BuildContext context) {
final brightness = Theme.of(context).brightness;
return Scaffold(
appBar: ChatScreenAppbar(user: widget.userConversation),
body: SafeArea(
child: Column(
children: <Widget>[
// Message list
Expanded(
child: _DemoMessageList(
InputBoxFocus: bottomTextFeildFocusNode,
),
),
// Bottom input field
BottomInputField(
focusNode: bottomTextFeildFocusNode,
),
],
),
),
);
}
}
// ChatComposer(
// controller: inputController,
// onReceiveText: (textMessage) {
// print(textMessage);
// },
// onRecordEnd: (filepath) {},
// borderRadius: BorderRadius.circular(60),
// sendIcon: Icons.send,
// sendButtonBackgroundColor: AppColors.secondary,
// textPadding: EdgeInsets.only(
// right: 12,
// top: 8,
// bottom: 5,
// ),
// padding: EdgeInsets.only(
// left: 12,
// bottom: 6,
// top: 1,
// right: 12,
// ),
// actions: [
// // camera button
// IconButton(
// splashRadius: 10,
// onPressed: () {},
// icon: Icon(Icons.camera_alt),
// ),
// ],
// keyboardType: TextInputType.multiline,
// textFieldDecoration: InputDecoration(
// hintText: "Type message...",
// hintStyle: TextStyle(
// color: brightness == Brightness.light
// ? AppColors.textDark
// : AppColors.textLight,
// ),
// contentPadding: EdgeInsets.zero,
// enabledBorder: OutlineInputBorder(
// borderRadius: BorderRadius.circular(60),
// borderSide: BorderSide(
// color: Colors.transparent,
// ),
// ),
// focusedBorder: OutlineInputBorder(
// borderRadius: BorderRadius.circular(60),
// borderSide: BorderSide(
// color: Colors.transparent,
// ),
// ),
// ),
// recordIcon: Icons.mic,
// recordIconColor: AppColors.iconLight,
// backgroundColor: Theme.of(context).scaffoldBackgroundColor,
// lockColor: AppColors.iconLight,
// lockBackgroundColor: AppColors.secondary,
// deleteButtonColor: Colors.red,
// leading: IconButton(
// splashRadius: 10,
// onPressed: () {},
// icon: Icon(Icons.attach_file),
// ),
// composerColor: brightness == Brightness.light
// ? Colors.grey.shade100
// : AppColors.cardDark,
// ),
// Gets keyBoard focus when user swipes
void getKeyBoardFocus(FocusNode InputBoxFocus) {
// if (InputBoxFocus.hasFocus) {
// InputBoxFocus.unfocus();
// InputBoxFocus.requestFocus();
// } else {
// InputBoxFocus.requestFocus();
// }
showCustomBottomSheet(
bottomSheetContext,
MessageInfo(),
.18,
.18,
);
}
class _DemoMessageList extends StatelessWidget {
const _DemoMessageList({
Key? key,
required this.InputBoxFocus,
}) : super(key: key);
final FocusNode InputBoxFocus;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: ListView(
physics: ScrollPhysics(parent: BouncingScrollPhysics()),
children: [
DateLable(lable: 'Yesterday'),
MessageTile(
message: 'Hi, Lucy! How\'s your day going?',
messageDate: '12:01 PM',
isSender: false,
status: MessageStatus.Seen,
type: MessageType.Text,
onSwipe: () {
// if input box already has focus
getKeyBoardFocus(InputBoxFocus);
},
isReacted: true,
),
MessageTile(
message: 'You know how it goes... \n bro',
messageDate: '12:02 PM',
isSender: true,
status: MessageStatus.Seen,
type: MessageType.Text,
onSwipe: () {
// if input box already has focus
getKeyBoardFocus(InputBoxFocus);
},
),
MessageTile(
message: 'Do you want Starbucks?',
messageDate: '12:02 PM',
isSender: false,
status: MessageStatus.Seen,
type: MessageType.Text,
onSwipe: () {
// if input box already has focus
getKeyBoardFocus(InputBoxFocus);
},
),
MessageTile(
message: 'Would be awesome!',
messageDate: '12:03 PM',
isSender: true,
status: MessageStatus.Seen,
type: MessageType.Text,
onSwipe: () {
// if input box already has focus
getKeyBoardFocus(InputBoxFocus);
},
),
MessageTile(
message: 'Coming up!',
messageDate: '12:03 PM',
isSender: false,
status: MessageStatus.Delivered,
type: MessageType.Image,
onSwipe: () {
// if input box already has focus
getKeyBoardFocus(InputBoxFocus);
},
),
MessageTile(
message: 'YAY!!!',
messageDate: '12:03 PM',
isSender: true,
status: MessageStatus.Sent,
type: MessageType.Text,
onSwipe: () {
// if input box already has focus
getKeyBoardFocus(InputBoxFocus);
},
),
],
),
);
}
}