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 {
|
2024-04-12 06:07:20 +00:00
|
|
|
if (localPlatform.isIOS) {
|
2023-07-09 11:39:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
2023-05-01 09:07:07 +00:00
|
|
|
try {
|
2023-10-20 14:12:43 +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() {
|
2024-04-12 06:07:20 +00:00
|
|
|
if (localPlatform.isIOS) {
|
2023-07-09 11:39:33 +00:00
|
|
|
return const Stream<int>.empty();
|
|
|
|
}
|
2023-10-20 14:12:43 +00:00
|
|
|
return LightSensor.luxStream();
|
2023-07-09 11:39:33 +00:00
|
|
|
}
|
2023-01-29 16:57:47 +00:00
|
|
|
}
|