Messages
Get Contacts
GET /parent/message/get-contacts
Returns the list of teachers/staff the parent can message.
{
"data": {
"contacts": [
{
"id": "uuid",
"name": "Mr. R. Kumar",
"role": "TEACHER",
"designation": "Class Teacher",
"photoUrl": "https://cdn.syncad.in/teachers/uuid.jpg"
}
]
}
}
Get Chat Messages
GET /parent/message/get-messages?contactId={uuid}
Returns message history with a specific contact.
{
"data": {
"messages": [
{
"id": "uuid",
"senderId": "uuid",
"body": "Please ensure John attends school tomorrow.",
"sentAt": "2024-04-01T14:30:00Z",
"readAt": "2024-04-01T15:00:00Z"
}
]
}
}
Send Direct Message
POST /parent/message/send-message
{
"data": {
"recipientId": "teacher-uuid",
"body": "Thank you for the update."
}
}
UI — Chat Screen
class ChatScreen extends StatefulWidget {
final String contactId;
final String recipientName;
@override
State<ChatScreen> createState() => _ChatScreenState();
}
class _ChatScreenState extends State<ChatScreen> {
final _controller = TextEditingController();
List<Message> _messages = [];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget.recipientName)),
body: Column(
children: [
Expanded(
child: ListView.builder(
reverse: true,
itemCount: _messages.length,
itemBuilder: (_, i) {
final msg = _messages[_messages.length - 1 - i];
final isMe = msg.senderId == currentUserId;
return Align(
alignment: isMe ? Alignment.centerRight : Alignment.centerLeft,
child: Container(
margin: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: isMe ? Colors.blue : Colors.grey.shade200,
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(msg.body, style: TextStyle(color: isMe ? Colors.white : Colors.black)),
const SizedBox(height: 4),
Text(
_formatTime(msg.sentAt),
style: TextStyle(fontSize: 10, color: isMe ? Colors.white70 : Colors.grey),
),
],
),
),
);
},
),
),
Row(
children: [
Expanded(child: TextField(controller: _controller, decoration: const InputDecoration(hintText: 'Type a message...'))),
IconButton(icon: const Icon(Icons.send), onPressed: _send),
],
),
],
),
);
}
}