+ChangeNotifier Fixes
+Signout Fixes +
This commit is contained in:
@@ -16,15 +16,19 @@ class ConversationsPage extends StatefulWidget {
|
||||
ConversationsPage({
|
||||
super.key,
|
||||
required this.chatId,
|
||||
// required this.receiverId,
|
||||
required this.chatImage,
|
||||
required this.chatName,
|
||||
this.userId,
|
||||
required this.userName,
|
||||
required this.userImage,
|
||||
this.userEmail,
|
||||
// this.chatMessage,
|
||||
});
|
||||
|
||||
String chatId;
|
||||
// String receiverId;
|
||||
String chatName;
|
||||
String chatImage;
|
||||
String? userId;
|
||||
String userName;
|
||||
String userImage;
|
||||
String? userEmail;
|
||||
// Map? chatMessage;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
@@ -34,13 +38,12 @@ class ConversationsPage extends StatefulWidget {
|
||||
|
||||
class _ConversationsPageState extends State<ConversationsPage> {
|
||||
//
|
||||
|
||||
MessagingProviders _auth = MessagingProviders.instance;
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
late double _deviceHeight;
|
||||
late double _deviceWidth;
|
||||
|
||||
final ScrollController _scrollController;
|
||||
final GlobalKey<FormState> _formKey;
|
||||
late MessagingProviders _auth;
|
||||
List<List<Messages>> _messagesArray;
|
||||
List<Messages> _messages;
|
||||
List<String> _members;
|
||||
@@ -49,8 +52,6 @@ class _ConversationsPageState extends State<ConversationsPage> {
|
||||
|
||||
_ConversationsPageState()
|
||||
: _messageText = '',
|
||||
_formKey = GlobalKey<FormState>(),
|
||||
_scrollController = ScrollController(),
|
||||
_messagesArray = [],
|
||||
_messages = [],
|
||||
_members = [],
|
||||
@@ -64,12 +65,46 @@ class _ConversationsPageState extends State<ConversationsPage> {
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => Dialog(
|
||||
child: SizedBox(
|
||||
height: _deviceHeight * 0.25,
|
||||
width: _deviceHeight * 0.25,
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
// padding: EdgeInsets.all(20),
|
||||
height: _deviceHeight * 0.20,
|
||||
width: _deviceHeight * 0.20,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
image: DecorationImage(
|
||||
image: NetworkImage(widget.userImage),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(widget.userName),
|
||||
Text(widget.userEmail!)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: Icon(Icons.info_outline),
|
||||
)
|
||||
],
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
title: Text(widget.chatName),
|
||||
title: Text(widget.userName),
|
||||
titleTextStyle: TextStyle(fontSize: 16),
|
||||
),
|
||||
body: ChangeNotifierProvider<MessagingProviders>.value(
|
||||
value: MessagingProviders.instance,
|
||||
value: _auth,
|
||||
child: _conversationPageUI(),
|
||||
),
|
||||
);
|
||||
@@ -92,11 +127,11 @@ class _ConversationsPageState extends State<ConversationsPage> {
|
||||
}
|
||||
|
||||
Widget _messageListView() {
|
||||
return Container(
|
||||
return SizedBox(
|
||||
height: _deviceHeight * 0.80,
|
||||
width: _deviceWidth,
|
||||
child: StreamBuilder<Chats>(
|
||||
stream: MessagingProviders.instance.getMessage(widget.chatId),
|
||||
stream: _auth.getMessage(widget.chatId),
|
||||
builder: (_context, _snapshot) {
|
||||
if (_snapshot.hasData) {
|
||||
_members = _snapshot.data!.members;
|
||||
@@ -110,6 +145,15 @@ class _ConversationsPageState extends State<ConversationsPage> {
|
||||
child: Text("No Chat"),
|
||||
);
|
||||
} else {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_scrollController.hasClients) {
|
||||
_scrollController.animateTo(
|
||||
_scrollController.position.maxScrollExtent,
|
||||
duration: const Duration(microseconds: 500),
|
||||
curve: Curves.fastOutSlowIn);
|
||||
}
|
||||
});
|
||||
|
||||
return ListView.builder(
|
||||
controller: _scrollController,
|
||||
padding: EdgeInsets.symmetric(
|
||||
@@ -203,7 +247,7 @@ class _ConversationsPageState extends State<ConversationsPage> {
|
||||
Widget _imageMessageBubble(bool _isOwnMessage, Messages _message) {
|
||||
List<Color> _colorScheme = _isOwnMessage
|
||||
? [Colors.blue, Color.fromRGBO(42, 117, 188, 1)]
|
||||
: [Color.fromRGBO(49, 69, 69, 1), Color.fromRGBO(43, 43, 43, 1)];
|
||||
: [Color.fromRGBO(49, 69, 69, 1), Color.fromRGBO(249, 249, 249, 1)];
|
||||
return Container(
|
||||
// height: _deviceHeight * 0.10,
|
||||
// width: _deviceWidth * 0.75,
|
||||
@@ -236,6 +280,7 @@ class _ConversationsPageState extends State<ConversationsPage> {
|
||||
height: 10,
|
||||
),
|
||||
Text(
|
||||
// '${DateTime.parse(_message.timeStamp).day}',
|
||||
timeago.format(DateTime.parse(_message.timeStamp)),
|
||||
style: TextStyle(color: Colors.white70, fontSize: 10),
|
||||
),
|
||||
@@ -253,7 +298,7 @@ class _ConversationsPageState extends State<ConversationsPage> {
|
||||
image: DecorationImage(
|
||||
fit: BoxFit.cover,
|
||||
image: NetworkImage(
|
||||
widget.chatImage,
|
||||
widget.userImage,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -318,7 +363,7 @@ class _ConversationsPageState extends State<ConversationsPage> {
|
||||
}
|
||||
|
||||
Widget _sendText(BuildContext _context) {
|
||||
return Container(
|
||||
return SizedBox(
|
||||
height: _deviceHeight * 0.045,
|
||||
width: _deviceHeight * 0.045,
|
||||
child: IconButton(
|
||||
@@ -349,8 +394,7 @@ class _ConversationsPageState extends State<ConversationsPage> {
|
||||
onPressed: () async {
|
||||
XFile? _imageFile = await MediaService.instance.getImageFromLibrary();
|
||||
if (_imageFile != null) {
|
||||
var _url = await MessagingProviders.instance
|
||||
.uploadUserImage(_imageFile, '_uid');
|
||||
var _url = await _auth.uploadUserImage(_imageFile, '_uid');
|
||||
|
||||
await sendMessage('image', _url);
|
||||
}
|
||||
@@ -387,9 +431,7 @@ class _ConversationsPageState extends State<ConversationsPage> {
|
||||
}
|
||||
|
||||
await _auth.sendMessage(
|
||||
widget.chatId,
|
||||
{"messages": outMessages},
|
||||
);
|
||||
widget.chatId, {"messages": outMessages}, 'update');
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -397,7 +439,30 @@ class _ConversationsPageState extends State<ConversationsPage> {
|
||||
}
|
||||
|
||||
Future<void> sendMessage(var type, var _message) async {
|
||||
List outMessages = [];
|
||||
List _outMessages = [];
|
||||
|
||||
if (_members.isEmpty) {
|
||||
_members = [_auth.user!.$id, widget.userId!];
|
||||
|
||||
List<String> messagesTemp = [];
|
||||
messagesTemp = [
|
||||
json.encode({
|
||||
_auth.user!.$id: [],
|
||||
}),
|
||||
json.encode({
|
||||
widget.userId: [],
|
||||
})
|
||||
];
|
||||
|
||||
Map<String, dynamic> _chat = {
|
||||
"ownerId": _auth.user!.$id,
|
||||
"members": _members,
|
||||
"messages": messagesTemp
|
||||
};
|
||||
|
||||
await _auth.sendMessage(widget.chatId, _chat, 'new');
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
}
|
||||
|
||||
for (var i = 0; i < _members.length; i++) {
|
||||
_messagesArray[i].add(
|
||||
@@ -409,7 +474,7 @@ class _ConversationsPageState extends State<ConversationsPage> {
|
||||
),
|
||||
);
|
||||
|
||||
outMessages.add(
|
||||
_outMessages.add(
|
||||
json.encode(
|
||||
{_members[i]: _messagesArray[i]},
|
||||
),
|
||||
@@ -418,7 +483,8 @@ class _ConversationsPageState extends State<ConversationsPage> {
|
||||
|
||||
await _auth.sendMessage(
|
||||
widget.chatId,
|
||||
{"messages": outMessages},
|
||||
{"messages": _outMessages},
|
||||
'update',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user