Skip to content

Commit f684564

Browse files
committed
chore: Now using mobile_scanner instead of google_mlkit_barcode_scanning.
1 parent e1d2447 commit f684564

17 files changed

+484
-905
lines changed

lib/i18n/en/error.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
"accessDeniedDialog": {
3737
"title": "Access denied",
3838
"message": "Failed to access your camera (access denied : $exception). Do you want to retry ?"
39-
}
39+
},
40+
"controllerUninitialized": "Uninitialized controller (code : $exception).",
41+
"unsupported": "Scanning is not supported on this device (code : $exception)."
4042
},
4143
"storageMigration(map)": {
4244
"backupError": "An error occurred while doing the backup. Please try again.",

lib/i18n/fr/error.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
"accessDeniedDialog": {
3737
"title": "Accès refusé",
3838
"message": "Impossible d'accéder à votre caméra (accès refusé : $exception). Voulez-vous réessayer ?"
39-
}
39+
},
40+
"controllerUninitialized": "Controlleur non initialisé (code : $exception).",
41+
"unsupported": "Le scan n'est pas supporté par cet appareil (code : $exception)."
4042
},
4143
"storageMigration(map)": {
4244
"backupError": "Une erreur est survenue durant la sauvegarde. Veuillez réessayer.",

lib/pages/home.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class _HomePageBody extends ConsumerWidget {
198198
? SmoothHighlight(
199199
color: Theme.of(context).focusColor,
200200
useInitialHighLight: true,
201+
onHighlightFinished: onHighlightFinished,
201202
child: totpWidget,
202203
)
203204
: totpWidget;

lib/pages/scan.dart

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter/services.dart';
23
import 'package:flutter_riverpod/flutter_riverpod.dart';
34
import 'package:open_authenticator/i18n/translations.g.dart';
45
import 'package:open_authenticator/pages/totp.dart';
5-
import 'package:open_authenticator/widgets/centered_circular_progress_indicator.dart';
6-
import 'package:open_authenticator/widgets/code_scan.dart';
7-
import 'package:open_authenticator/widgets/dialog/confirmation_dialog.dart';
6+
import 'package:open_authenticator/widgets/scan/scanner.dart';
87
import 'package:open_authenticator/widgets/snackbar_icon.dart';
98
import 'package:open_authenticator/widgets/waiting_overlay.dart';
9+
import 'package:wakelock_plus/wakelock_plus.dart';
1010

1111
/// Allows to scan QR codes.
12-
class ScanPage extends ConsumerWidget {
12+
class ScanPage extends ConsumerStatefulWidget {
1313
/// The scan page name.
1414
static const String name = '/scan';
1515

@@ -19,16 +19,30 @@ class ScanPage extends ConsumerWidget {
1919
});
2020

2121
@override
22-
Widget build(BuildContext context, WidgetRef ref) => Scaffold(
23-
body: CodeScanner(
24-
once: true,
25-
formats: const [BarcodeFormat.qrCode],
26-
loading: const CenteredCircularProgressIndicator(),
27-
onScan: (code, details, listener) async {
28-
if (code == null || !context.mounted) {
22+
ConsumerState<ConsumerStatefulWidget> createState() => _ScanPageState();
23+
}
24+
25+
/// The scan page state.
26+
class _ScanPageState extends ConsumerState<ScanPage> {
27+
@override
28+
void initState() {
29+
super.initState();
30+
WakelockPlus.enable();
31+
SystemChrome.setPreferredOrientations([
32+
DeviceOrientation.portraitUp,
33+
DeviceOrientation.portraitDown,
34+
]);
35+
}
36+
37+
@override
38+
Widget build(BuildContext context) => Scaffold(
39+
body: QrCodeScanner(
40+
onScan: (code) async {
41+
String? data = code.barcodes.firstOrNull?.rawValue;
42+
if (data == null || !context.mounted) {
2943
return;
3044
}
31-
Uri? uri = Uri.tryParse(code);
45+
Uri? uri = Uri.tryParse(data);
3246
if (uri == null) {
3347
Navigator.pop(context);
3448
SnackBarIcon.showErrorSnackBar(context, text: translations.error.scan.noUri);
@@ -39,25 +53,23 @@ class ScanPage extends ConsumerWidget {
3953
future: TotpPage.openFromUri(context, ref, uri),
4054
);
4155
},
42-
onAccessDenied: (exception, listener) async {
43-
bool result = await ConfirmationDialog.ask(
44-
context,
45-
title: translations.error.scan.accessDeniedDialog.title,
46-
message: translations.error.scan.accessDeniedDialog.message(exception: exception),
47-
);
48-
if (result) {
49-
return true;
50-
}
51-
if (context.mounted) {
52-
Navigator.pop(context);
53-
}
54-
return false;
55-
},
5656
onError: (exception, listener) => SnackBarIcon.showErrorSnackBar(context, text: translations.error.generic.withException(exception: exception)),
5757
),
5858
floatingActionButton: FloatingActionButton(
59-
child: const BackButtonIcon(),
59+
child: Icon(Icons.close),
6060
onPressed: () => Navigator.pop(context),
6161
),
6262
);
63+
64+
@override
65+
void dispose() {
66+
SystemChrome.setPreferredOrientations([
67+
DeviceOrientation.landscapeRight,
68+
DeviceOrientation.landscapeLeft,
69+
DeviceOrientation.portraitUp,
70+
DeviceOrientation.portraitDown,
71+
]);
72+
WakelockPlus.disable();
73+
super.dispose();
74+
}
6375
}

lib/utils/camera.dart

Lines changed: 0 additions & 64 deletions
This file was deleted.

lib/utils/stream.dart

Lines changed: 0 additions & 163 deletions
This file was deleted.

0 commit comments

Comments
 (0)