fix listeners for thingy
This commit is contained in:
parent
9e399866a6
commit
574562b459
|
@ -1,4 +1,7 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:loris/pages/notifications/single_notif.dart';
|
||||
import '../../business_logic/websocket.dart' as websocket;
|
||||
|
||||
class Notifications extends StatefulWidget {
|
||||
|
@ -10,15 +13,33 @@ class Notifications extends StatefulWidget {
|
|||
|
||||
class _NotificationsState extends State<Notifications> {
|
||||
List<Widget> notifs = [];
|
||||
List subscriptions = [];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
void initState() {
|
||||
for (int i = 0; i < websocket.map.length; i++) {
|
||||
final keyI = websocket.map.keys.toList()[i];
|
||||
subscriptions.add(websocket.map[keyI]!["home"]!.stream.listen((event) {
|
||||
print(event);
|
||||
}));
|
||||
websocket.map[keyI]!["home"]!.stream.listen((event) async {
|
||||
Map<String, dynamic> json = jsonDecode(event);
|
||||
if (json["event"] == "notification") {
|
||||
SingleNotif notif = SingleNotif(
|
||||
content: jsonDecode(json["payload"]),
|
||||
);
|
||||
setState(() {
|
||||
notifs.insert(0, notif);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return Text("Notifs");
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.separated(
|
||||
itemBuilder: ((context, index) => notifs[index]),
|
||||
separatorBuilder: (context, index) => const SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
itemCount: notifs.length);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class SingleNotif extends StatelessWidget {
|
||||
const SingleNotif({
|
||||
required this.content,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
final Map<String, dynamic> content;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print(content);
|
||||
return Text(content["id"].toString());
|
||||
}
|
||||
}
|
|
@ -21,7 +21,6 @@ class TimelineState extends State<Timeline> {
|
|||
|
||||
@override
|
||||
void initState() {
|
||||
print("init");
|
||||
super.initState();
|
||||
children.add(const LoadingBox());
|
||||
fetchMore();
|
||||
|
|
Loading…
Reference in New Issue