Skip to content

Commit

Permalink
Merge branch 'master_twentyeight' of https://github.com/AvinandanBose…
Browse files Browse the repository at this point in the history
…/FlashChat_Flutter_x_Firebase_Cloud_Firestore_Updates into master_twentynine

� Conflicts:
�	lib/screens/chat_screen.dart
�	lib/screens/login_screen.dart
�	lib/screens/registration_screen.dart
  • Loading branch information
AvinandanBose committed May 25, 2022
2 parents 090e19a + d8848ff commit 3b419cb
Show file tree
Hide file tree
Showing 4 changed files with 353 additions and 122 deletions.
30 changes: 19 additions & 11 deletions lib/screens/chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flash_chat_flutter_firebase/constants.dart';

final _firestore = FirebaseFirestore.instance;
User? loggedInUser;
class ChatScreen extends StatefulWidget {
static const String id = 'chat_screen';
@override
Expand Down Expand Up @@ -60,9 +61,9 @@ class _ChatScreenState extends State<ChatScreen> {
IconButton(
icon: Icon(Icons.close),
onPressed: () {
// _auth.signOut();
// Navigator.pop(context);
getMessages();
_auth.signOut();
Navigator.pop(context);

}),
],
title: Text('⚡️Chat'),
Expand Down Expand Up @@ -91,8 +92,8 @@ class _ChatScreenState extends State<ChatScreen> {
),
FlatButton(
onPressed: () {
//messageText + loggedInUser
messageTextController.clear();
//messageText + loggedInUser
_firestore.collection('messages').add({
'text' : messageText,
'sender': loggedInUser?.email,
Expand Down Expand Up @@ -129,13 +130,19 @@ class MessagesStream extends StatelessWidget {
),
);
}
final messages = snapshot.data!.docs;
final messages = snapshot.data!.docs.reversed;
List<MessageBubble> messageWidgets = [];
for (var message in messages) {
final messageText = message.data()['text'];
final messageSender = message.data()['sender'];

final messageWidget = MessageBubble(text: messageText,sender: messageSender);
final currentUser = loggedInUser?.email;

if(currentUser == messageSender){

}

final messageWidget = MessageBubble(text: messageText,sender: messageSender ,isMe: currentUser==messageSender,);

messageWidgets.add(messageWidget);
}
Expand All @@ -154,7 +161,8 @@ class MessagesStream extends StatelessWidget {
class MessageBubble extends StatefulWidget {
final String? sender;
final String? text;
const MessageBubble({Key? key, this.text,this.sender}) : super(key: key);
final bool? isMe;
const MessageBubble({Key? key, this.text,this.sender, this.isMe}) : super(key: key);

@override
State<MessageBubble> createState() => _MessageBubbleState();
Expand All @@ -168,23 +176,23 @@ class _MessageBubbleState extends State<MessageBubble> {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
crossAxisAlignment: widget.isMe! ? CrossAxisAlignment.end : CrossAxisAlignment.start,
children: <Widget>[
Text('${widget.sender}',
style: const TextStyle(
fontSize: 12.0,
color: Colors.black54,
),),
Material(
borderRadius: BorderRadius.circular(50.0),
borderRadius: widget.isMe! ?const BorderRadius.only(topLeft: Radius.circular(30.0),bottomLeft:Radius.circular(30.0), bottomRight:Radius.circular(30.0) ):BorderRadius.only(topRight: Radius.circular(30.0),bottomLeft:Radius.circular(30.0), bottomRight:Radius.circular(30.0) ),
elevation:5.0, //Drop Shadow to each text
color: Colors.lightBlueAccent,
color: widget.isMe! ? Colors.lightBlueAccent : Colors.white,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
child: Text(
'${widget.text}',
style: TextStyle(
color: Colors.white,
color: widget.isMe! ? Colors.white : Colors.black54 ,
fontSize: 15.0,
),
),
Expand Down
114 changes: 54 additions & 60 deletions lib/screens/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flash_chat_flutter_firebase/components/rounded_button.dart';
import 'package:flash_chat_flutter_firebase/constants.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';

class LoginScreen extends StatefulWidget {
static const String id = 'login_screen';
@override
Expand All @@ -12,74 +12,68 @@ class LoginScreen extends StatefulWidget {

class _LoginScreenState extends State<LoginScreen> {
final _auth = FirebaseAuth.instance;
bool showSpinner = false;
String? email;
String? password;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: ModalProgressHUD(
inAsyncCall: showSpinner, ///Here we call the bool value (initially it is false)
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Flexible(
child: Hero(
tag: 'logo',
child: Container(
height: 200.0,
child: Image.asset('images/logo.png'),
),
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Flexible(
child: Hero(
tag: 'logo',
child: Container(
height: 200.0,
child: Image.asset('images/logo.png'),
),
),
const SizedBox(
height: 48.0,
),
TextField(
textAlign: TextAlign.center,
onChanged: (value) {
email = value;
},
decoration: kInputDecoration.copyWith(hintText: 'Enter your email'),
),
const SizedBox(
height: 8.0,
),
TextField(
textAlign: TextAlign.center,
obscureText: true,
onChanged: (value) {
password = value;
},
decoration: kInputDecoration.copyWith(hintText: 'Enter your password'),
),
const SizedBox(
height: 24.0,
),
RoundButton(title: 'Log In' , color: Colors.blueAccent, onPressed: (){
setState((){ ///before signIn with Email and Password state changed and it spins
showSpinner = true;
});
try {
final user = _auth.signInWithEmailAndPassword(
email: email!, password: password!);
if (user != null) {
Navigator.pushNamed(context, ChatScreen.id);
),
const SizedBox(
height: 48.0,
),
TextField(
textAlign: TextAlign.center,
onChanged: (value) {
email = value;
},
decoration:
kInputDecoration.copyWith(hintText: 'Enter your email'),
),
const SizedBox(
height: 8.0,
),
TextField(
textAlign: TextAlign.center,
obscureText: true,
onChanged: (value) {
password = value;
},
decoration:
kInputDecoration.copyWith(hintText: 'Enter your password'),
),
const SizedBox(
height: 24.0,
),
RoundButton(
title: 'Log In',
color: Colors.blueAccent,
onPressed: () {
try {
final user = _auth.signInWithEmailAndPassword(
email: email!, password: password!);
if (user != null) {
Navigator.pushNamed(context, ChatScreen.id);
}
} on Error catch (e) {
print(e);
}
setState((){ ///After signIn with Email and Password state changed and it stops spins
showSpinner = false;
});
}on Error catch(e){
print(e);
}

})
],
),
})
],
),
),
);
Expand Down
97 changes: 46 additions & 51 deletions lib/screens/registration_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import '../components/rounded_button.dart';
import 'package:firebase_auth/firebase_auth.dart';

import 'chat_screen.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';

class RegistrationScreen extends StatefulWidget {
static const String id = 'registration_screen';
Expand All @@ -16,77 +15,73 @@ class RegistrationScreen extends StatefulWidget {

class _RegistrationScreenState extends State<RegistrationScreen> {
final _auth = FirebaseAuth.instance;
bool showSpinner = false;
String? email;
String? password;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: ModalProgressHUD(
inAsyncCall: showSpinner, ///Here we call the bool value (initially it is false)
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Hero(
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Flexible(
child: Hero(
tag: 'logo',
child: Container(
height: 200.0,
child: Image.asset('images/logo.png'),
),
),
const SizedBox(
height: 48.0,
),
Flexible(
child: TextField(
keyboardType: TextInputType.emailAddress,
textAlign:TextAlign.center,
onChanged: (value) {
email = value;
},
decoration: kInputDecoration.copyWith(hintText: "Enter your Email"),
),
),
const SizedBox(
height: 8.0,
),
TextField(
keyboardType: TextInputType.visiblePassword,
textAlign:TextAlign.center,
obscureText: true,
onChanged: (value) {
password = value;
},
decoration: kInputDecoration.copyWith(hintText: "Enter your password"),
),
const SizedBox(
height: 24.0,
),
RoundButton(title:'Register', color: Colors.blueAccent, onPressed: ()async{
setState((){ ///before creation of Email and Password state changed and it spins
showSpinner = true;
});
),
const SizedBox(
height: 48.0,
),
TextField(
keyboardType: TextInputType.emailAddress,
textAlign: TextAlign.center,
onChanged: (value) {
email = value;
},
decoration:
kInputDecoration.copyWith(hintText: "Enter your Email"),
),
const SizedBox(
height: 8.0,
),
TextField(
keyboardType: TextInputType.visiblePassword,
textAlign: TextAlign.center,
obscureText: true,
onChanged: (value) {
password = value;
},
decoration:
kInputDecoration.copyWith(hintText: "Enter your password"),
),
const SizedBox(
height: 24.0,
),
RoundButton(
title: 'Register',
color: Colors.blueAccent,
onPressed: () async {
try {
final newUser = await _auth.createUserWithEmailAndPassword(
email: email!, password: password!);
if(newUser != null){
if (newUser != null) {
Navigator.pushNamed(context, ChatScreen.id);
}
setState((){ ///After creation of Email and Password state changed and it stops spins
showSpinner = false;
});
}on Error catch(e){
} on Error catch (e) {
print(e);
}
// print(email);
// print(password);
},),
],
),
},
),
],
),
),
);
Expand Down
Loading

0 comments on commit 3b419cb

Please sign in to comment.