Ver a proveniência

refactor: changed lifecycle callback to late

flutter-beta
Julian Steenbakker há 5 anos
ascendente
cometimento
c8ed07e915
2 ficheiros alterados com 5 adições e 14 eliminações
  1. +3
    -11
      lib/src/lifecycle_event_handler.dart
  2. +2
    -3
      lib/src/qr_code_scanner.dart

+ 3
- 11
lib/src/lifecycle_event_handler.dart Ver ficheiro

@@ -3,28 +3,20 @@ import 'package:flutter/foundation.dart';


class LifecycleEventHandler extends WidgetsBindingObserver { class LifecycleEventHandler extends WidgetsBindingObserver {
LifecycleEventHandler({ LifecycleEventHandler({
this.resumeCallBack,
this.suspendingCallBack,
required this.resumeCallBack,
}); });


final AsyncCallback? resumeCallBack;
final AsyncCallback? suspendingCallBack;
late final AsyncCallback resumeCallBack;


@override @override
Future<void> didChangeAppLifecycleState(AppLifecycleState state) async { Future<void> didChangeAppLifecycleState(AppLifecycleState state) async {
switch (state) { switch (state) {
case AppLifecycleState.resumed: case AppLifecycleState.resumed:
if (resumeCallBack != null) {
await resumeCallBack!();
}
await resumeCallBack();
break; break;
case AppLifecycleState.inactive: case AppLifecycleState.inactive:
case AppLifecycleState.paused: case AppLifecycleState.paused:
case AppLifecycleState.detached: case AppLifecycleState.detached:
if (suspendingCallBack != null) {
await suspendingCallBack!();
}
break;
} }
} }
} }

+ 2
- 3
lib/src/qr_code_scanner.dart Ver ficheiro

@@ -98,7 +98,6 @@ class _QRViewState extends State<QRView> {
widget.key as GlobalKey<State<StatefulWidget>>, _channel, widget.key as GlobalKey<State<StatefulWidget>>, _channel,
overlay: widget.overlay) overlay: widget.overlay)
}); });

return false; return false;
} }


@@ -139,7 +138,7 @@ class _QRViewState extends State<QRView> {
break; break;
default: default:
throw UnsupportedError( throw UnsupportedError(
"Trying to use the default webview implementation for $defaultTargetPlatform but there isn't a default one");
"Trying to use the default qrview implementation for $defaultTargetPlatform but there isn't a default one");
} }
return _platformQrView; return _platformQrView;
} }
@@ -199,7 +198,7 @@ class QRViewController {
} }
break; break;
case 'onPermissionSet': case 'onPermissionSet':
await getSystemFeatures(); // if we have no permission all features will not be avaible
await getSystemFeatures(); // if we have no permission all features will not be available
if (call.arguments != null) { if (call.arguments != null) {
if (call.arguments as bool) { if (call.arguments as bool) {
_hasPermissions = true; _hasPermissions = true;


Carregando…
Cancelar
Guardar