48 lines
1.3 KiB
Dart
48 lines
1.3 KiB
Dart
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 {
|
|
const Notifications({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<Notifications> createState() => _NotificationsState();
|
|
}
|
|
|
|
class _NotificationsState extends State<Notifications> {
|
|
List<Widget> notifs = [];
|
|
|
|
@override
|
|
void initState() {
|
|
for (int i = 0; i < websocket.map.length; i++) {
|
|
final keyI = websocket.map.keys.toList()[i];
|
|
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"]),
|
|
);
|
|
if (mounted) {
|
|
setState(() {
|
|
notifs.insert(0, notif);
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
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);
|
|
}
|
|
}
|