+ChangeNotifier Fixes
+Signout Fixes +
This commit is contained in:
+96
-123
@@ -1,5 +1,3 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:messaging_app/components/messaging_provider.dart';
|
||||
import 'package:messaging_app/models/users.dart';
|
||||
@@ -18,7 +16,6 @@ class SearchPage extends StatefulWidget {
|
||||
|
||||
double deviceHeight;
|
||||
double deviceWidth;
|
||||
late MessagingProviders _auth;
|
||||
|
||||
@override
|
||||
State<SearchPage> createState() => _SearchPageState();
|
||||
@@ -27,6 +24,7 @@ class SearchPage extends StatefulWidget {
|
||||
class _SearchPageState extends State<SearchPage> {
|
||||
late String _searchText;
|
||||
late List<User> _usersData;
|
||||
MessagingProviders _auth = MessagingProviders.instance;
|
||||
//
|
||||
@override
|
||||
void initState() {
|
||||
@@ -42,7 +40,7 @@ class _SearchPageState extends State<SearchPage> {
|
||||
height: widget.deviceHeight,
|
||||
width: widget.deviceWidth,
|
||||
child: ChangeNotifierProvider.value(
|
||||
value: MessagingProviders.instance,
|
||||
value: _auth,
|
||||
child: _searchPaheUI(),
|
||||
),
|
||||
),
|
||||
@@ -51,7 +49,7 @@ class _SearchPageState extends State<SearchPage> {
|
||||
|
||||
Widget _searchPaheUI() {
|
||||
return Builder(builder: (_context) {
|
||||
widget._auth = Provider.of<MessagingProviders>(_context);
|
||||
_auth = Provider.of<MessagingProviders>(_context);
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
@@ -68,7 +66,9 @@ class _SearchPageState extends State<SearchPage> {
|
||||
return Container(
|
||||
height: widget.deviceHeight * 0.08,
|
||||
width: widget.deviceWidth,
|
||||
padding: EdgeInsets.symmetric(vertical: widget.deviceHeight * 0.02),
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: widget.deviceHeight * 0.02,
|
||||
),
|
||||
child: TextField(
|
||||
autocorrect: false,
|
||||
style: TextStyle(
|
||||
@@ -91,133 +91,106 @@ class _SearchPageState extends State<SearchPage> {
|
||||
|
||||
Widget _searchPageUIList() {
|
||||
return StreamBuilder<List<User>>(
|
||||
stream: MessagingProviders.instance.getAllUsers(_searchText.trim()),
|
||||
stream: _auth.getAllUsers(_searchText.trim()),
|
||||
builder: (_, _snapshot) {
|
||||
if (_snapshot.hasData) {
|
||||
_usersData = _snapshot.data!
|
||||
.where((_data) => _data.id != widget._auth.user!.$id)
|
||||
.where((_data) => _data.id != _auth.user!.$id)
|
||||
.toList();
|
||||
}
|
||||
return _snapshot.hasData
|
||||
? SizedBox(
|
||||
height: widget.deviceHeight * 0.70,
|
||||
child: ListView.builder(
|
||||
itemCount: _usersData.length,
|
||||
itemBuilder: (_, _index) {
|
||||
var _userData = _usersData[_index];
|
||||
var _isUserActive = _userData.lastSeen.isBefore(
|
||||
DateTime.now().toUtc().subtract(
|
||||
Duration(
|
||||
minutes: 1,
|
||||
),
|
||||
),
|
||||
);
|
||||
return ListTile(
|
||||
enabled: true,
|
||||
onTap: () async {
|
||||
String _chatId;
|
||||
String _linkId =
|
||||
'${widget._auth.user!.$id}${_userData.id}';
|
||||
|
||||
_chatId = await MessagingProviders.instance
|
||||
.getConversationLink(
|
||||
_linkId.substring(0, 36));
|
||||
|
||||
if (_chatId.isEmpty) {
|
||||
List<dynamic> _members = [
|
||||
widget._auth.user!.$id,
|
||||
_userData.id
|
||||
];
|
||||
|
||||
List<String> messagesTemp = [];
|
||||
messagesTemp = [
|
||||
json.encode({
|
||||
widget._auth.user!.$id: [],
|
||||
}),
|
||||
json.encode({
|
||||
_userData.id: [],
|
||||
})
|
||||
];
|
||||
|
||||
Map<String, dynamic> _chat = {
|
||||
"ownerId": widget._auth.user!.$id,
|
||||
"members": _members,
|
||||
"messages": messagesTemp
|
||||
};
|
||||
_chatId = await MessagingProviders.instance
|
||||
.newMesaage(_chat);
|
||||
}
|
||||
|
||||
NavigationService.instance.navigateToRoute(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext _context) {
|
||||
return ConversationsPage(
|
||||
chatId: _chatId,
|
||||
chatName: _userData.name,
|
||||
chatImage: _userData.image,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
title: Text(_userData.name),
|
||||
leading: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
image: DecorationImage(
|
||||
fit: BoxFit.cover,
|
||||
image: NetworkImage(_userData.image),
|
||||
),
|
||||
? SizedBox(
|
||||
height: widget.deviceHeight * 0.70,
|
||||
child: ListView.builder(
|
||||
itemCount: _usersData.length,
|
||||
itemBuilder: (_, _index) {
|
||||
var _userData = _usersData[_index];
|
||||
var _isUserActive = _userData.lastSeen.isBefore(
|
||||
DateTime.now().toUtc().subtract(
|
||||
Duration(
|
||||
minutes: 1,
|
||||
),
|
||||
),
|
||||
trailing: Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
_isUserActive
|
||||
? Text(
|
||||
"last seen",
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
"active",
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
_isUserActive
|
||||
? Text(
|
||||
timeago.format(
|
||||
_userData.lastSeen,
|
||||
),
|
||||
style: TextStyle(fontSize: 15),
|
||||
)
|
||||
: Container(
|
||||
height: 10,
|
||||
width: 10,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue,
|
||||
borderRadius:
|
||||
BorderRadius.circular(100),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
return ListTile(
|
||||
enabled: true,
|
||||
onTap: () async {
|
||||
List _linkId = [
|
||||
_auth.user!.$id.substring(0, 18),
|
||||
_userData.id.substring(0, 18)
|
||||
];
|
||||
_linkId.sort();
|
||||
|
||||
NavigationService.instance.navigateToRoute(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext _context) {
|
||||
return ConversationsPage(
|
||||
chatId: _linkId.join(),
|
||||
userId: _userData.id,
|
||||
userName: _userData.name,
|
||||
userImage: _userData.image,
|
||||
userEmail: _userData.email,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}),
|
||||
)
|
||||
: Container()
|
||||
// : SpinKitWanderingCubes(
|
||||
// color: Colors.blue,
|
||||
// size: 50.0,
|
||||
// );
|
||||
;
|
||||
},
|
||||
title: Text(_userData.name),
|
||||
leading: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
image: DecorationImage(
|
||||
fit: BoxFit.cover,
|
||||
image: NetworkImage(_userData.image),
|
||||
),
|
||||
),
|
||||
),
|
||||
trailing: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
_isUserActive
|
||||
? Text(
|
||||
"last seen",
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
"active",
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
_isUserActive
|
||||
? Text(
|
||||
timeago.format(
|
||||
_userData.lastSeen,
|
||||
),
|
||||
style: TextStyle(fontSize: 15),
|
||||
)
|
||||
: Container(
|
||||
height: 10,
|
||||
width: 10,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue,
|
||||
borderRadius:
|
||||
BorderRadius.circular(100),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
)
|
||||
: Container();
|
||||
// : SpinKitWanderingCubes(
|
||||
// color: Colors.blue,
|
||||
// size: 50.0,
|
||||
// );
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user