Skip to content

Commit 74dab31

Browse files
committed
🐛 (fix) login bug fixed
1.:bug: Redirect on welcome page after enter incorrect credentials ficed. 2.:bug: FCM tokrn not found on message send fix
1 parent 19c77be commit 74dab31

File tree

3 files changed

+43
-23
lines changed

3 files changed

+43
-23
lines changed

lib/page/homePage.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ class _HomePageState extends State<HomePage> {
6565
final chatState = Provider.of<ChatState>(context, listen: false);
6666
final state = Provider.of<AuthState>(context, listen: false);
6767
chatState.databaseInit(state.userId, state.userId);
68+
state.updateFCMToken();
6869
}
6970

7071
Widget _body() {
71-
var state = Provider.of<AppState>(context);
72+
7273
final authstate = Provider.of<AuthState>(context, listen: false);
7374
WidgetsBinding.instance.addPostFrameCallback((_) {
7475
var state = Provider.of<NotificationState>(context);
@@ -84,7 +85,7 @@ class _HomePageState extends State<HomePage> {
8485
});
8586
}
8687
});
87-
return SafeArea(child: Container(child: _getPage(state.pageIndex)));
88+
return SafeArea(child: Container(child: _getPage(Provider.of<AppState>(context).pageIndex)));
8889
}
8990

9091
Widget _getPage(int index) {

lib/page/message/chatListPage.dart

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import 'package:flutter_twitter_clone/page/common/sidebar.dart';
88
import 'package:flutter_twitter_clone/page/message/newMessagePage.dart';
99
import 'package:flutter_twitter_clone/state/authState.dart';
1010
import 'package:flutter_twitter_clone/state/chats/chatState.dart';
11+
import 'package:flutter_twitter_clone/state/notificationState.dart';
12+
import 'package:flutter_twitter_clone/state/searchState.dart';
1113
import 'package:flutter_twitter_clone/widgets/customAppBar.dart';
1214
import 'package:flutter_twitter_clone/widgets/customWidgets.dart';
1315
import 'package:flutter_twitter_clone/widgets/newWidget/emptyList.dart';
@@ -29,7 +31,7 @@ class _ChatListPageState extends State<ChatListPage> {
2931
chatState.setIsChatScreenOpen = true;
3032

3133
// chatState.databaseInit(state.profileUserModel.userId,state.userId);
32-
chatState.getUserchatList(state.userModel.userId);
34+
chatState.getUserchatList(state.user.uid);
3335
super.initState();
3436
}
3537

@@ -40,10 +42,11 @@ class _ChatListPageState extends State<ChatListPage> {
4042
if (state.chatUserList == null) {
4143
return Padding(
4244
padding: EdgeInsets.symmetric(horizontal: 30),
43-
child:EmptyList(
44-
'No message available ',
45-
subTitle: 'When someonw sends you message,User list\'ll show up here \n To send message tap message.',
46-
)
45+
child: EmptyList(
46+
'No message available ',
47+
subTitle:
48+
'When someonw sends you message,User list\'ll show up here \n To send message tap message.',
49+
),
4750
);
4851
} else {
4952
return ListView.separated(
@@ -66,7 +69,13 @@ class _ChatListPageState extends State<ChatListPage> {
6669
contentPadding: EdgeInsets.symmetric(horizontal: 10),
6770
onTap: () {
6871
final chatState = Provider.of<ChatState>(context, listen: false);
72+
final searchState = Provider.of<SearchState>(context, listen: false);
6973
chatState.setChatUser = model;
74+
if (searchState.userlist.any((x) => x.userId == model.userId)) {
75+
chatState.setChatUser = searchState.userlist
76+
.where((x) => x.userId == model.userId)
77+
.first;
78+
}
7079
Navigator.pushNamed(context, '/ChatScreenPage');
7180
},
7281
leading: RippleButton(
@@ -100,14 +109,22 @@ class _ChatListPageState extends State<ChatListPage> {
100109
),
101110
);
102111
}
103-
FloatingActionButton _newMessageButton(){
112+
113+
FloatingActionButton _newMessageButton() {
104114
return FloatingActionButton(
105-
onPressed: (){
115+
onPressed: () {
106116
Navigator.of(context).pushNamed('/NewMessagePage');
107117
},
108-
child: customIcon(context,icon:AppIcon.newMessage,istwitterIcon: true, iconColor:Theme.of(context).colorScheme.onPrimary, size:25)
118+
child: customIcon(
119+
context,
120+
icon: AppIcon.newMessage,
121+
istwitterIcon: true,
122+
iconColor: Theme.of(context).colorScheme.onPrimary,
123+
size: 25,
124+
),
109125
);
110126
}
127+
111128
void onSettingIconPressed() {
112129
Navigator.pushNamed(context, '/DirectMessagesPage');
113130
}

lib/state/authState.dart

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class AuthState extends AppState {
4545
authStatus = AuthStatus.NOT_LOGGED_IN;
4646
userId = '';
4747
_userModel = null;
48+
user = null;
4849
_profileUserModelList = null;
4950
if (isSignInWithGoogle) {
5051
_googleSignIn.signOut();
@@ -190,13 +191,8 @@ class AuthState extends AppState {
190191

191192
// Time at which user is created
192193
user.createdAt = DateTime.now().toUtc().toString();
193-
/// Get firebase token
194-
/// Helps to send notification
195-
_firebaseMessaging.getToken().then((String token) {
196-
assert(token != null);
197-
user.fcmToken = token;
198-
});
199194
}
195+
200196
kDatabase.child('profile').child(user.userId).set(user.toJson());
201197
_userModel = user;
202198
if (_profileUserModelList != null) {
@@ -361,13 +357,7 @@ class AuthState extends AppState {
361357
reloadUser();
362358
}
363359
if (_userModel.fcmToken == null) {
364-
/// if firebase token not available in frofile
365-
/// Then get token from firebase and save it to profile
366-
_firebaseMessaging.getToken().then((String token) {
367-
assert(token != null);
368-
_userModel.fcmToken = token;
369-
createUser(_userModel);
370-
});
360+
updateFCMToken();
371361
}
372362
}
373363

@@ -382,6 +372,18 @@ class AuthState extends AppState {
382372
}
383373
}
384374

375+
/// if firebase token not available in frofile
376+
/// Then get token from firebase and save it to profile
377+
/// When someonw sends you a message FCM token is used
378+
void updateFCMToken() {
379+
getProfileUser(userProfileId: userId);
380+
_firebaseMessaging.getToken().then((String token) {
381+
assert(token != null);
382+
_userModel.fcmToken = token;
383+
createUser(_userModel);
384+
});
385+
}
386+
385387
/// Follow / Unfollow user
386388
///
387389
/// If `removeFollower` is true then remove user from follower list

0 commit comments

Comments
 (0)