Skip to content

Commit 627b746

Browse files
committed
Update
1 parent 411366b commit 627b746

File tree

10 files changed

+254
-34
lines changed

10 files changed

+254
-34
lines changed

Update 15 (Refactoration)-2/ReadMe.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

android/app/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ if (flutterVersionName == null) {
2222
}
2323

2424
apply plugin: 'com.android.application'
25+
apply plugin: 'com.google.gms.google-services'
2526
apply plugin: 'kotlin-android'
2627
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2728

@@ -43,11 +44,12 @@ android {
4344

4445
defaultConfig {
4546
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
46-
applicationId "com.example.flash_chat_flutter_firebase"
47+
applicationId "com.MyChat.flash_chat_flutter_firebase"
4748
minSdkVersion flutter.minSdkVersion
4849
targetSdkVersion flutter.targetSdkVersion
4950
versionCode flutterVersionCode.toInteger()
5051
versionName flutterVersionName
52+
multiDexEnabled true
5153
}
5254

5355
buildTypes {
@@ -65,4 +67,7 @@ flutter {
6567

6668
dependencies {
6769
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
70+
implementation platform('com.google.firebase:firebase-bom:30.0.1')
71+
implementation 'com.google.firebase:firebase-analytics'
72+
implementation 'com.google.firebase:firebase-analytics-ktx'
6873
}

android/app/google-services.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"project_info": {
3+
"project_number": "831044757364",
4+
"project_id": "my-flash-chat-109c0",
5+
"storage_bucket": "my-flash-chat-109c0.appspot.com"
6+
},
7+
"client": [
8+
{
9+
"client_info": {
10+
"mobilesdk_app_id": "1:831044757364:android:fd95e5e9e181736901ae21",
11+
"android_client_info": {
12+
"package_name": "com.MyChat.flash_chat_flutter_firebase"
13+
}
14+
},
15+
"oauth_client": [
16+
{
17+
"client_id": "831044757364-vqt7lf02krp5jilbmjsn1dmji3it081h.apps.googleusercontent.com",
18+
"client_type": 3
19+
}
20+
],
21+
"api_key": [
22+
{
23+
"current_key": "AIzaSyBxwX-2iTDNvkr8OveEBii_uXfnLaFf1vM"
24+
}
25+
],
26+
"services": {
27+
"appinvite_service": {
28+
"other_platform_oauth_client": [
29+
{
30+
"client_id": "831044757364-vqt7lf02krp5jilbmjsn1dmji3it081h.apps.googleusercontent.com",
31+
"client_type": 3
32+
}
33+
]
34+
}
35+
}
36+
}
37+
],
38+
"configuration_version": "1"
39+
}

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ buildscript {
88
dependencies {
99
classpath 'com.android.tools.build:gradle:4.1.0'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11+
classpath 'com.google.gms:google-services:4.3.10'
1112
}
1213
}
1314

lib/main.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import 'package:firebase_core/firebase_core.dart';
12
import 'package:flutter/material.dart';
23
import 'package:flash_chat_flutter_firebase/screens/welcome_screen.dart';
34
import 'package:flash_chat_flutter_firebase/screens/login_screen.dart';
45
import 'package:flash_chat_flutter_firebase/screens/registration_screen.dart';
56
import 'package:flash_chat_flutter_firebase/screens/chat_screen.dart';
67

7-
void main() => runApp(FlashChat());
8+
void main()async{
9+
WidgetsFlutterBinding.ensureInitialized();
10+
await Firebase.initializeApp();
11+
runApp(FlashChat());
12+
}
813

914
class FlashChat extends StatelessWidget {
1015
@override

lib/screens/chat_screen.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:firebase_auth/firebase_auth.dart';
12
import 'package:flutter/material.dart';
23
import 'package:flash_chat_flutter_firebase/constants.dart';
34

@@ -8,6 +9,27 @@ class ChatScreen extends StatefulWidget {
89
}
910

1011
class _ChatScreenState extends State<ChatScreen> {
12+
final _auth = FirebaseAuth.instance;
13+
User? loggedInUser;
14+
15+
void getCurrentUser() async {
16+
try {
17+
final user = await _auth.currentUser;
18+
if (user != null) {
19+
loggedInUser = user;
20+
print(loggedInUser);
21+
22+
}
23+
} catch (e) {
24+
print(e);
25+
}
26+
}
27+
@override
28+
void initState() {
29+
super.initState();
30+
31+
getCurrentUser();
32+
}
1133
@override
1234
Widget build(BuildContext context) {
1335
return Scaffold(

lib/screens/login_screen.dart

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
import 'package:flash_chat_flutter_firebase/screens/chat_screen.dart';
12
import 'package:flutter/material.dart';
23
import 'package:flash_chat_flutter_firebase/components/rounded_button.dart';
34
import 'package:flash_chat_flutter_firebase/constants.dart';
5+
import 'package:firebase_auth/firebase_auth.dart';
46
class LoginScreen extends StatefulWidget {
57
static const String id = 'login_screen';
68
@override
79
_LoginScreenState createState() => _LoginScreenState();
810
}
911

1012
class _LoginScreenState extends State<LoginScreen> {
13+
final _auth = FirebaseAuth.instance;
14+
String? email;
15+
String? password;
1116
@override
1217
Widget build(BuildContext context) {
1318
return Scaffold(
@@ -25,28 +30,42 @@ class _LoginScreenState extends State<LoginScreen> {
2530
child: Image.asset('images/logo.png'),
2631
),
2732
),
28-
SizedBox(
33+
const SizedBox(
2934
height: 48.0,
3035
),
3136
TextField(
37+
textAlign: TextAlign.center,
3238
onChanged: (value) {
33-
//Do something with the user input.
39+
email = value;
3440
},
3541
decoration: kInputDecoration.copyWith(hintText: 'Enter your email'),
3642
),
37-
SizedBox(
43+
const SizedBox(
3844
height: 8.0,
3945
),
4046
TextField(
47+
textAlign: TextAlign.center,
48+
obscureText: true,
4149
onChanged: (value) {
42-
//Do something with the user input.
50+
password = value;
4351
},
4452
decoration: kInputDecoration.copyWith(hintText: 'Enter your password'),
4553
),
46-
SizedBox(
54+
const SizedBox(
4755
height: 24.0,
4856
),
49-
RoundButton(title: 'Log In' , color: Colors.blueAccent, onPressed: (){})
57+
RoundButton(title: 'Log In' , color: Colors.blueAccent, onPressed: (){
58+
try {
59+
final user = _auth.signInWithEmailAndPassword(
60+
email: email!, password: password!);
61+
if (user != null) {
62+
Navigator.pushNamed(context, ChatScreen.id);
63+
}
64+
}on Error catch(e){
65+
print(e);
66+
}
67+
68+
})
5069
],
5170
),
5271
),

lib/screens/registration_screen.dart

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import 'package:flash_chat_flutter_firebase/constants.dart';
22
import 'package:flutter/material.dart';
33

4+
import '../components/rounded_button.dart';
5+
6+
import 'package:firebase_auth/firebase_auth.dart';
7+
8+
import 'chat_screen.dart';
9+
410
class RegistrationScreen extends StatefulWidget {
511
static const String id = 'registration_screen';
612
@override
713
_RegistrationScreenState createState() => _RegistrationScreenState();
814
}
915

1016
class _RegistrationScreenState extends State<RegistrationScreen> {
17+
final _auth = FirebaseAuth.instance;
18+
String? email;
19+
String? password;
1120
@override
1221
Widget build(BuildContext context) {
1322
return Scaffold(
@@ -25,46 +34,45 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
2534
child: Image.asset('images/logo.png'),
2635
),
2736
),
28-
SizedBox(
37+
const SizedBox(
2938
height: 48.0,
3039
),
3140
TextField(
41+
keyboardType: TextInputType.emailAddress,
42+
textAlign:TextAlign.center,
3243
onChanged: (value) {
33-
//Do something with the user input.
44+
email = value;
3445
},
3546
decoration: kInputDecoration.copyWith(hintText: "Enter your Email"),
3647
),
37-
SizedBox(
48+
const SizedBox(
3849
height: 8.0,
3950
),
4051
TextField(
52+
keyboardType: TextInputType.visiblePassword,
53+
textAlign:TextAlign.center,
54+
obscureText: true,
4155
onChanged: (value) {
42-
//Do something with the user input.
56+
password = value;
4357
},
4458
decoration: kInputDecoration.copyWith(hintText: "Enter your password"),
4559
),
46-
SizedBox(
60+
const SizedBox(
4761
height: 24.0,
4862
),
49-
Padding(
50-
padding: EdgeInsets.symmetric(vertical: 16.0),
51-
child: Material(
52-
color: Colors.blueAccent,
53-
borderRadius: BorderRadius.all(Radius.circular(30.0)),
54-
elevation: 5.0,
55-
child: MaterialButton(
56-
onPressed: () {
57-
//Implement registration functionality.
58-
},
59-
minWidth: 200.0,
60-
height: 42.0,
61-
child: Text(
62-
'Register',
63-
style: TextStyle(color: Colors.white),
64-
),
65-
),
66-
),
67-
),
63+
RoundButton(title:'Register', color: Colors.blueAccent, onPressed: ()async{
64+
try {
65+
final newUser = await _auth.createUserWithEmailAndPassword(
66+
email: email!, password: password!);
67+
if(newUser != null){
68+
Navigator.pushNamed(context, ChatScreen.id);
69+
}
70+
}on Error catch(e){
71+
print(e);
72+
}
73+
// print(email);
74+
// print(password);
75+
},),
6876
],
6977
),
7078
),

0 commit comments

Comments
 (0)