[Android] Probably fixed grey screen issue

This commit is contained in:
Vadim 2023-05-01 11:07:07 +02:00
parent d3512faa9b
commit 77cbd11268
2 changed files with 12 additions and 4 deletions

View file

@ -3,7 +3,6 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:light_sensor/light_sensor.dart';
import 'package:lightmeter/data/caffeine_service.dart';
import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/models/supported_locale.dart';
@ -34,7 +33,7 @@ class Application extends StatelessWidget {
return FutureBuilder(
future: Future.wait([
SharedPreferences.getInstance(),
Platform.isAndroid ? LightSensor.hasSensor : Future.value(false),
Platform.isAndroid ? const LightSensorService().hasSensor() : Future.value(false),
]),
builder: (_, snapshot) {
if (snapshot.data != null) {
@ -83,8 +82,11 @@ class Application extends StatelessWidget {
),
),
);
} else if (snapshot.error != null) {
return Center(child: Text(snapshot.error!.toString()));
} else {
return const SizedBox.shrink();
}
return const SizedBox();
},
);
}

View file

@ -3,7 +3,13 @@ import 'package:light_sensor/light_sensor.dart';
class LightSensorService {
const LightSensorService();
Future<bool> hasSensor() async => await LightSensor.hasSensor ?? false;
Future<bool> hasSensor() async {
try {
return await LightSensor.hasSensor ?? false;
} catch (_) {
return false;
}
}
Stream<int> luxStream() => LightSensor.lightSensorStream;
}