2026-04-24 08:29:12 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
|
|
|
|
|
import '../i18n/strings.g.dart';
|
|
|
|
|
import '../models/trackers/device_code.dart';
|
|
|
|
|
import '../utils/snackbar_helper.dart';
|
2026-07-26 05:44:35 +02:00
|
|
|
import 'pending_auth_dialog.dart';
|
2026-04-24 08:29:12 +02:00
|
|
|
|
2026-08-09 20:33:30 +02:00
|
|
|
/// Shared device-code activation dialog for Trakt, Simkl, and MDBList
|
|
|
|
|
/// (RFC 8628).
|
2026-04-24 08:29:12 +02:00
|
|
|
///
|
2026-08-09 20:33:30 +02:00
|
|
|
/// The [PendingAuthDialog] shell contributes the QR code (encoding the
|
|
|
|
|
/// code-prefilled verification URL when the service provides one), the
|
|
|
|
|
/// readable copyable verification URL, the browser launch button, and the
|
|
|
|
|
/// "waiting for authorization…" spinner; this dialog adds the `userCode` with
|
|
|
|
|
/// copy-to-clipboard. Dismissing calls [onCancel] so the provider can abort
|
|
|
|
|
/// the poll.
|
2026-04-24 08:29:12 +02:00
|
|
|
class DeviceCodeDialog extends StatelessWidget {
|
|
|
|
|
final DeviceCode code;
|
|
|
|
|
final String serviceName;
|
|
|
|
|
final VoidCallback onCancel;
|
|
|
|
|
|
2026-04-24 14:19:07 +02:00
|
|
|
const DeviceCodeDialog({super.key, required this.code, required this.serviceName, required this.onCancel});
|
2026-04-24 08:29:12 +02:00
|
|
|
|
|
|
|
|
Future<void> _copy(BuildContext context) async {
|
|
|
|
|
await Clipboard.setData(ClipboardData(text: code.userCode));
|
|
|
|
|
if (!context.mounted) return;
|
2026-07-10 07:09:29 +02:00
|
|
|
showAppSnackBar(context, t.services.deviceCode.codeCopied);
|
2026-04-24 08:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final theme = Theme.of(context);
|
2026-07-26 05:44:35 +02:00
|
|
|
return PendingAuthDialog(
|
|
|
|
|
title: t.services.deviceCode.title(service: serviceName),
|
2026-08-09 20:33:30 +02:00
|
|
|
body: t.services.deviceCode.instructions,
|
2026-07-26 05:44:35 +02:00
|
|
|
url: code.verificationUrlComplete ?? code.verificationUrl,
|
2026-08-09 20:33:30 +02:00
|
|
|
displayUrl: code.verificationUrl,
|
2026-07-26 05:44:35 +02:00
|
|
|
openLabel: t.services.deviceCode.openToActivate(service: serviceName),
|
|
|
|
|
onCancel: onCancel,
|
|
|
|
|
children: [
|
|
|
|
|
Center(
|
|
|
|
|
child: CopyTapRegion(
|
|
|
|
|
onCopy: () => _copy(context),
|
|
|
|
|
semanticLabel: t.services.deviceCode.copyCode,
|
2026-07-26 19:41:23 +02:00
|
|
|
semanticValue: code.userCode,
|
2026-07-26 05:44:35 +02:00
|
|
|
child: Padding(
|
2026-08-09 20:33:30 +02:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
|
|
|
// Scale down instead of wrapping: user codes vary in length and
|
|
|
|
|
// a wrapped activation code reads as two codes.
|
|
|
|
|
child: FittedBox(
|
|
|
|
|
fit: BoxFit.scaleDown,
|
|
|
|
|
child: Text(
|
|
|
|
|
code.userCode,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
style: theme.textTheme.displaySmall?.copyWith(
|
|
|
|
|
fontFeatures: const [FontFeature.tabularFigures()],
|
|
|
|
|
letterSpacing: 4,
|
|
|
|
|
fontWeight: .w600,
|
|
|
|
|
),
|
2026-04-24 08:29:12 +02:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-07-26 05:44:35 +02:00
|
|
|
const SizedBox(height: 16),
|
2026-04-24 08:29:12 +02:00
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|