2023-08-13 13:27:43 +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';
|
|
|
|
import 'package:lightmeter/data/volume_events_service.dart';
|
|
|
|
import 'package:lightmeter/environment.dart';
|
|
|
|
|
2023-08-13 19:14:32 +00:00
|
|
|
class ServicesProvider extends InheritedWidget {
|
2023-08-13 13:27:43 +00:00
|
|
|
final CaffeineService caffeineService;
|
|
|
|
final Environment environment;
|
|
|
|
final HapticsService hapticsService;
|
|
|
|
final LightSensorService lightSensorService;
|
|
|
|
final PermissionsService permissionsService;
|
|
|
|
final UserPreferencesService userPreferencesService;
|
|
|
|
final VolumeEventsService volumeEventsService;
|
|
|
|
|
2023-08-13 19:14:32 +00:00
|
|
|
const ServicesProvider({
|
2023-08-13 13:27:43 +00:00
|
|
|
required this.caffeineService,
|
|
|
|
required this.environment,
|
|
|
|
required this.hapticsService,
|
|
|
|
required this.lightSensorService,
|
|
|
|
required this.permissionsService,
|
|
|
|
required this.userPreferencesService,
|
|
|
|
required this.volumeEventsService,
|
|
|
|
required super.child,
|
|
|
|
});
|
|
|
|
|
|
|
|
static CaffeineService caffeineServiceOf(BuildContext context) {
|
2023-08-13 19:14:32 +00:00
|
|
|
return ServicesProvider._of(context).caffeineService;
|
2023-08-13 13:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Environment environmentOf(BuildContext context) {
|
2023-08-13 19:14:32 +00:00
|
|
|
return ServicesProvider._of(context).environment;
|
2023-08-13 13:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HapticsService hapticsServiceOf(BuildContext context) {
|
2023-08-13 19:14:32 +00:00
|
|
|
return ServicesProvider._of(context).hapticsService;
|
2023-08-13 13:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static LightSensorService lightSensorServiceOf(BuildContext context) {
|
2023-08-13 19:14:32 +00:00
|
|
|
return ServicesProvider._of(context).lightSensorService;
|
2023-08-13 13:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PermissionsService permissionsServiceOf(BuildContext context) {
|
2023-08-13 19:14:32 +00:00
|
|
|
return ServicesProvider._of(context).permissionsService;
|
2023-08-13 13:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static UserPreferencesService userPreferencesServiceOf(BuildContext context) {
|
2023-08-13 19:14:32 +00:00
|
|
|
return ServicesProvider._of(context).userPreferencesService;
|
2023-08-13 13:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VolumeEventsService volumeEventsServiceOf(BuildContext context) {
|
2023-08-13 19:14:32 +00:00
|
|
|
return ServicesProvider._of(context).volumeEventsService;
|
2023-08-13 13:27:43 +00:00
|
|
|
}
|
|
|
|
|
2023-08-13 19:14:32 +00:00
|
|
|
static ServicesProvider _of(BuildContext context) {
|
|
|
|
return context.findAncestorWidgetOfExactType<ServicesProvider>()!;
|
2023-08-13 13:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-08-13 19:14:32 +00:00
|
|
|
bool updateShouldNotify(ServicesProvider oldWidget) => false;
|
2023-08-13 13:27:43 +00:00
|
|
|
}
|