22 lines
603 B
Dart
22 lines
603 B
Dart
import 'package:flutter/material.dart';
|
|
|
|
class AppLifecycleLockObserver extends WidgetsBindingObserver {
|
|
final VoidCallback onLock;
|
|
final bool Function()? shouldLock;
|
|
|
|
AppLifecycleLockObserver({required this.onLock, this.shouldLock});
|
|
|
|
@override
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
switch (state) {
|
|
case AppLifecycleState.inactive:
|
|
case AppLifecycleState.hidden:
|
|
case AppLifecycleState.paused:
|
|
case AppLifecycleState.detached:
|
|
if (shouldLock?.call() ?? true) onLock();
|
|
case AppLifecycleState.resumed:
|
|
break;
|
|
}
|
|
}
|
|
}
|