2023-01-29 16:57:47 +00:00
|
|
|
import 'package:light_sensor/light_sensor.dart';
|
2023-07-09 11:39:33 +00:00
|
|
|
import 'package:platform/platform.dart';
|
2023-01-29 16:57:47 +00:00
|
|
|
|
|
|
|
class LightSensorService {
|
2023-07-09 11:39:33 +00:00
|
|
|
final LocalPlatform localPlatform;
|
|
|
|
|
|
|
|
const LightSensorService(this.localPlatform);
|
2023-01-29 16:57:47 +00:00
|
|
|
|
2023-05-01 09:07:07 +00:00
|
|
|
Future<bool> hasSensor() async {
|
2023-07-09 11:39:33 +00:00
|
|
|
if (!localPlatform.isAndroid) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-05-01 09:07:07 +00:00
|
|
|
try {
|
2023-10-19 17:19:54 +00:00
|
|
|
return await LightSensor.hasSensor();
|
2023-05-01 09:07:07 +00:00
|
|
|
} catch (_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-01-29 16:57:47 +00:00
|
|
|
|
2023-07-09 11:39:33 +00:00
|
|
|
Stream<int> luxStream() {
|
|
|
|
if (!localPlatform.isAndroid) {
|
|
|
|
return const Stream<int>.empty();
|
|
|
|
}
|
2023-10-19 17:19:54 +00:00
|
|
|
return LightSensor.luxStream();
|
2023-07-09 11:39:33 +00:00
|
|
|
}
|
2023-01-29 16:57:47 +00:00
|
|
|
}
|