mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-22 08:22:16 +03:00
switch to function
This commit is contained in:
parent
d563a060eb
commit
c8931e6328
@ -64,7 +64,6 @@ Future<Widget> initialize() async {
|
||||
currentDeviceDataProvider.overrideWith(
|
||||
(ref) => ref.watch(androidDeviceDataProvider),
|
||||
),
|
||||
addOathAccount.overrideWith((ref) => ref.read(androidAddOathAccount)),
|
||||
oathStateProvider.overrideWithProvider(androidOathStateProvider.call),
|
||||
credentialListProvider
|
||||
.overrideWithProvider(androidCredentialListProvider.call),
|
||||
|
@ -32,37 +32,11 @@ 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 androidAddOathAccount = Provider<
|
||||
void Function(
|
||||
BuildContext, [
|
||||
DevicePath? devicePath,
|
||||
OathState? oathState,
|
||||
])>((ref) => (context, [devicePath, oathState]) 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);
|
||||
|
@ -25,7 +25,7 @@ import '../../fido/views/fingerprints_screen.dart';
|
||||
import '../../fido/views/passkeys_screen.dart';
|
||||
import '../../fido/views/webauthn_page.dart';
|
||||
import '../../management/views/management_screen.dart';
|
||||
import '../../oath/state.dart';
|
||||
import '../../oath/utils.dart';
|
||||
import '../../oath/views/oath_screen.dart';
|
||||
import '../../otp/views/otp_screen.dart';
|
||||
import '../../piv/views/piv_screen.dart';
|
||||
@ -101,7 +101,7 @@ class MainPage extends ConsumerWidget {
|
||||
icon: const Icon(Icons.person_add_alt_1),
|
||||
tooltip: l10n.s_add_account,
|
||||
onPressed: () async {
|
||||
ref.read(addOathAccount)(context);
|
||||
addOathAccount(context, ref);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -214,7 +214,6 @@ Future<Widget> initialize(List<String> argv) async {
|
||||
(ref) => ref.watch(desktopDeviceDataProvider),
|
||||
),
|
||||
// OATH
|
||||
addOathAccount.overrideWith((ref) => ref.read(desktopAddOathAccount)),
|
||||
oathStateProvider.overrideWithProvider(desktopOathState.call),
|
||||
credentialListProvider
|
||||
.overrideWithProvider(desktopOathCredentialListProvider.call),
|
||||
|
@ -24,30 +24,16 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import '../../app/logging.dart';
|
||||
import '../../app/message.dart';
|
||||
import '../../app/models.dart';
|
||||
import '../../app/state.dart';
|
||||
import '../../app/views/user_interaction.dart';
|
||||
import '../../oath/models.dart';
|
||||
import '../../oath/state.dart';
|
||||
import '../../oath/views/add_account_dialog.dart';
|
||||
import '../rpc.dart';
|
||||
import '../state.dart';
|
||||
|
||||
final _log = Logger('desktop.oath.state');
|
||||
|
||||
final desktopAddOathAccount = Provider<
|
||||
void Function(
|
||||
BuildContext, [
|
||||
DevicePath? devicePath,
|
||||
OathState? oathState,
|
||||
])>((ref) => (context, [devicePath, oathState]) async {
|
||||
await showBlurDialog(
|
||||
context: context,
|
||||
builder: (context) => AddAccountDialog(devicePath, oathState),
|
||||
);
|
||||
});
|
||||
|
||||
final _sessionProvider =
|
||||
Provider.autoDispose.family<RpcNodeSession, DevicePath>(
|
||||
(ref, devicePath) => RpcNodeSession(
|
||||
|
@ -26,13 +26,6 @@ import '../app/state.dart';
|
||||
import '../core/state.dart';
|
||||
import 'models.dart';
|
||||
|
||||
final addOathAccount = Provider<
|
||||
void Function(
|
||||
BuildContext, [
|
||||
DevicePath? devicePath,
|
||||
OathState? oathState,
|
||||
])>((ref) => throw UnimplementedError());
|
||||
|
||||
final searchProvider =
|
||||
StateNotifierProvider<SearchNotifier, String>((ref) => SearchNotifier());
|
||||
|
||||
|
55
lib/oath/utils.dart
Normal file
55
lib/oath/utils.dart
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Yubico.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../android/qr_scanner/qr_scanner_provider.dart';
|
||||
import '../app/message.dart';
|
||||
import '../app/models.dart';
|
||||
import '../app/state.dart';
|
||||
import '../core/state.dart';
|
||||
import '../exception/cancellation_exception.dart';
|
||||
import 'models.dart';
|
||||
import 'views/add_account_dialog.dart';
|
||||
|
||||
void addOathAccount(BuildContext context, WidgetRef ref,
|
||||
[DevicePath? devicePath, OathState? oathState]) async {
|
||||
if (isAndroid) {
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
await showBlurDialog(
|
||||
context: context,
|
||||
builder: (context) => AddAccountDialog(devicePath, oathState),
|
||||
);
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@ import '../features.dart' as features;
|
||||
import '../icon_provider/icon_pack_dialog.dart';
|
||||
import '../keys.dart' as keys;
|
||||
import '../models.dart';
|
||||
import '../state.dart';
|
||||
import '../utils.dart';
|
||||
import 'manage_password_dialog.dart';
|
||||
|
||||
Widget oathBuildActions(
|
||||
@ -56,7 +56,7 @@ Widget oathBuildActions(
|
||||
onTap: used != null && (capacity == null || capacity > used)
|
||||
? (context) async {
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
ref.read(addOathAccount)(context, devicePath, oathState);
|
||||
addOathAccount(context, ref, devicePath, oathState);
|
||||
}
|
||||
: null),
|
||||
]),
|
||||
|
@ -40,6 +40,7 @@ import '../features.dart' as features;
|
||||
import '../keys.dart' as keys;
|
||||
import '../models.dart';
|
||||
import '../state.dart';
|
||||
import '../utils.dart';
|
||||
import 'account_dialog.dart';
|
||||
import 'account_helper.dart';
|
||||
import 'account_list.dart';
|
||||
@ -163,8 +164,9 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
|
||||
ActionChip(
|
||||
label: Text(l10n.s_add_account),
|
||||
onPressed: () async {
|
||||
ref.read(addOathAccount)(
|
||||
addOathAccount(
|
||||
context,
|
||||
ref,
|
||||
widget.devicePath,
|
||||
widget.oathState,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user