mirror of
https://github.com/nostrlabs-io/zap-stream-flutter.git
synced 2025-06-16 11:58:50 +00:00
feat: notify keys
This commit is contained in:
57
lib/widgets/notifications_button.dart
Normal file
57
lib/widgets/notifications_button.dart
Normal file
@ -0,0 +1,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:zap_stream_flutter/notifications.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
import 'package:zap_stream_flutter/utils.dart';
|
||||
|
||||
class NotificationsButtonWidget extends StatefulWidget {
|
||||
final StreamEvent stream;
|
||||
|
||||
const NotificationsButtonWidget({super.key, required this.stream});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _NotificationsButtonWidget();
|
||||
}
|
||||
|
||||
class _NotificationsButtonWidget extends State<NotificationsButtonWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: () async {
|
||||
final n = getNotificationService();
|
||||
return await n?.getWatchedKeys();
|
||||
}(),
|
||||
builder: (context, state) {
|
||||
if (state.data == null) {
|
||||
return SizedBox.shrink();
|
||||
} else {
|
||||
final isNotified = (state.data ?? []).contains(
|
||||
widget.stream.info.host,
|
||||
);
|
||||
return IconButton(
|
||||
iconSize: 20,
|
||||
onPressed: () async {
|
||||
final n = getNotificationService();
|
||||
if (n == null) return;
|
||||
|
||||
if (isNotified) {
|
||||
await n.removeWatchPubkey(widget.stream.info.host);
|
||||
} else {
|
||||
await n.watchPubkey(widget.stream.info.host, [30311]);
|
||||
}
|
||||
setState(() {
|
||||
// reload widget
|
||||
});
|
||||
},
|
||||
style: ButtonStyle(
|
||||
padding: WidgetStatePropertyAll(EdgeInsets.all(0)),
|
||||
backgroundColor: WidgetStateColor.resolveWith((_) => LAYER_2),
|
||||
),
|
||||
icon: Icon(
|
||||
isNotified ? Icons.notifications_off : Icons.notification_add,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user