diff --git a/lib/screens/ChatPage.dart b/lib/screens/ChatPage.dart index aa83c89..19ac4b2 100644 --- a/lib/screens/ChatPage.dart +++ b/lib/screens/ChatPage.dart @@ -1,6 +1,8 @@ -// ignore_for_file: file_names +// ignore_for_file: file_names, prefer_const_constructors +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; class ChatPage extends StatefulWidget { const ChatPage({super.key, required this.name, required this.image}); @@ -20,6 +22,14 @@ class _ChatPageState extends State { }); } + bool attachmentBoxShow = false; + void _showAttachmentBox() { + setState(() { + attachmentBoxShow = !attachmentBoxShow; // + }); + } + + TextEditingController _textEditingController = TextEditingController(); List messages = [ { "message": "Hola!", @@ -123,43 +133,170 @@ class _ChatPageState extends State { ), body: Padding( padding: const EdgeInsets.all(8.0), - child: ListView.builder( - controller: _scrollController, - itemCount: messages.length, - itemBuilder: (context, index) { - int previous = index - 1 >= 0 ? index - 1 : 0; - int current = index; - return Padding( - padding: messages[previous]["sent"] == messages[current]["sent"] - ? const EdgeInsets.only(left: 8, right: 8, top: 4) - : const EdgeInsets.only(left: 8, right: 8, top: 8), - child: Align( - alignment: messages[index]["sent"] - ? Alignment.centerRight - : Alignment.centerLeft, - child: Container( + child: Column( + children: [ + Expanded( + child: ListView.builder( + controller: _scrollController, + itemCount: messages.length, + itemBuilder: (context, index) { + int previous = index - 1 >= 0 ? index - 1 : 0; + int current = index; + return Padding( + padding: messages[previous]["sent"] == + messages[current]["sent"] + ? const EdgeInsets.only(left: 8, right: 8, top: 4) + : const EdgeInsets.only(left: 8, right: 8, top: 8), + child: Align( + alignment: messages[index]["sent"] + ? Alignment.centerRight + : Alignment.centerLeft, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: messages[index]["sent"] + ? Colors.amber[200] + : Colors.blue[200], + ), + child: Padding( + padding: const EdgeInsets.all(10), + child: ConstrainedBox( + constraints: BoxConstraints( + maxWidth: + MediaQuery.of(context).size.width * 0.8, + ), + child: Text( + messages[index]["message"], + style: const TextStyle(fontSize: 18), + ), + ), + ), + ), + ), + ); + }), + ), + Row( + children: [ + Expanded( + child: TextField( + keyboardType: TextInputType.text, + controller: _textEditingController, + decoration: InputDecoration( + border: OutlineInputBorder(), + suffixIcon: IconButton( + icon: Icon(Icons.attachment_sharp), + onPressed: _showAttachmentBox, + ), + hintText: "Type a message", + ), + ), + ), + TextButton( + onPressed: () { + if (_textEditingController.text.isNotEmpty) { + setState(() { + messages.add({ + "message": _textEditingController.text, + "sent": true, + }); + _textEditingController.clear(); + }); + } + }, + child: const Icon(Icons.send)), + ], + ), + attachmentBoxShow + ? Container( + padding: EdgeInsets.only(top: 25), + height: MediaQuery.of(context).size.width * 0.5, decoration: BoxDecoration( + color: const Color.fromARGB(255, 37, 37, 37), borderRadius: BorderRadius.circular(10), - color: messages[index]["sent"] - ? Colors.amber[200] - : Colors.blue[200], ), - child: Padding( - padding: const EdgeInsets.all(10), - child: ConstrainedBox( - constraints: BoxConstraints( - maxWidth: MediaQuery.of(context).size.width * 0.8, + child: Column( + children: [ + Padding( + padding: const EdgeInsets.all(25.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + SizedBox( + child: Icon( + Icons.photo, + color: Color.fromARGB(255, 66, 108, 117), + size: 35, + ), + ), + SizedBox( + child: Icon( + Icons.camera, + color: Color.fromARGB(255, 66, 108, 117), + size: 35, + ), + ), + SizedBox( + child: Icon( + Icons.location_pin, + color: Color.fromARGB(255, 66, 108, 117), + size: 35, + ), + ), + SizedBox( + child: Icon( + Icons.contact_phone, + color: Color.fromARGB(255, 66, 108, 117), + size: 35, + ), + ) + ], + ), ), - child: Text( - messages[index]["message"], - style: const TextStyle(fontSize: 18), + Padding( + padding: const EdgeInsets.all(25.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + SizedBox( + child: Icon( + Icons.document_scanner, + color: Color.fromARGB(255, 66, 108, 117), + size: 35, + ), + ), + SizedBox( + child: Icon( + Icons.audio_file, + color: Color.fromARGB(255, 66, 108, 117), + size: 35, + ), + ), + SizedBox( + child: Icon( + Icons.poll, + color: Color.fromARGB(255, 66, 108, 117), + size: 35, + ), + ), + SizedBox( + child: Icon( + Icons.payment, + color: Color.fromARGB(255, 66, 108, 117), + size: 35, + ), + ) + ], + ), ), - ), + ], ), - ), - ), - ); - }), + ) + : SizedBox( + height: 0, + ) + ], + ), ), ); }