wake lock implemented
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
|
||||
import '../app_mode/app_mode_cubit.dart';
|
||||
import 'screens/fly/fly_screen.dart';
|
||||
@@ -18,12 +19,26 @@ class AppShell extends StatelessWidget {
|
||||
final mode = context.select((AppModeCubit c) => c.state.mode);
|
||||
final screen = mode == AppMode.fly ? const FlyScreen() : const PlanScreen();
|
||||
|
||||
return Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
Positioned.fill(child: screen),
|
||||
const Align(alignment: Alignment.topCenter, child: TopModeBar()),
|
||||
],
|
||||
return BlocListener<AppModeCubit, AppModeState>(
|
||||
listenWhen: (previous, current) => previous.mode != current.mode,
|
||||
listener: (context, state) {
|
||||
// Nur FLAG_KEEP_SCREEN_ON, kein PowerManager.WakeLock (Doku 4.20
|
||||
// deckt den Foreground-Service fuer Hintergrund-Telemetrie separat
|
||||
// ab). Android-Empfehlung: an die Activity-Sichtbarkeit gebunden,
|
||||
// keine Permission, kein manuelles Leak-Risiko.
|
||||
if (state.mode == AppMode.fly) {
|
||||
WakelockPlus.enable();
|
||||
} else {
|
||||
WakelockPlus.disable();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
Positioned.fill(child: screen),
|
||||
const Align(alignment: Alignment.topCenter, child: TopModeBar()),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user