simplify work with hasCamera

This commit is contained in:
Adam Velebil 2022-11-08 14:06:27 +01:00
parent 5ad830f191
commit 80fdb03b34
No known key found for this signature in database
GPG Key ID: AC6D6B9D715FC084
5 changed files with 15 additions and 21 deletions

View File

@ -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)
],

View File

@ -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);

View File

@ -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

View File

@ -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'),

View File

@ -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();