onLogout method

Future<void> onLogout(
  1. dynamic context,
  2. dynamic ref
)

Implementation

Future<void> onLogout(BuildContext context, WidgetRef ref) async {
  TextEditingController passwordController = TextEditingController();
  final result = await showDialog<bool>(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        backgroundColor: Theme.of(context).colorScheme.surface,
        title: Text(L10n.of(context).authenticationRequired),
        content: Wrap(
          children: [
            Text(L10n.of(context).pleaseProvideYourUserPassword),
            TextField(
              controller: passwordController,
              obscureText: true,
              decoration: InputDecoration(
                hintText: L10n.of(context).password,
              ),
            ),
          ],
        ),
        actions: [
          OutlinedButton(
            child: Text(L10n.of(context).cancel),
            onPressed: () {
              if (context.mounted) {
                Navigator.pop(context, false);
              }
            },
          ),
          ActerPrimaryActionButton(
            child: Text(L10n.of(context).ok),
            onPressed: () {
              if (passwordController.text.isEmpty) {
                return;
              }
              if (context.mounted) {
                Navigator.pop(context, true);
              }
            },
          ),
        ],
      );
    },
  );
  if (result != true) {
    return;
  }
  final client = ref.read(alwaysClientProvider);
  final manager = client.sessionManager();
  await manager.deleteDevice(
    deviceRecord.deviceId().toString(),
    client.userId().toString(),
    passwordController.text,
  );
  ref.invalidate(allSessionsProvider); // DeviceUpdates doesn’t cover logout
}