2023-06-04 11:04:04 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:lightmeter/data/caffeine_service.dart';
|
|
|
|
import 'package:lightmeter/data/haptics_service.dart';
|
|
|
|
import 'package:lightmeter/data/light_sensor_service.dart';
|
|
|
|
import 'package:lightmeter/data/permissions_service.dart';
|
|
|
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
2023-07-09 11:39:33 +00:00
|
|
|
import 'package:lightmeter/data/volume_events_service.dart';
|
2023-06-04 11:04:04 +00:00
|
|
|
import 'package:lightmeter/environment.dart';
|
2023-08-13 14:10:25 +00:00
|
|
|
import 'package:lightmeter/providers/enum_providers.dart';
|
2023-06-04 11:04:04 +00:00
|
|
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
|
|
|
import 'package:lightmeter/providers/metering_screen_layout_provider.dart';
|
2023-08-13 13:27:43 +00:00
|
|
|
import 'package:lightmeter/providers/service_providers.dart';
|
2023-06-04 11:04:04 +00:00
|
|
|
import 'package:lightmeter/providers/theme_provider.dart';
|
2023-07-09 11:39:33 +00:00
|
|
|
import 'package:platform/platform.dart';
|
2023-06-04 11:04:04 +00:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
class LightmeterProviders extends StatelessWidget {
|
|
|
|
final Environment env;
|
|
|
|
final Widget Function(BuildContext context, bool ready) builder;
|
|
|
|
|
|
|
|
const LightmeterProviders({required this.env, required this.builder, super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FutureBuilder(
|
|
|
|
future: Future.wait([
|
|
|
|
SharedPreferences.getInstance(),
|
2023-07-09 11:39:33 +00:00
|
|
|
const LightSensorService(LocalPlatform()).hasSensor(),
|
2023-06-04 11:04:04 +00:00
|
|
|
]),
|
|
|
|
builder: (_, snapshot) {
|
|
|
|
if (snapshot.data != null) {
|
2023-08-13 13:27:43 +00:00
|
|
|
return ServiceProviders(
|
|
|
|
caffeineService: const CaffeineService(),
|
|
|
|
environment: env.copyWith(hasLightSensor: snapshot.data![1] as bool),
|
|
|
|
hapticsService: const HapticsService(),
|
|
|
|
lightSensorService: const LightSensorService(LocalPlatform()),
|
|
|
|
permissionsService: const PermissionsService(),
|
|
|
|
userPreferencesService: UserPreferencesService(snapshot.data![0] as SharedPreferences),
|
|
|
|
volumeEventsService: const VolumeEventsService(LocalPlatform()),
|
2023-08-13 14:10:25 +00:00
|
|
|
child: EnumProviders(
|
|
|
|
child: MeteringScreenLayoutProvider(
|
2023-08-13 13:27:43 +00:00
|
|
|
child: EquipmentProfileProvider(
|
2023-08-13 14:10:25 +00:00
|
|
|
child: ThemeProvider(
|
|
|
|
child: Builder(
|
|
|
|
builder: (context) => builder(context, true),
|
2023-06-04 11:04:04 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else if (snapshot.error != null) {
|
|
|
|
return Center(child: Text(snapshot.error!.toString()));
|
|
|
|
}
|
|
|
|
return builder(context, false);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|