feat: Implement deleting pushers in app

This commit is contained in:
Christian Pauly 2022-07-22 11:01:58 +02:00
parent 839711bb9b
commit 534c84db7d
2 changed files with 38 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:collection/collection.dart' show IterableExtension; import 'package:collection/collection.dart' show IterableExtension;
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
@ -94,6 +95,40 @@ class SettingsNotificationsController extends State<SettingsNotifications> {
); );
} }
void onPusherTap(Pusher pusher) async {
final delete = await showModalActionSheet<bool>(
context: context,
title: pusher.deviceDisplayName,
message: '${pusher.appDisplayName} (${pusher.appId})',
actions: [
SheetAction(
label: L10n.of(context)!.delete,
isDestructiveAction: true,
key: true,
)
],
);
if (delete != true) return;
final success = await showFutureLoadingDialog(
context: context,
future: () => Matrix.of(context).client.deletePusher(
PusherId(
appId: pusher.appId,
pushkey: pusher.pushkey,
),
),
);
if (success.error != null) return;
setState(() {
pusherFuture = null;
});
}
Future<List<Pusher>?>? pusherFuture;
@override @override
Widget build(BuildContext context) => SettingsNotificationsView(this); Widget build(BuildContext context) => SettingsNotificationsView(this);
} }

View File

@ -77,7 +77,8 @@ class SettingsNotificationsView extends StatelessWidget {
), ),
), ),
FutureBuilder<List<Pusher>?>( FutureBuilder<List<Pusher>?>(
future: Matrix.of(context).client.getPushers(), future: controller.pusherFuture ??=
Matrix.of(context).client.getPushers(),
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.hasError) { if (snapshot.hasError) {
Center( Center(
@ -100,6 +101,7 @@ class SettingsNotificationsView extends StatelessWidget {
title: Text( title: Text(
'${pushers[i].appDisplayName} - ${pushers[i].appId}'), '${pushers[i].appDisplayName} - ${pushers[i].appId}'),
subtitle: Text(pushers[i].data.url.toString()), subtitle: Text(pushers[i].data.url.toString()),
onTap: () => controller.onPusherTap(pushers[i]),
), ),
); );
}, },