mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-23 18:22:39 +03:00
simplify work with hasCamera
This commit is contained in:
parent
5ad830f191
commit
80fdb03b34
@ -67,11 +67,11 @@ Future<Widget> initialize() async {
|
||||
currentAppProvider.overrideWithProvider(androidSubPageProvider),
|
||||
managementStateProvider.overrideWithProvider(androidManagementState),
|
||||
currentDeviceProvider.overrideWithProvider(androidCurrentDeviceProvider),
|
||||
qrScannerProvider.overrideWithProvider(androidQrScannerProvider),
|
||||
qrScannerProvider.overrideWithProvider(
|
||||
androidQrScannerProvider.call(await getHasCamera())),
|
||||
windowStateProvider.overrideWithProvider(androidWindowStateProvider),
|
||||
clipboardProvider.overrideWithProvider(androidClipboardProvider),
|
||||
androidSdkVersionProvider.overrideWithValue(await getAndroidSdkVersion()),
|
||||
androidHasCameraProvider.overrideWithValue(await getHasCamera()),
|
||||
supportedThemesProvider
|
||||
.overrideWithProvider(androidSupportedThemesProvider)
|
||||
],
|
||||
|
@ -46,6 +46,6 @@ class AndroidQrScanner implements QrScanner {
|
||||
}
|
||||
}
|
||||
|
||||
final androidQrScannerProvider = Provider<QrScanner?>(
|
||||
(ref) => AndroidQrScanner(ref.watch(withContextProvider)),
|
||||
);
|
||||
final androidQrScannerProvider = Provider.family<QrScanner?, bool>(
|
||||
(ref, hasCamera) =>
|
||||
hasCamera ? AndroidQrScanner(ref.watch(withContextProvider)) : null);
|
||||
|
@ -64,8 +64,6 @@ class _AndroidClipboard extends AppClipboard {
|
||||
|
||||
final androidSdkVersionProvider = Provider<int>((ref) => -1);
|
||||
|
||||
final androidHasCameraProvider = Provider<bool>((ref) => false);
|
||||
|
||||
final androidSupportedThemesProvider = StateProvider<List<ThemeMode>>((ref) {
|
||||
if (ref.read(androidSdkVersionProvider) < 29) {
|
||||
// the user can select from light or dark theme of the app
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:yubico_authenticator/android/state.dart';
|
||||
import 'package:yubico_authenticator/cancellation_exception.dart';
|
||||
import 'package:yubico_authenticator/core/state.dart';
|
||||
|
||||
@ -75,7 +74,6 @@ class MainPage extends ConsumerWidget {
|
||||
tooltip: 'Add account',
|
||||
onPressed: () async {
|
||||
CredentialData? otpauth;
|
||||
if (ref.read(androidHasCameraProvider)) {
|
||||
final scanner = ref.read(qrScannerProvider);
|
||||
if (scanner != null) {
|
||||
try {
|
||||
@ -88,7 +86,6 @@ class MainPage extends ConsumerWidget {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
await showBlurDialog(
|
||||
context: context,
|
||||
routeSettings: const RouteSettings(name: 'oath_add_account'),
|
||||
|
@ -20,7 +20,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:yubico_authenticator/android/state.dart';
|
||||
import 'package:yubico_authenticator/widgets/delayed_visibility.dart';
|
||||
|
||||
import '../../app/message.dart';
|
||||
@ -238,7 +237,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
|
||||
action: capacity == null || capacity > used
|
||||
? () async {
|
||||
CredentialData? otpauth;
|
||||
if (Platform.isAndroid && ref.read(androidHasCameraProvider)) {
|
||||
if (Platform.isAndroid) {
|
||||
final scanner = ref.read(qrScannerProvider);
|
||||
if (scanner != null) {
|
||||
final url = await scanner.scanQr();
|
||||
|
Loading…
Reference in New Issue
Block a user