2023-09-28 21:29:33 +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';
|
2023-10-28 20:40:56 +00:00
|
|
|
import 'package:lightmeter/data/remote_config_service.dart';
|
2023-09-28 21:29:33 +00:00
|
|
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
|
|
|
import 'package:lightmeter/data/volume_events_service.dart';
|
|
|
|
import 'package:lightmeter/environment.dart';
|
2023-10-20 14:12:43 +00:00
|
|
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
|
|
|
import 'package:lightmeter/providers/films_provider.dart';
|
2023-10-28 20:40:56 +00:00
|
|
|
import 'package:lightmeter/providers/remote_config_provider.dart';
|
2023-09-28 21:29:33 +00:00
|
|
|
import 'package:lightmeter/providers/services_provider.dart';
|
|
|
|
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
|
|
|
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
|
|
|
import 'package:platform/platform.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
class ApplicationWrapper extends StatelessWidget {
|
|
|
|
final Environment env;
|
|
|
|
final Widget child;
|
|
|
|
|
|
|
|
const ApplicationWrapper(this.env, {required this.child, super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FutureBuilder(
|
2023-10-28 20:40:56 +00:00
|
|
|
future: Future.wait<dynamic>([
|
2023-09-28 21:29:33 +00:00
|
|
|
SharedPreferences.getInstance(),
|
|
|
|
const LightSensorService(LocalPlatform()).hasSensor(),
|
2023-10-28 20:40:56 +00:00
|
|
|
const RemoteConfigService().activeAndFetchFeatures(),
|
2023-09-28 21:29:33 +00:00
|
|
|
]),
|
|
|
|
builder: (_, snapshot) {
|
|
|
|
if (snapshot.data != null) {
|
2023-10-20 14:12:43 +00:00
|
|
|
final iapService = IAPStorageService(snapshot.data![0] as SharedPreferences);
|
|
|
|
final userPreferencesService = UserPreferencesService(snapshot.data![0] as SharedPreferences);
|
|
|
|
final hasLightSensor = snapshot.data![1] as bool;
|
|
|
|
return ServicesProvider(
|
|
|
|
caffeineService: const CaffeineService(),
|
|
|
|
environment: env.copyWith(hasLightSensor: hasLightSensor),
|
|
|
|
hapticsService: const HapticsService(),
|
|
|
|
lightSensorService: const LightSensorService(LocalPlatform()),
|
|
|
|
permissionsService: const PermissionsService(),
|
2023-10-28 20:40:56 +00:00
|
|
|
remoteConfigService: const RemoteConfigService(),
|
2023-10-20 14:12:43 +00:00
|
|
|
userPreferencesService: userPreferencesService,
|
|
|
|
volumeEventsService: const VolumeEventsService(LocalPlatform()),
|
2023-10-28 20:40:56 +00:00
|
|
|
child: RemoteConfig(
|
|
|
|
child: EquipmentProfileProvider(
|
2023-10-20 14:12:43 +00:00
|
|
|
storageService: iapService,
|
2023-10-28 20:40:56 +00:00
|
|
|
child: FilmsProvider(
|
|
|
|
storageService: iapService,
|
|
|
|
child: UserPreferencesProvider(
|
|
|
|
hasLightSensor: hasLightSensor,
|
|
|
|
userPreferencesService: userPreferencesService,
|
|
|
|
child: child,
|
|
|
|
),
|
2023-10-20 14:12:43 +00:00
|
|
|
),
|
2023-09-28 21:29:33 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else if (snapshot.error != null) {
|
|
|
|
return Center(child: Text(snapshot.error!.toString()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(@vodemn): maybe user splashscreen instead
|
|
|
|
return const SizedBox();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|