Initial commit
This commit is contained in:
166
lib/screen/pages/talk/chatOverview.dart
Normal file
166
lib/screen/pages/talk/chatOverview.dart
Normal file
@ -0,0 +1,166 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:marianum_mobile/data/outgoingPackets/talkContactsAskPacket.dart';
|
||||
import 'package:marianum_mobile/widget/loadingPacket.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../data/accountModel.dart';
|
||||
import '../../../data/incommingPackets/talkContactsPacket.dart';
|
||||
import '../../../widget/loadingSpinner.dart';
|
||||
import 'chatView.dart';
|
||||
|
||||
class Talk extends StatefulWidget {
|
||||
const Talk({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Talk> createState() => _TalkState();
|
||||
}
|
||||
|
||||
class _TalkState extends State<Talk> {
|
||||
// List<ChatData> chats = List<ChatData>.empty(growable: true);
|
||||
//
|
||||
// Future<List<ChatData>> getChats() async {
|
||||
// var url = Uri.https("***REMOVED***:***REMOVED***@mhsl.eu", "marianum/app/middleware/chat.php");
|
||||
// var response = await http.get(
|
||||
// url,
|
||||
// headers: (
|
||||
// {
|
||||
// "Accept": "application/json",
|
||||
// "OCS-APIRequest": "true",
|
||||
// }
|
||||
// ),
|
||||
// );
|
||||
//
|
||||
// return compute(parseChats, response.body);
|
||||
// }
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
Provider.of<TalkContactsPaket>(context, listen: false).invoke();
|
||||
//TalkContactsAskPacket().send();
|
||||
super.initState();
|
||||
// Future.delayed(Duration.zero).then((context) => updateChats());
|
||||
// Provider.of<AccountModel>(context, listen: false).channel.sink.add("chat");
|
||||
|
||||
}
|
||||
|
||||
void updateChats() {
|
||||
// var chats = getChats();
|
||||
//
|
||||
// showDialog(
|
||||
// context: context,
|
||||
// barrierDismissible: false,
|
||||
// builder: (BuildContext context) {
|
||||
// return const LoadingSpinner();
|
||||
// }
|
||||
// );
|
||||
//
|
||||
// chats.then((value) =>
|
||||
// setState(() {
|
||||
// Navigator.pop(context);
|
||||
// this.chats.clear();
|
||||
// this.chats = value;
|
||||
// })
|
||||
// );
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// List<ListTile> chats = List<ListTile>.empty(growable: true);
|
||||
//
|
||||
// for (var element in this.chats) {
|
||||
// chats.add(
|
||||
// ListTile(
|
||||
// leading: element.type == 1 ? CircleAvatar(
|
||||
// backgroundColor: Colors.grey,
|
||||
// foregroundImage: Image.network(element.avatar).image,
|
||||
// ) : const Icon(Icons.group),
|
||||
// title: Text(element.name),
|
||||
// subtitle: Text(
|
||||
// "${element.lastMessageAuthor}: ${element.lastMessage.replaceAll("\n", "")}",
|
||||
// overflow: TextOverflow.ellipsis,
|
||||
// ),
|
||||
// onTap: () {
|
||||
// Navigator.push(context, MaterialPageRoute(builder: (builder) => const ChatView()));
|
||||
// },
|
||||
// trailing: element.unreadMessages > 0 ? const Icon(Icons.mark_chat_unread) : Text(element.lastActivity),
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// return ListView(
|
||||
// children: chats,
|
||||
// );
|
||||
|
||||
return Consumer<TalkContactsPaket>(
|
||||
builder: (context, data, child) {
|
||||
List<ListTile> chats = List<ListTile>.empty(growable: true);
|
||||
|
||||
for (var element in data.contacts) {
|
||||
chats.add(ListTile(
|
||||
title: Text(element.name),
|
||||
subtitle: Text("${element.lastTime}: ${element.lastMessage}".replaceAll("\n", " "), overflow: TextOverflow.ellipsis),
|
||||
trailing: element.unreadMessages ? const Icon(Icons.new_releases_outlined) : null,
|
||||
leading: CircleAvatar(
|
||||
foregroundImage: element.isGroup ? null : Image.network(element.profilePicture).image,
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
child: element.isGroup ? const Icon(Icons.group) : const Icon(Icons.person),
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (context) {
|
||||
return ChatView(
|
||||
userToken: element.userToken,
|
||||
);
|
||||
}));
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
return LoadingPacket(packet: data, child: ListView(children: chats));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// List<ChatData> parseChats(String json) {
|
||||
// final parsed = jsonDecode(json).cast<Map<String, dynamic>>();
|
||||
// return parsed.map<ChatData>((a) => ChatData.fromJson(a)).toList();
|
||||
// }
|
||||
//
|
||||
// class ChatData {
|
||||
// final String name;
|
||||
// final String lastMessage;
|
||||
// final String lastMessageAuthor;
|
||||
// final String avatar;
|
||||
// final int type;
|
||||
// final String lastActivity;
|
||||
// final int unreadMessages;
|
||||
//
|
||||
// const ChatData({
|
||||
// required this.name,
|
||||
// required this.lastMessage,
|
||||
// required this.lastMessageAuthor,
|
||||
// required this.avatar,
|
||||
// required this.type,
|
||||
// required this.lastActivity,
|
||||
// required this.unreadMessages,
|
||||
// });
|
||||
//
|
||||
// factory ChatData.fromJson(Map<String, dynamic> json) {
|
||||
// return ChatData(
|
||||
// name: json['name'] as String,
|
||||
// lastMessage: json['last_message'] as String,
|
||||
// lastMessageAuthor: json['last_message_author'] as String,
|
||||
// avatar: json['avatar'] as String,
|
||||
// type: json['type'] as int,
|
||||
// lastActivity: json['lastActivity'] as String,
|
||||
// unreadMessages: json['unreadMessages'] as int,
|
||||
// );
|
||||
// }
|
||||
// }
|
101
lib/screen/pages/talk/chatView.dart
Normal file
101
lib/screen/pages/talk/chatView.dart
Normal file
@ -0,0 +1,101 @@
|
||||
|
||||
import 'package:bubble/bubble.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marianum_mobile/data/incommingPackets/talkChatPacket.dart';
|
||||
import 'package:marianum_mobile/widget/loadingPacket.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ChatView extends StatefulWidget {
|
||||
final String userToken;
|
||||
const ChatView({Key? key, required this.userToken}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ChatView> createState() => _ChatViewState();
|
||||
}
|
||||
|
||||
class _ChatViewState extends State<ChatView> {
|
||||
static const styleSystem = BubbleStyle(
|
||||
color: Color.fromRGBO(212, 234, 244, 1.0),
|
||||
borderWidth: 1,
|
||||
elevation: 2,
|
||||
margin: BubbleEdges.only(top: 15),
|
||||
alignment: Alignment.center,
|
||||
);
|
||||
|
||||
static const styleOther = BubbleStyle(
|
||||
nip: BubbleNip.leftBottom,
|
||||
color: Colors.white,
|
||||
borderWidth: 1,
|
||||
elevation: 2,
|
||||
margin: BubbleEdges.only(top: 15, left: 10),
|
||||
alignment: Alignment.topLeft,
|
||||
);
|
||||
|
||||
static const styleSelf = BubbleStyle(
|
||||
nip: BubbleNip.rightBottom,
|
||||
color: Color.fromRGBO(225, 255, 199, 1.0),
|
||||
borderWidth: 1,
|
||||
elevation: 2,
|
||||
margin: BubbleEdges.only(top: 15, right: 10),
|
||||
alignment: Alignment.topRight,
|
||||
);
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
Provider.of<TalkChatPacket>(context, listen: false).invoke(
|
||||
data: {
|
||||
"token": widget.userToken
|
||||
},
|
||||
indicateLoading: true,
|
||||
allowNotifyListeners: false,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.grey,
|
||||
appBar: AppBar(
|
||||
title: const Text("Chat mit jemandem"),
|
||||
),
|
||||
body: Consumer<TalkChatPacket>(
|
||||
builder: (context, data, child) {
|
||||
List<Bubble> messages = List<Bubble>.empty(growable: true);
|
||||
|
||||
data.messages.forEach((element) {
|
||||
messages.add(Bubble(
|
||||
style: styleSelf,
|
||||
child: Text(element.content),
|
||||
));
|
||||
});
|
||||
|
||||
return LoadingPacket(packet: data, child: ListView(
|
||||
children: [],
|
||||
));
|
||||
},
|
||||
),
|
||||
|
||||
|
||||
|
||||
// ListView(
|
||||
// children: [
|
||||
// Bubble(
|
||||
// style: styleSystem,
|
||||
// child: const Text("Chat gestartet"),
|
||||
// ),
|
||||
// Bubble(
|
||||
// style: styleOther,
|
||||
// child: const Text("Hi, das ist ein Testtext"),
|
||||
// ),
|
||||
// Bubble(
|
||||
// style: styleSelf,
|
||||
// child: Text(widget.userToken),
|
||||
// )
|
||||
// ],
|
||||
// ),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user