diff options
| author | BoredGuy <osome3717@gmail.com> | 2026-05-09 19:59:04 -0700 |
|---|---|---|
| committer | BoredGuy <osome3717@gmail.com> | 2026-05-09 19:59:04 -0700 |
| commit | 67427aec40ba094f1e7f3ee77eab09df73d752f1 (patch) | |
| tree | b1cbaff8f809f5b003977279b93a6bae262e5b0b /lib/screens/chat_screen.dart | |
Diffstat (limited to 'lib/screens/chat_screen.dart')
| -rw-r--r-- | lib/screens/chat_screen.dart | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart new file mode 100644 index 0000000..35ea4a2 --- /dev/null +++ b/lib/screens/chat_screen.dart @@ -0,0 +1,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, + ), + ), + ], + ), + ), + ), + ], + ), + ), + ); + } +} |
