diff --git a/lib/authorization/signupemail.dart b/lib/authorization/signupemail.dart index cc84030..8976510 100644 --- a/lib/authorization/signupemail.dart +++ b/lib/authorization/signupemail.dart @@ -16,10 +16,11 @@ class SignUpMethods { required String userName, required BuildContext context}) async { try { - // ignore: use_build_context_synchronously - await sendEmailVerification(context); UserCredential userCredential = await _auth .createUserWithEmailAndPassword(email: email, password: password); + // ignore: use_build_context_synchronously + await sendEmailVerification(context); + await _firestore.collection('users').doc(userCredential.user!.uid).set({ 'username': userName, diff --git a/lib/authorization/storage.dart b/lib/authorization/storage.dart new file mode 100644 index 0000000..8a28ef6 --- /dev/null +++ b/lib/authorization/storage.dart @@ -0,0 +1,12 @@ +// import 'package:cloud_firestore/cloud_firestore.dart'; + +// class Storage { +// FirebaseFirestore users = FirebaseFirestore.instance; +// Future getUserList() async { +// await users.collection('users').snapshots(); + +// } +// } + + +//! Till Auth app is done , till yet not even list of people is shown diff --git a/lib/pages/homepage.dart b/lib/pages/homepage.dart index 78e1334..6a66aa1 100644 --- a/lib/pages/homepage.dart +++ b/lib/pages/homepage.dart @@ -1,6 +1,9 @@ import 'package:chatapp/authorization/signupemail.dart'; +import 'package:chatapp/pages/messaging.dart'; import 'package:chatapp/utils/color.dart'; +import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_auth/firebase_auth.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class HomePage extends StatefulWidget { @@ -15,53 +18,95 @@ class _HomePageState extends State { @override Widget build(BuildContext context) { return SafeArea( - minimum: const EdgeInsets.only(left: 8, right: 8), child: Scaffold( - appBar: AppBar( - actions: [ - Padding( - padding: const EdgeInsets.only(right: 10), - child: GestureDetector( - onTap: () { - showDialog( - context: context, - builder: (context) => AlertDialog( - title: const Text( - "Do you really want to Log out", - style: TextStyle(color: Colors.red), + backgroundColor: backgroundColor, + appBar: AppBar( + actions: [ + Padding( + padding: const EdgeInsets.only(right: 10), + child: GestureDetector( + onTap: () { + showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text( + "Do you really want to Log out", + style: TextStyle(color: Colors.red), + ), + actions: [ + GestureDetector( + onTap: () => + SignUpMethods(_auth).logOut(context), + child: const Text( + "Yes", + style: TextStyle(color: Colors.red), + )), + const SizedBox( + width: 20, + ), + GestureDetector( + onTap: () => Navigator.of(context).pop(), + child: const Text( + "No", + style: TextStyle(color: Colors.green), ), - actions: [ - GestureDetector( - onTap: () => SignUpMethods(_auth).logOut(context), - child: const Text( - "Yes", - style: TextStyle(color: Colors.red), - )), - const SizedBox( - width: 20, - ), - GestureDetector(onTap: () => Navigator.of(context).pop(), - child: const Text( - "No", - style: TextStyle(color: Colors.green), - ), - ), - ], - )); - }, - child: const Icon( - Icons.output_rounded, - color: Colors.red, - size: 30, - )), - ) - ], - title: Text( - "Chats", - style: TextStyle(color: Colors.cyan.shade100, fontSize: 25), - ), - backgroundColor: darkBackgroundColor, - ), - )); + ), + ], + )); + }, + child: const Icon( + Icons.output_rounded, + color: Colors.red, + size: 30, + )), + ) + ], + title: Text( + "Chats", + style: TextStyle(color: Colors.cyan.shade100, fontSize: 25), + ), + backgroundColor: darkBackgroundColor, + ), + body: StreamBuilder( + stream: FirebaseFirestore.instance.collection('users').snapshots(), + builder: (context, snapshot) { + if (snapshot.hasError) { + return const CircularProgressIndicator(); + } + if (snapshot.hasData) { + // print("**************"); + // print(snapshot.data!.docs[0].data()); + // print(snapshot.data!.docs); + // print(snapshot.data); + + // print("**************"); + + return ListView.builder( + itemCount: snapshot.data!.docs.length, + itemBuilder: (context, index) { + // var userId = snapshot.data?.docs[index].id; + Map userData = snapshot.data?.docs[index].data() as Map; + + return ListTile( + leading: CircleAvatar( + // You can use user image or initials here + // Example: backgroundImage: NetworkImage(userData['profileImage']), + child: Text(userData['username'] + [0]), // Displaying the first letter of the username + ), + title: Text(userData['username']), + subtitle: Text(userData['email']), + onTap: () { + Navigator.of(context).push(CupertinoPageRoute( + builder: (context) => Messaging( + otherPersonName: userData['username'], + otherPersonId: userData['uid']))); + }, + ); + }); + } + return const CircularProgressIndicator(); + }), + )); } } diff --git a/lib/pages/messaging.dart b/lib/pages/messaging.dart new file mode 100644 index 0000000..9400f8d --- /dev/null +++ b/lib/pages/messaging.dart @@ -0,0 +1,96 @@ +import 'package:chatapp/utils/color.dart'; +import 'package:chatapp/widget/chatwidget.dart'; +import 'package:flutter/material.dart'; + +class Messaging extends StatefulWidget { + final String otherPersonName; + final String otherPersonId; + + const Messaging( + {super.key, required this.otherPersonName, required this.otherPersonId}); + + @override + State createState() => _MessagingState(); +} + +class _MessagingState extends State { + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + final size = MediaQuery.of(context).size; + return SafeArea( + child: Scaffold( + resizeToAvoidBottomInset: true, + backgroundColor: backgroundColor, + appBar: AppBar( + title: Text( + widget.otherPersonName, + style: TextStyle(color: Colors.cyan.shade100, fontSize: 25), + ), + backgroundColor: darkBackgroundColor, + ), + body: Padding( + padding: const EdgeInsets.only(right: 8, left: 8), + child: ListView(children: [ + Container( + height: size.height * 0.8, + width: double.infinity, + // ! child: , Column will come here to show chats + // color: Colors.deepPurple.shade200.withOpacity(0.2), + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [ + Colors.deepPurple.withOpacity(0.2), + Colors.deepPurpleAccent.withOpacity(0.2), + const Color.fromARGB(255, 208, 5, 244).withOpacity(0.1), + const Color.fromARGB(255, 210, 13, 228).withOpacity(0.1), + Colors.pink.withOpacity(0.2), + ])), + child: Column(crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ChatWidget(size: size,isMyChat: false,chat: "Satyam is my name heres the first chat",), + ], + ), + ), + Expanded( + child: Align( + alignment: Alignment.bottomCenter, + child: TextField( + onTapOutside: (event) => + FocusScope.of(context).requestFocus(FocusNode()), + style: const TextStyle(fontSize: 20), + canRequestFocus: true, + decoration: InputDecoration( + suffixIcon: IconButton( + icon: Icon( + Icons.send, + size: 40, + color: Colors.blueGrey.shade900, + ), + onPressed: () {}, //! send chat + ), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(30), + ), + fillColor: Colors.deepPurple, + filled: true, + hintText: "Yeah , why not..", + ), + ), + ), + ), + const SizedBox( + height: 10, + ) + ]), + ), + )); + } +} + diff --git a/lib/widget/chatwidget.dart b/lib/widget/chatwidget.dart new file mode 100644 index 0000000..1969235 --- /dev/null +++ b/lib/widget/chatwidget.dart @@ -0,0 +1,51 @@ +import 'package:flutter/material.dart'; + +class ChatWidget extends StatefulWidget { + final bool isMyChat; + final String chat; + + const ChatWidget({ + super.key, + required this.size, + required this.chat, + required this.isMyChat, + }); + + final Size size; + + @override + State createState() => _ChatWidgetState(); +} + +class _ChatWidgetState extends State { + @override + Widget build(BuildContext context) { + return Container( + width: widget.size.width * 0.45, + decoration: BoxDecoration( + shape: BoxShape.rectangle, + borderRadius: BorderRadius.circular(30), + gradient: LinearGradient( + colors: widget.isMyChat + ? [ + const Color.fromARGB(255, 173, 58, 183).withOpacity(0.2), + const Color.fromARGB(255, 221, 61, 215).withOpacity(0.2), + const Color.fromARGB(255, 208, 5, 244).withOpacity(0.1), + const Color.fromARGB(255, 210, 13, 228).withOpacity(0.1), + Colors.pink.withOpacity(0.2), + ] + : [ + const Color.fromARGB(255, 147, 227, 129).withOpacity(0.2), + const Color.fromARGB(255, 71, 205, 87).withOpacity(0.2), + const Color.fromARGB(255, 66, 199, 117).withOpacity(0.1), + const Color.fromARGB(255, 21, 235, 85).withOpacity(0.2), + const Color.fromARGB(255, 57, 194, 86).withOpacity(0.1), + ]), + ), + child: Text( + widget.chat, + style: const TextStyle(fontSize: 20, color: Colors.white), + ), + ); + } +}