parent
							
								
									a1aa552947
								
							
						
					
					
						commit
						c1624d7e05
					
				| @ -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…
					
					
				
		Reference in new issue