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
|
import 'package:flutter/material.dart';
class ChatScreen extends StatefulWidget {
final String name;
const ChatScreen({super.key, required this.name});
@override
State<ChatScreen> createState() => _ChatScreenState();
}
class _ChatScreenState extends State<ChatScreen> {
final _messageController = TextEditingController();
final List<Map<String, dynamic>> _messages = [
{'text': 'Hello!', 'isMe': false, 'time': '10:00 AM'},
{'text': 'Hi, how are you?', 'isMe': true, 'time': '10:05 AM'},
{'text': 'I am good, thanks! Are we meeting later?', 'isMe': false, 'time': '10:06 AM'},
];
void _sendMessage() {
if (_messageController.text.trim().isEmpty) return;
setState(() {
_messages.add({
'text': _messageController.text,
'isMe': true,
'time': 'Now',
});
_messageController.clear();
});
}
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
appBar: AppBar(
backgroundColor: const Color(0xFF2AABEE),
foregroundColor: Colors.white,
titleSpacing: 0,
title: Row(
children: [
CircleAvatar(
radius: 18,
backgroundColor: Colors.white24,
child: Text(widget.name[0], style: const TextStyle(color: Colors.white, fontSize: 16)),
),
const SizedBox(width: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.name, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
const Text('last seen recently', style: TextStyle(fontSize: 12, color: Colors.white70)),
],
),
],
),
actions: [
IconButton(icon: const Icon(Icons.call), onPressed: () {}),
IconButton(icon: const Icon(Icons.more_vert), onPressed: () {}),
],
),
body: Container(
color: isDark ? null : const Color(0xFFC8DCED), // Classic background color
child: Column(
children: [
Expanded(
child: ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
itemCount: _messages.length,
itemBuilder: (context, index) {
final msg = _messages[index];
final isMe = msg['isMe'] as bool;
return Align(
alignment: isMe ? Alignment.centerRight : Alignment.centerLeft,
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.75,
),
child: Container(
margin: const EdgeInsets.only(bottom: 8),
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
decoration: BoxDecoration(
color: isMe
? (isDark ? const Color(0xFF2AABEE) : const Color(0xFFEEFFDE))
: (isDark ? const Color(0xFF212D3B) : Colors.white),
borderRadius: BorderRadius.circular(16).copyWith(
bottomRight: isMe ? const Radius.circular(4) : const Radius.circular(16),
bottomLeft: !isMe ? const Radius.circular(4) : const Radius.circular(16),
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 2,
offset: const Offset(0, 1),
),
],
),
child: Wrap(
crossAxisAlignment: WrapCrossAlignment.end,
alignment: WrapAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(right: 8.0, bottom: 2.0),
child: Text(
msg['text'] as String,
style: TextStyle(
color: isDark
? Colors.white
: (isMe ? Colors.black87 : Colors.black87),
fontSize: 16,
),
),
),
Text(
msg['time'] as String,
style: TextStyle(
color: isDark
? Colors.white54
: (isMe ? const Color(0xFF55A65A) : Colors.grey),
fontSize: 11,
),
),
],
),
),
),
);
},
),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
color: Theme.of(context).scaffoldBackgroundColor,
child: SafeArea(
child: Row(
children: [
IconButton(
icon: const Icon(Icons.attach_file, color: Colors.grey),
onPressed: () {},
),
Expanded(
child: TextField(
controller: _messageController,
decoration: InputDecoration(
hintText: 'Message',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(24),
borderSide: BorderSide.none,
),
filled: true,
fillColor: isDark ? const Color(0xFF212D3B) : Colors.grey[200],
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
),
onSubmitted: (_) => _sendMessage(),
),
),
const SizedBox(width: 8),
CircleAvatar(
backgroundColor: const Color(0xFF2AABEE),
child: IconButton(
icon: const Icon(Icons.send, color: Colors.white, size: 20),
onPressed: _sendMessage,
),
),
],
),
),
),
],
),
),
);
}
}
|