Skip to content

Commit

Permalink
Login issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshar062 committed Nov 28, 2023
1 parent 21eacc9 commit cb0b9cd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/api/apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class APIs {
.collection('users')
.doc(chatUser.id)
.collection('contacts')
.doc(chatUser.id)
.doc(user.uid)
.set({}).then((value) => sendMessage(chatUser, msg, type));
}

Expand Down
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:developer';

import 'package:chat_app/screens/auth/login_screen.dart';
import 'package:chat_app/screens/splash_screen.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -31,7 +32,7 @@ class MyApp extends StatelessWidget {
title: 'Let\'s Chat',
debugShowCheckedModeBanner: false,
theme: ThemeData.dark(useMaterial3: true),
home: const LoginScreen(),
home: const SplashScreen(),
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ class _ChatScreenState extends State<ChatScreen> {
if (_textController.text.isNotEmpty) {
if(_list.isEmpty){
APIs.sendFirstMessage(widget.user, _textController.text, 'text');
} else {
APIs.sendMessage(widget.user, _textController.text, 'text');
}
APIs.sendMessage(widget.user, _textController.text, 'text');
_textController.clear();
}
},
Expand Down
17 changes: 17 additions & 0 deletions lib/screens/splash_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:developer';

import 'package:chat_app/api/apis.dart';
import 'package:chat_app/screens/auth/login_screen.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../main.dart';
Expand All @@ -17,13 +18,16 @@ class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
print("Splash Screen , init called ............");
Future.delayed(const Duration(seconds: 2), () {
//exit full-screen
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
systemNavigationBarColor: Colors.white,
statusBarColor: Colors.white));

print('User: ${APIs.auth.currentUser}');

if (APIs.auth.currentUser != null) {
log('\nUser: ${APIs.auth.currentUser}');
//navigate to home screen
Expand All @@ -34,6 +38,19 @@ class _SplashScreenState extends State<SplashScreen> {
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (_) => const LoginScreen()));
}

// APIs.auth.authStateChanges().listen((User? user) {
// if (user != null) {
// log('\nUser: ${user}');
// // Navigate to home screen
// Navigator.pushReplacement(
// context, MaterialPageRoute(builder: (_) => const HomeScreen()));
// } else {
// // Navigate to login screen
// Navigator.pushReplacement(
// context, MaterialPageRoute(builder: (_) => const LoginScreen()));
// }
// });
});
}

Expand Down

0 comments on commit cb0b9cd

Please sign in to comment.