Skip to content

Commit

Permalink
chore: Now using mobile_scanner instead of `google_mlkit_barcode_sc…
Browse files Browse the repository at this point in the history
…anning`.
  • Loading branch information
Skyost committed Nov 3, 2024
1 parent e1d2447 commit f684564
Show file tree
Hide file tree
Showing 17 changed files with 484 additions and 905 deletions.
4 changes: 3 additions & 1 deletion lib/i18n/en/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"accessDeniedDialog": {
"title": "Access denied",
"message": "Failed to access your camera (access denied : $exception). Do you want to retry ?"
}
},
"controllerUninitialized": "Uninitialized controller (code : $exception).",
"unsupported": "Scanning is not supported on this device (code : $exception)."
},
"storageMigration(map)": {
"backupError": "An error occurred while doing the backup. Please try again.",
Expand Down
4 changes: 3 additions & 1 deletion lib/i18n/fr/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"accessDeniedDialog": {
"title": "Accès refusé",
"message": "Impossible d'accéder à votre caméra (accès refusé : $exception). Voulez-vous réessayer ?"
}
},
"controllerUninitialized": "Controlleur non initialisé (code : $exception).",
"unsupported": "Le scan n'est pas supporté par cet appareil (code : $exception)."
},
"storageMigration(map)": {
"backupError": "Une erreur est survenue durant la sauvegarde. Veuillez réessayer.",
Expand Down
1 change: 1 addition & 0 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class _HomePageBody extends ConsumerWidget {
? SmoothHighlight(
color: Theme.of(context).focusColor,
useInitialHighLight: true,
onHighlightFinished: onHighlightFinished,
child: totpWidget,
)
: totpWidget;
Expand Down
66 changes: 39 additions & 27 deletions lib/pages/scan.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:open_authenticator/i18n/translations.g.dart';
import 'package:open_authenticator/pages/totp.dart';
import 'package:open_authenticator/widgets/centered_circular_progress_indicator.dart';
import 'package:open_authenticator/widgets/code_scan.dart';
import 'package:open_authenticator/widgets/dialog/confirmation_dialog.dart';
import 'package:open_authenticator/widgets/scan/scanner.dart';
import 'package:open_authenticator/widgets/snackbar_icon.dart';
import 'package:open_authenticator/widgets/waiting_overlay.dart';
import 'package:wakelock_plus/wakelock_plus.dart';

/// Allows to scan QR codes.
class ScanPage extends ConsumerWidget {
class ScanPage extends ConsumerStatefulWidget {
/// The scan page name.
static const String name = '/scan';

Expand All @@ -19,16 +19,30 @@ class ScanPage extends ConsumerWidget {
});

@override
Widget build(BuildContext context, WidgetRef ref) => Scaffold(
body: CodeScanner(
once: true,
formats: const [BarcodeFormat.qrCode],
loading: const CenteredCircularProgressIndicator(),
onScan: (code, details, listener) async {
if (code == null || !context.mounted) {
ConsumerState<ConsumerStatefulWidget> createState() => _ScanPageState();
}

/// The scan page state.
class _ScanPageState extends ConsumerState<ScanPage> {
@override
void initState() {
super.initState();
WakelockPlus.enable();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}

@override
Widget build(BuildContext context) => Scaffold(
body: QrCodeScanner(
onScan: (code) async {
String? data = code.barcodes.firstOrNull?.rawValue;
if (data == null || !context.mounted) {
return;
}
Uri? uri = Uri.tryParse(code);
Uri? uri = Uri.tryParse(data);
if (uri == null) {
Navigator.pop(context);
SnackBarIcon.showErrorSnackBar(context, text: translations.error.scan.noUri);
Expand All @@ -39,25 +53,23 @@ class ScanPage extends ConsumerWidget {
future: TotpPage.openFromUri(context, ref, uri),
);
},
onAccessDenied: (exception, listener) async {
bool result = await ConfirmationDialog.ask(
context,
title: translations.error.scan.accessDeniedDialog.title,
message: translations.error.scan.accessDeniedDialog.message(exception: exception),
);
if (result) {
return true;
}
if (context.mounted) {
Navigator.pop(context);
}
return false;
},
onError: (exception, listener) => SnackBarIcon.showErrorSnackBar(context, text: translations.error.generic.withException(exception: exception)),
),
floatingActionButton: FloatingActionButton(
child: const BackButtonIcon(),
child: Icon(Icons.close),
onPressed: () => Navigator.pop(context),
),
);

@override
void dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
WakelockPlus.disable();
super.dispose();
}
}
64 changes: 0 additions & 64 deletions lib/utils/camera.dart

This file was deleted.

163 changes: 0 additions & 163 deletions lib/utils/stream.dart

This file was deleted.

Loading

0 comments on commit f684564

Please sign in to comment.