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),
|
currentAppProvider.overrideWithProvider(androidSubPageProvider),
|
||||||
managementStateProvider.overrideWithProvider(androidManagementState),
|
managementStateProvider.overrideWithProvider(androidManagementState),
|
||||||
currentDeviceProvider.overrideWithProvider(androidCurrentDeviceProvider),
|
currentDeviceProvider.overrideWithProvider(androidCurrentDeviceProvider),
|
||||||
qrScannerProvider.overrideWithProvider(androidQrScannerProvider),
|
qrScannerProvider.overrideWithProvider(
|
||||||
|
androidQrScannerProvider.call(await getHasCamera())),
|
||||||
windowStateProvider.overrideWithProvider(androidWindowStateProvider),
|
windowStateProvider.overrideWithProvider(androidWindowStateProvider),
|
||||||
clipboardProvider.overrideWithProvider(androidClipboardProvider),
|
clipboardProvider.overrideWithProvider(androidClipboardProvider),
|
||||||
androidSdkVersionProvider.overrideWithValue(await getAndroidSdkVersion()),
|
androidSdkVersionProvider.overrideWithValue(await getAndroidSdkVersion()),
|
||||||
androidHasCameraProvider.overrideWithValue(await getHasCamera()),
|
|
||||||
supportedThemesProvider
|
supportedThemesProvider
|
||||||
.overrideWithProvider(androidSupportedThemesProvider)
|
.overrideWithProvider(androidSupportedThemesProvider)
|
||||||
],
|
],
|
||||||
|
@ -46,6 +46,6 @@ class AndroidQrScanner implements QrScanner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final androidQrScannerProvider = Provider<QrScanner?>(
|
final androidQrScannerProvider = Provider.family<QrScanner?, bool>(
|
||||||
(ref) => AndroidQrScanner(ref.watch(withContextProvider)),
|
(ref, hasCamera) =>
|
||||||
);
|
hasCamera ? AndroidQrScanner(ref.watch(withContextProvider)) : null);
|
||||||
|
@ -64,8 +64,6 @@ class _AndroidClipboard extends AppClipboard {
|
|||||||
|
|
||||||
final androidSdkVersionProvider = Provider<int>((ref) => -1);
|
final androidSdkVersionProvider = Provider<int>((ref) => -1);
|
||||||
|
|
||||||
final androidHasCameraProvider = Provider<bool>((ref) => false);
|
|
||||||
|
|
||||||
final androidSupportedThemesProvider = StateProvider<List<ThemeMode>>((ref) {
|
final androidSupportedThemesProvider = StateProvider<List<ThemeMode>>((ref) {
|
||||||
if (ref.read(androidSdkVersionProvider) < 29) {
|
if (ref.read(androidSdkVersionProvider) < 29) {
|
||||||
// the user can select from light or dark theme of the app
|
// the user can select from light or dark theme of the app
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.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/cancellation_exception.dart';
|
||||||
import 'package:yubico_authenticator/core/state.dart';
|
import 'package:yubico_authenticator/core/state.dart';
|
||||||
|
|
||||||
@ -75,18 +74,16 @@ class MainPage extends ConsumerWidget {
|
|||||||
tooltip: 'Add account',
|
tooltip: 'Add account',
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
CredentialData? otpauth;
|
CredentialData? otpauth;
|
||||||
if (ref.read(androidHasCameraProvider)) {
|
final scanner = ref.read(qrScannerProvider);
|
||||||
final scanner = ref.read(qrScannerProvider);
|
if (scanner != null) {
|
||||||
if (scanner != null) {
|
try {
|
||||||
try {
|
final url = await scanner.scanQr();
|
||||||
final url = await scanner.scanQr();
|
if (url != null) {
|
||||||
if (url != null) {
|
otpauth = CredentialData.fromUri(Uri.parse(url));
|
||||||
otpauth = CredentialData.fromUri(Uri.parse(url));
|
|
||||||
}
|
|
||||||
} on CancellationException catch (_) {
|
|
||||||
// ignored - user cancelled
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
} on CancellationException catch (_) {
|
||||||
|
// ignored - user cancelled
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await showBlurDialog(
|
await showBlurDialog(
|
||||||
|
@ -20,7 +20,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/services.dart';
|
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 'package:yubico_authenticator/android/state.dart';
|
|
||||||
import 'package:yubico_authenticator/widgets/delayed_visibility.dart';
|
import 'package:yubico_authenticator/widgets/delayed_visibility.dart';
|
||||||
|
|
||||||
import '../../app/message.dart';
|
import '../../app/message.dart';
|
||||||
@ -238,7 +237,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
|
|||||||
action: capacity == null || capacity > used
|
action: capacity == null || capacity > used
|
||||||
? () async {
|
? () async {
|
||||||
CredentialData? otpauth;
|
CredentialData? otpauth;
|
||||||
if (Platform.isAndroid && ref.read(androidHasCameraProvider)) {
|
if (Platform.isAndroid) {
|
||||||
final scanner = ref.read(qrScannerProvider);
|
final scanner = ref.read(qrScannerProvider);
|
||||||
if (scanner != null) {
|
if (scanner != null) {
|
||||||
final url = await scanner.scanQr();
|
final url = await scanner.scanQr();
|
||||||
|
Loading…
Reference in New Issue
Block a user