mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-29 05:03:05 +03:00
unify android add oath account flow
This commit is contained in:
parent
fb04f2c8d0
commit
83716a6e8e
@ -32,11 +32,34 @@ import '../../exception/cancellation_exception.dart';
|
||||
import '../../exception/platform_exception_decoder.dart';
|
||||
import '../../oath/models.dart';
|
||||
import '../../oath/state.dart';
|
||||
import '../qr_scanner/qr_scanner_provider.dart';
|
||||
|
||||
final _log = Logger('android.oath.state');
|
||||
|
||||
const _methods = MethodChannel('android.oath.methods');
|
||||
|
||||
// handles adding account on Android
|
||||
final androidAddAccountFlowProvider =
|
||||
Provider<void Function(BuildContext)>((ref) => (context) async {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final withContext = ref.read(withContextProvider);
|
||||
final qrScanner = ref.read(qrScannerProvider);
|
||||
if (qrScanner != null) {
|
||||
try {
|
||||
final qrData = await qrScanner.scanQr();
|
||||
await AndroidQrScanner.handleScannedData(
|
||||
qrData, withContext, qrScanner, l10n);
|
||||
} on CancellationException catch (_) {
|
||||
//ignored - user cancelled
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// no QR scanner - enter data manually
|
||||
await AndroidQrScanner.showAccountManualEntryDialog(
|
||||
withContext, l10n);
|
||||
}
|
||||
});
|
||||
|
||||
final androidOathStateProvider = AsyncNotifierProvider.autoDispose
|
||||
.family<OathStateNotifier, OathState, DevicePath>(
|
||||
_AndroidOathStateNotifier.new);
|
||||
|
@ -19,6 +19,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../android/app_methods.dart';
|
||||
import '../../android/oath/state.dart';
|
||||
import '../../android/qr_scanner/qr_scanner_provider.dart';
|
||||
import '../../android/state.dart';
|
||||
import '../../core/state.dart';
|
||||
@ -102,22 +103,7 @@ class MainPage extends ConsumerWidget {
|
||||
icon: const Icon(Icons.person_add_alt_1),
|
||||
tooltip: l10n.s_add_account,
|
||||
onPressed: () async {
|
||||
final withContext = ref.read(withContextProvider);
|
||||
final qrScanner = ref.read(qrScannerProvider);
|
||||
if (qrScanner != null) {
|
||||
try {
|
||||
final qrData = await qrScanner.scanQr();
|
||||
await AndroidQrScanner.handleScannedData(
|
||||
qrData, withContext, qrScanner, l10n);
|
||||
} on CancellationException catch (_) {
|
||||
// ignored - user cancelled
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// no QR scanner - enter data manually
|
||||
await AndroidQrScanner.showAccountManualEntryDialog(
|
||||
withContext, l10n);
|
||||
}
|
||||
ref.read(androidAddAccountFlowProvider)(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -18,6 +18,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../android/oath/state.dart';
|
||||
import '../../android/qr_scanner/qr_scanner_provider.dart';
|
||||
import '../../app/message.dart';
|
||||
import '../../app/models.dart';
|
||||
@ -59,17 +60,7 @@ Widget oathBuildActions(
|
||||
? (context) async {
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
if (isAndroid) {
|
||||
final withContext = ref.read(withContextProvider);
|
||||
final qrScanner = ref.read(qrScannerProvider);
|
||||
if (qrScanner != null) {
|
||||
final qrData = await qrScanner.scanQr();
|
||||
await AndroidQrScanner.handleScannedData(
|
||||
qrData, withContext, qrScanner, l10n);
|
||||
} else {
|
||||
// no QR scanner - enter data manually
|
||||
await AndroidQrScanner.showAccountManualEntryDialog(
|
||||
withContext, l10n);
|
||||
}
|
||||
ref.read(androidAddAccountFlowProvider)(context);
|
||||
} else {
|
||||
await showBlurDialog(
|
||||
context: context,
|
||||
|
@ -22,6 +22,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../android/oath/state.dart';
|
||||
import '../../app/message.dart';
|
||||
import '../../app/models.dart';
|
||||
import '../../app/shortcuts.dart';
|
||||
@ -164,13 +165,17 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
|
||||
ActionChip(
|
||||
label: Text(l10n.s_add_account),
|
||||
onPressed: () async {
|
||||
await showBlurDialog(
|
||||
context: context,
|
||||
builder: (context) => AddAccountDialog(
|
||||
widget.devicePath,
|
||||
widget.oathState,
|
||||
),
|
||||
);
|
||||
if (isAndroid) {
|
||||
ref.read(androidAddAccountFlowProvider)(context);
|
||||
} else {
|
||||
await showBlurDialog(
|
||||
context: context,
|
||||
builder: (context) => AddAccountDialog(
|
||||
widget.devicePath,
|
||||
widget.oathState,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
avatar: const Icon(Icons.person_add_alt_1_outlined),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user