der Fehler tritt immer noch auf.
Hier die restlichen Sachen.
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/patient_app_localizations.dart';
import 'package:patient_app/models/scan_result.dart';
import 'package:patient_app/modules/account_linking/account_linking_state_manager.dart';
import 'package:patient_app/modules/account_linking/widgets/qr_scanner.dart'
if (dart.library.html) 'package:patient_app/modules/account_linking/widgets/qr_scanner_mock.dart';
import 'package:patient_app/modules/account_linking/widgets/qr_scanner_unmaintained.dart'
as qr_code_scanner_unmaintained;
import 'package:patient_app/settings.dart' as settings;
import 'package:patient_app/theme/patient_app_theme.dart' as theme;
import 'package:provider/provider.dart';
class AccountLinkingQrCodeScannerScreen extends StatefulWidget {
static MaterialPage page() {
return const MaterialPage(
name: "QrCodeScanner",
key: ValueKey("QrCodeScanner"),
child: AccountLinkingQrCodeScannerScreen(),
);
}
const AccountLinkingQrCodeScannerScreen({Key? key}) : super(key: key);
@override
State createState() =>
_AccountLinkingQrCodeScannerScreenState();
}
class _AccountLinkingQrCodeScannerScreenState
extends State {
late AppLocalizations _l10n;
@override
void didChangeDependencies() {
_l10n = AppLocalizations.of(context)!;
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
alignment: Alignment.center,
fit: StackFit.expand,
children: [
_buildQrScannerArea(),
_buildMainContent(),
],
),
);
}
Widget _buildMainContent() {
return Padding(
padding: theme.commonEdgeInsets,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: theme.extraLargeSpacing,
),
Text(
_l10n.accountLinking_QrCodeScannerScreenTitle,
style: theme.lightHeadline1,
),
const SizedBox(height: theme.extraSmallSpacing),
Text(
_l10n.accountLinking_QrCodeScannerScreenDescription,
style: theme.lightBodyText2,
),
const Spacer(),
Center(
child: ElevatedButton(
onPressed: () {
context.read().deleteState();
},
style: Theme.of(context).elevatedButtonTheme.style,
child: Text(_l10n.general_cancelButtonLabel),
),
),
],
),
);
}
Widget _buildQrScannerArea() {
Widget child = settings.useUnmaintainedQrScanner
? qr_code_scanner_unmaintained.QrScanner(
callback: _handleResult, backButtonCallback: _backButtonCallback)
: QrScanner(
callback: _handleResult,
backButtonCallback: _backButtonCallback,
);
return Positioned.fill(
child: child,
);
}
Future _handleResult(ScanResult scanResult) async {
if (isValid(scanResult)) {
context.read().updateScanResult(scanResult);
return true;
} else {
return false;
}
}
// prevent qr code fragments to be accepted
// Large qr codes could result in partially identified qr codes,
// they are too short to be accepted
bool isValid(ScanResult scanResult) => scanResult.qrCodeAsString.length > 16;
void _backButtonCallback() {
context.read().deleteState();
}
}
import 'dart:async';
import 'package:code_scan/code_scan.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/patient_app_localizations.dart';
import 'package:patient_app/models/scan_result.dart';
import 'package:patient_app/theme/patient_app_colors.dart';
import 'package:patient_app/widgets/patient_app_back_button.dart';
typedef QrScanResultCallback = Future Function(ScanResult);
// see https://pub.dev/packages/code_scan/example
class QrScanner extends StatefulWidget {
const QrScanner(
{Key? key, required this.callback, required this.backButtonCallback})
: super(key: key);
final QrScanResultCallback callback;
final BackButtonCallback backButtonCallback;
@override
State createState() => _QrScannerState();
}
class _QrScannerState extends State with WidgetsBindingObserver {
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
late AppLocalizations _l10n;
// prevent over processing
bool processingInProgress = false;
@override
void didChangeDependencies() {
_l10n = AppLocalizations.of(context)!;
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
return Container(
color: AppColors.opascaBlue,
child: _buildQrView(),
);
}
Widget buildQrView() {
return CodeScanner(
key: qrKey,
formats: const [BarcodeFormat.qrCode],
scanInterval: const Duration(milliseconds: 500),
onScan: (code, , listener) {
if (code != null) {
if (processingInProgress == false) {
processingInProgress = true;
widget.callback(ScanResult(code)).then((isValidCode) {
if (mounted && !isValidCode) {
processingInProgress = false;
}
});
}
}
},
onAccessDenied: (, controller) {
showPermissionNotGrantedDialog()
.then(() => widget.backButtonCallback());
return false;
},
onError: (, __) {
_showQrCodeReadErrorDialog();
},
overlay: Container(),
);
}
Future showQrCodeReadErrorDialog() {
return showDialog(
context: context,
builder: () => AlertDialog(
title: Text(_l10n.accountLinking_QrCodeScannerDialogTitle),
content: Text(_l10n.accountLinking_QrCodeScannerDialogDescription),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text(_l10n.accountLinking_QrCodeScannerDialogAction),
)
],
),
);
}
Future showPermissionNotGrantedDialog() {
return showDialog(
context: context,
builder: () => AlertDialog(
title: Text(
_l10n.accountLinking_QrCodeScannerMissingCameraPermissionTitle),
content: Text(_l10n
.accountLinking_QrCodeScannerMissingCameraPermissionDescription),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text(_l10n.accountLinking_QrCodeScannerDialogAction),
)
],
),
);
}
}
'code: "Disposed CameraController"
"stopImageStream() was called on a disposed CameraController."
void _throwIfNotInitialized(String functionName) {
if (!value.isInitialized) {
throw CameraException(
'Uninitialized CameraController',
'functionName() was called on an uninitialized CameraController.',
);
}
if (_isDisposed) {
throw CameraException(
'Disposed CameraController',
'functionName() was called on a disposed CameraController.',
);
}
}
/// Stops the camera image controller and image stream.
Future stop() async {
await imageController.close();
if (controller.value.isStreamingImages) {
await controller.stopImageStream();
}
}
/// Alias of the .stop() method, for consistency with the flutter environment.
Future dispose() async => await stop();
@patch
@pragma("vm:external-name", "Error_throwWithStackTrace")
external static Never _throw(Object error, StackTrace stackTrace);
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of dart.async;
typedef void _AsyncCallback();
class _AsyncCallbackEntry {
final _AsyncCallback callback;
_AsyncCallbackEntry? next;
_AsyncCallbackEntry(this.callback);
}
/// Head of single linked list of pending callbacks.
_AsyncCallbackEntry? _nextCallback;
/// Tail of single linked list of pending callbacks.
_AsyncCallbackEntry? _lastCallback;
/// Tail of priority callbacks added by the currently executing callback.
///
/// Priority callbacks are put at the beginning of the
/// callback queue, so that if one callback schedules more than one
/// priority callback, they are still enqueued in scheduling order.
_AsyncCallbackEntry? _lastPriorityCallback;
/// Whether we are currently inside the callback loop.
///
/// If we are inside the loop, we never need to schedule the loop,
/// even if adding a first element.
bool _isInCallbackLoop = false;
void _microtaskLoop() {
for (var entry = _nextCallback; entry != null; entry = _nextCallback) {
_lastPriorityCallback = null;
var next = entry.next;
_nextCallback = next;
if (next == null) _lastCallback = null;
(entry.callback)();
}
}
void _startMicrotaskLoop() {
_isInCallbackLoop = true;
try {
// Moved to separate function because try-finally prevents
// good optimization.
_microtaskLoop();
} finally {
_lastPriorityCallback = null;
_isInCallbackLoop = false;
if (_nextCallback != null) {
_AsyncRun._scheduleImmediate(_startMicrotaskLoop);
}
}
}
/// Schedules a callback to be called as a microtask.
///
/// The microtask is called after all other currently scheduled
/// microtasks, but as part of the current system event.
void _scheduleAsyncCallback(_AsyncCallback callback) {
_AsyncCallbackEntry newEntry = new _AsyncCallbackEntry(callback);
_AsyncCallbackEntry? lastCallback = _lastCallback;
if (lastCallback == null) {
_nextCallback = _lastCallback = newEntry;
if (!_isInCallbackLoop) {
_AsyncRun._scheduleImmediate(_startMicrotaskLoop);
}
} else {
lastCallback.next = newEntry;
_lastCallback = newEntry;
}
}
/// Schedules a callback to be called before all other currently scheduled ones.
///
/// This callback takes priority over existing scheduled callbacks.
/// It is only used internally to give higher priority to error reporting.
///
/// Is always run in the root zone.
void _schedulePriorityAsyncCallback(_AsyncCallback callback) {
if (_nextCallback == null) {
_scheduleAsyncCallback(callback);
_lastPriorityCallback = _lastCallback;
return;
}
_AsyncCallbackEntry entry = new _AsyncCallbackEntry(callback);
_AsyncCallbackEntry? lastPriorityCallback = _lastPriorityCallback;
if (lastPriorityCallback == null) {
entry.next = _nextCallback;
_nextCallback = _lastPriorityCallback = entry;
} else {
var next = lastPriorityCallback.next;
entry.next = next;
lastPriorityCallback.next = entry;
_lastPriorityCallback = entry;
if (next == null) {
_lastCallback = entry;
}
}
}
/// Runs a function asynchronously.
///
/// Callbacks registered through this function are always executed in order and
/// are guaranteed to run before other asynchronous events (like [Timer] events,
/// or DOM events).
///
/// Warning: it is possible to starve the DOM by registering asynchronous
/// callbacks through this method. For example the following program runs
/// the callbacks without ever giving the Timer callback a chance to execute:
/// dart /// main() { /// Timer.run(() { print("executed"); }); // Will never be executed. /// foo() { /// scheduleMicrotask(foo); // Schedules [foo] in front of other events. /// } /// foo(); /// } ///
/// ## Other resources
///
/// * The Event Loop and Dart:
/// Learn how Dart handles the event queue and microtask queue, so you can write
/// better asynchronous code with fewer surprises.
@pragma('vm:entry-point', 'call')
void scheduleMicrotask(void Function() callback) {
_Zone currentZone = Zone._current;
if (identical(_rootZone, currentZone)) {
// No need to bind the callback. We know that the root's scheduleMicrotask
// will be invoked in the root zone.
_rootScheduleMicrotask(null, null, _rootZone, callback);
return;
}
_ZoneFunction implementation = currentZone._scheduleMicrotask;
if (identical(_rootZone, implementation.zone) &&
_rootZone.inSameErrorZone(currentZone)) {
_rootScheduleMicrotask(
null, null, currentZone, currentZone.registerCallback(callback));
return;
}
Zone.current.scheduleMicrotask(Zone.current.bindCallbackGuarded(callback));
}
class _AsyncRun {
/// Schedule the given callback before any other event in the event-loop.
external static void _scheduleImmediate(void Function() callback);
}