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 {
|
|
|
|
return await LightSensor.hasSensor ?? false;
|
|
|
|
} 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();
|
|
|
|
}
|
|
|
|
return LightSensor.lightSensorStream;
|
|
|
|
}
|
2023-01-29 16:57:47 +00:00
|
|
|
}
|