Notification indicator

This commit is contained in:
2025-01-20 16:52:53 +08:00
parent 068ddcdcdc
commit 7f58710c6f
4 changed files with 92 additions and 6 deletions

View File

@ -8,14 +8,18 @@ import 'package:flutter_udid/flutter_udid.dart';
import 'package:provider/provider.dart';
import 'package:surface/providers/sn_network.dart';
import 'package:surface/providers/userinfo.dart';
import 'package:surface/providers/websocket.dart';
import 'package:surface/types/notification.dart';
class NotificationProvider extends ChangeNotifier {
late final SnNetworkProvider _sn;
late final UserProvider _ua;
late final WebSocketProvider _ws;
NotificationProvider(BuildContext context) {
_sn = context.read<SnNetworkProvider>();
_ua = context.read<UserProvider>();
_ws = context.read<WebSocketProvider>();
}
Future<void> registerPushNotifications() async {
@ -62,4 +66,21 @@ class NotificationProvider extends ChangeNotifier {
},
);
}
List<SnNotification> notifications = List.empty(growable: true);
void listen() {
_ws.stream.stream.listen((event) {
if (event.method == 'notifications.new') {
final notification = SnNotification.fromJson(event.payload!);
notifications.add(notification);
notifyListeners();
}
});
}
void clear() {
notifications.clear();
notifyListeners();
}
}