Add fullscreen screen activator when screen is turned off

android_attempt
Felix Bruns 10 months ago
parent a1aa552947
commit c1624d7e05

@ -5,7 +5,6 @@ import 'package:pi_dashboard/src/proxmox_webservice/model.dart';
import 'package:pi_dashboard/src/proxmox_webservice/service.dart'; import 'package:pi_dashboard/src/proxmox_webservice/service.dart';
import 'package:pi_dashboard/src/screen_helper.dart'; import 'package:pi_dashboard/src/screen_helper.dart';
import 'package:pi_dashboard/src/settings/settings_controller.dart'; import 'package:pi_dashboard/src/settings/settings_controller.dart';
import 'package:pi_dashboard/src/settings/settings_service.dart';
import '../settings/settings_view.dart'; import '../settings/settings_view.dart';
import 'vm_card.dart'; import 'vm_card.dart';
@ -69,8 +68,20 @@ class _ProxmoxListerState extends State<ProxmoxListerView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( // infinite touch container to turn screen back on
appBar: AppBar( return Stack(
children: [
Scaffold(
appBar: appbar(context),
body: bodyBuilder(context),
),
screenActivator(),
],
);
}
PreferredSizeWidget? appbar(BuildContext context) {
return AppBar(
title: const Text("Proxmox VMs"), title: const Text("Proxmox VMs"),
actions: [ actions: [
IconButton( IconButton(
@ -92,8 +103,11 @@ class _ProxmoxListerState extends State<ProxmoxListerView> {
}, },
), ),
], ],
), );
body: FutureBuilder<ProxmoxNodeMap>( }
Widget bodyBuilder(BuildContext context) {
return FutureBuilder<ProxmoxNodeMap>(
future: nodes, future: nodes,
builder: (ctx, snapshot) { builder: (ctx, snapshot) {
if (snapshot.hasData) { if (snapshot.hasData) {
@ -122,7 +136,6 @@ class _ProxmoxListerState extends State<ProxmoxListerView> {
return const Center(child: CircularProgressIndicator()); return const Center(child: CircularProgressIndicator());
} }
}, },
)); );
} }
} }

@ -1,34 +1,50 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart';
const _off = "1"; const _off = "1";
const _on = "0"; const _on = "0";
bool _screenStatus = true;
Future<void> toggleScreen() async { Future<void> toggleScreen() async {
if (await isScreenOff()) { if (_screenStatus) {
turnOncreen();
} else {
turnOffScreen(); turnOffScreen();
} else {
turnOncreen();
} }
} }
Future<void> turnOffScreen() async { Future<void> turnOffScreen() async {
await setBlFile(_off); await setBlFile(_off);
_screenStatus = false;
} }
Future<void> turnOncreen() async { Future<void> turnOncreen() async {
await setBlFile(_on); await setBlFile(_on);
_screenStatus = true;
} }
File blFile() { File blFile() {
return File("/sys/class/backlight/10-0045/bl_power"); return File("/sys/class/backlight/10-0045/bl_power");
} }
Future<bool> isScreenOff() async {
final status = await blFile().readAsString();
if (status.startsWith(_on)) return false;
return true;
}
Future<void> setBlFile(String content) async { Future<void> setBlFile(String content) async {
await blFile().writeAsString(content); await blFile().writeAsString(content);
} }
Widget screenActivator() {
// only show when screen is dark
return Visibility(
visible: !_screenStatus,
child: SizedBox(
height: double.infinity,
width: double.infinity,
child: Material(
color: Colors.black,
child: InkWell(onTap: () async {
await turnOncreen();
}),
),
),
);
}

Loading…
Cancel
Save