mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-26 22:03:55 +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 '../../exception/platform_exception_decoder.dart';
|
||||||
import '../../oath/models.dart';
|
import '../../oath/models.dart';
|
||||||
import '../../oath/state.dart';
|
import '../../oath/state.dart';
|
||||||
|
import '../qr_scanner/qr_scanner_provider.dart';
|
||||||
|
|
||||||
final _log = Logger('android.oath.state');
|
final _log = Logger('android.oath.state');
|
||||||
|
|
||||||
const _methods = MethodChannel('android.oath.methods');
|
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
|
final androidOathStateProvider = AsyncNotifierProvider.autoDispose
|
||||||
.family<OathStateNotifier, OathState, DevicePath>(
|
.family<OathStateNotifier, OathState, DevicePath>(
|
||||||
_AndroidOathStateNotifier.new);
|
_AndroidOathStateNotifier.new);
|
||||||
|
@ -19,6 +19,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
import '../../android/app_methods.dart';
|
import '../../android/app_methods.dart';
|
||||||
|
import '../../android/oath/state.dart';
|
||||||
import '../../android/qr_scanner/qr_scanner_provider.dart';
|
import '../../android/qr_scanner/qr_scanner_provider.dart';
|
||||||
import '../../android/state.dart';
|
import '../../android/state.dart';
|
||||||
import '../../core/state.dart';
|
import '../../core/state.dart';
|
||||||
@ -102,22 +103,7 @@ class MainPage extends ConsumerWidget {
|
|||||||
icon: const Icon(Icons.person_add_alt_1),
|
icon: const Icon(Icons.person_add_alt_1),
|
||||||
tooltip: l10n.s_add_account,
|
tooltip: l10n.s_add_account,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final withContext = ref.read(withContextProvider);
|
ref.read(androidAddAccountFlowProvider)(context);
|
||||||
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);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -18,6 +18,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
|
import '../../android/oath/state.dart';
|
||||||
import '../../android/qr_scanner/qr_scanner_provider.dart';
|
import '../../android/qr_scanner/qr_scanner_provider.dart';
|
||||||
import '../../app/message.dart';
|
import '../../app/message.dart';
|
||||||
import '../../app/models.dart';
|
import '../../app/models.dart';
|
||||||
@ -59,17 +60,7 @@ Widget oathBuildActions(
|
|||||||
? (context) async {
|
? (context) async {
|
||||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||||
if (isAndroid) {
|
if (isAndroid) {
|
||||||
final withContext = ref.read(withContextProvider);
|
ref.read(androidAddAccountFlowProvider)(context);
|
||||||
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);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
await showBlurDialog(
|
await showBlurDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -22,6 +22,7 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
|
import '../../android/oath/state.dart';
|
||||||
import '../../app/message.dart';
|
import '../../app/message.dart';
|
||||||
import '../../app/models.dart';
|
import '../../app/models.dart';
|
||||||
import '../../app/shortcuts.dart';
|
import '../../app/shortcuts.dart';
|
||||||
@ -164,6 +165,9 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
|
|||||||
ActionChip(
|
ActionChip(
|
||||||
label: Text(l10n.s_add_account),
|
label: Text(l10n.s_add_account),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
if (isAndroid) {
|
||||||
|
ref.read(androidAddAccountFlowProvider)(context);
|
||||||
|
} else {
|
||||||
await showBlurDialog(
|
await showBlurDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AddAccountDialog(
|
builder: (context) => AddAccountDialog(
|
||||||
@ -171,6 +175,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
|
|||||||
widget.oathState,
|
widget.oathState,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
avatar: const Icon(Icons.person_add_alt_1_outlined),
|
avatar: const Icon(Icons.person_add_alt_1_outlined),
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user