浏览代码

refactor: changed lifecycle callback to late

flutter-beta
Julian Steenbakker 5 年前
父节点
当前提交
c8ed07e915
共有 2 个文件被更改,包括 5 次插入14 次删除
  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 查看文件

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

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

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

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

+ 2
- 3
lib/src/qr_code_scanner.dart 查看文件

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

return false;
}

@@ -139,7 +138,7 @@ class _QRViewState extends State<QRView> {
break;
default:
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;
}
@@ -199,7 +198,7 @@ class QRViewController {
}
break;
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 as bool) {
_hasPermissions = true;


正在加载...
取消
保存