diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index e0375b8..cc14283 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ { + final TextEditingController _messageController = TextEditingController(); final ScrollController _scrollController = ScrollController(); + @override void initState() { super.initState(); @@ -20,6 +22,19 @@ class _ChatPageState extends State { }); } + void _sendMessage() { + String message = _messageController.text.trim(); + if (message.isNotEmpty) { + messages.add({"message": message, "sent": true}); + _messageController.clear(); + _scrollController.animateTo( + _scrollController.position.maxScrollExtent, + duration: const Duration(milliseconds: 100), + curve: Curves.easeIn, + ); + } + } + List messages = [ { "message": "Hola!", @@ -122,44 +137,75 @@ 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( - 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), + padding: const EdgeInsets.fromLTRB(5, 10, 5, 5), + 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: Padding( + padding: const EdgeInsets.fromLTRB(0, 7, 0, 0), + child: TextField( + controller: _messageController, + decoration: InputDecoration( + hintText: "Message", + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + ), + )), + ), + IconButton( + icon: const Icon(Icons.send_rounded), + onPressed: () { + _sendMessage(); + }, ), - ); - }), + ], + ), + ], + ), ), ); } diff --git a/lib/screens/HomePage.dart b/lib/screens/HomePage.dart index 5266eb5..5d31bea 100644 --- a/lib/screens/HomePage.dart +++ b/lib/screens/HomePage.dart @@ -1,7 +1,7 @@ // ignore_for_file: file_names import 'package:flutter/material.dart'; -import 'package:test_app/screens/ChatPage.dart'; +import 'package:looper/screens/ChatPage.dart'; class HomePage extends StatefulWidget { const HomePage({super.key}); @@ -81,35 +81,35 @@ class _HomePageState extends State { title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text("What's UP"), + const Text("Looper"), Row( children: [ - Icon(Icons.search), + const Icon(Icons.search), PopupMenuButton( onSelected: (value) => {print(value)}, itemBuilder: (BuildContext context) => >[ - PopupMenuItem( + const PopupMenuItem( value: "New Group", child: Text("New Group"), ), - PopupMenuItem( + const PopupMenuItem( value: "New Broadcast", child: Text("New Broadcast"), ), - PopupMenuItem( + const PopupMenuItem( value: "Linked devices", child: Text("Linked devices"), ), - PopupMenuItem( + const PopupMenuItem( value: "Starred message", child: Text("Starred message"), ), - PopupMenuItem( + const PopupMenuItem( value: "Payment", child: Text("Payment"), ), - PopupMenuItem( + const PopupMenuItem( value: "Settings", child: Text("Settings"), ), diff --git a/pubspec.yaml b/pubspec.yaml index f83b8c5..76e8c28 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ -name: test_app -description: "A new Flutter project." +name: looper +description: " Conversations that never stop." # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev