mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-21 23:10:40 +00:00
Removed redundant methods from ServicesProvider
This commit is contained in:
parent
ee3bf31856
commit
f17e4edb2d
11 changed files with 39 additions and 63 deletions
|
@ -90,6 +90,8 @@ class Application extends StatelessWidget {
|
|||
} else if (snapshot.error != null) {
|
||||
return Center(child: Text(snapshot.error!.toString()));
|
||||
}
|
||||
|
||||
// TODO(@vodemn): maybe user splashscreen instead
|
||||
return const SizedBox();
|
||||
},
|
||||
);
|
||||
|
|
|
@ -33,7 +33,7 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
|||
EquipmentProfile get _selectedProfile => _customProfiles.firstWhere(
|
||||
(e) => e.id == _selectedId,
|
||||
orElse: () {
|
||||
ServicesProvider.userPreferencesServiceOf(context).selectedEquipmentProfileId =
|
||||
ServicesProvider.of(context).userPreferencesService.selectedEquipmentProfileId =
|
||||
_defaultProfile.id;
|
||||
return _defaultProfile;
|
||||
},
|
||||
|
@ -42,8 +42,8 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedId = ServicesProvider.userPreferencesServiceOf(context).selectedEquipmentProfileId;
|
||||
_customProfiles = ServicesProvider.userPreferencesServiceOf(context).equipmentProfiles;
|
||||
_selectedId = ServicesProvider.of(context).userPreferencesService.selectedEquipmentProfileId;
|
||||
_customProfiles = ServicesProvider.of(context).userPreferencesService.equipmentProfiles;
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -59,7 +59,7 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
|||
setState(() {
|
||||
_selectedId = data.id;
|
||||
});
|
||||
ServicesProvider.userPreferencesServiceOf(context).selectedEquipmentProfileId =
|
||||
ServicesProvider.of(context).userPreferencesService.selectedEquipmentProfileId =
|
||||
_selectedProfile.id;
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ class EquipmentProfileProviderState extends State<EquipmentProfileProvider> {
|
|||
}
|
||||
|
||||
void _refreshSavedProfiles() {
|
||||
ServicesProvider.userPreferencesServiceOf(context).equipmentProfiles = _customProfiles;
|
||||
ServicesProvider.of(context).userPreferencesService.equipmentProfiles = _customProfiles;
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +132,8 @@ class EquipmentProfiles extends InheritedModel<EquipmentProfilesAspect> {
|
|||
|
||||
@override
|
||||
bool updateShouldNotifyDependent(
|
||||
EquipmentProfiles oldWidget, Set<EquipmentProfilesAspect> dependencies,) =>
|
||||
EquipmentProfiles oldWidget,
|
||||
Set<EquipmentProfilesAspect> dependencies,
|
||||
) =>
|
||||
false;
|
||||
}
|
||||
|
|
|
@ -27,35 +27,7 @@ class ServicesProvider extends InheritedWidget {
|
|||
required super.child,
|
||||
});
|
||||
|
||||
static CaffeineService caffeineServiceOf(BuildContext context) {
|
||||
return ServicesProvider._of(context).caffeineService;
|
||||
}
|
||||
|
||||
static Environment environmentOf(BuildContext context) {
|
||||
return ServicesProvider._of(context).environment;
|
||||
}
|
||||
|
||||
static HapticsService hapticsServiceOf(BuildContext context) {
|
||||
return ServicesProvider._of(context).hapticsService;
|
||||
}
|
||||
|
||||
static LightSensorService lightSensorServiceOf(BuildContext context) {
|
||||
return ServicesProvider._of(context).lightSensorService;
|
||||
}
|
||||
|
||||
static PermissionsService permissionsServiceOf(BuildContext context) {
|
||||
return ServicesProvider._of(context).permissionsService;
|
||||
}
|
||||
|
||||
static UserPreferencesService userPreferencesServiceOf(BuildContext context) {
|
||||
return ServicesProvider._of(context).userPreferencesService;
|
||||
}
|
||||
|
||||
static VolumeEventsService volumeEventsServiceOf(BuildContext context) {
|
||||
return ServicesProvider._of(context).volumeEventsService;
|
||||
}
|
||||
|
||||
static ServicesProvider _of(BuildContext context) {
|
||||
static ServicesProvider of(BuildContext context) {
|
||||
return context.findAncestorWidgetOfExactType<ServicesProvider>()!;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,12 +71,12 @@ class UserPreferencesProvider extends StatefulWidget {
|
|||
class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
||||
with WidgetsBindingObserver {
|
||||
UserPreferencesService get userPreferencesService =>
|
||||
ServicesProvider.userPreferencesServiceOf(context);
|
||||
ServicesProvider.of(context).userPreferencesService;
|
||||
|
||||
late bool dynamicColor = userPreferencesService.dynamicColor;
|
||||
late EvSourceType evSourceType;
|
||||
late final MeteringScreenLayoutConfig meteringScreenLayout =
|
||||
ServicesProvider.userPreferencesServiceOf(context).meteringScreenLayout;
|
||||
ServicesProvider.of(context).userPreferencesService.meteringScreenLayout;
|
||||
late Color primaryColor = userPreferencesService.primaryColor;
|
||||
late StopType stopType = userPreferencesService.stopType;
|
||||
late SupportedLocale locale = userPreferencesService.locale;
|
||||
|
@ -85,9 +85,9 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
evSourceType = ServicesProvider.userPreferencesServiceOf(context).evSourceType;
|
||||
evSourceType = ServicesProvider.of(context).userPreferencesService.evSourceType;
|
||||
evSourceType = evSourceType == EvSourceType.sensor &&
|
||||
!ServicesProvider.environmentOf(context).hasLightSensor
|
||||
!ServicesProvider.of(context).environment.hasLightSensor
|
||||
? EvSourceType.camera
|
||||
: evSourceType;
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
|
@ -145,11 +145,11 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
|||
setState(() {
|
||||
dynamicColor = enable;
|
||||
});
|
||||
ServicesProvider.userPreferencesServiceOf(context).dynamicColor = enable;
|
||||
ServicesProvider.of(context).userPreferencesService.dynamicColor = enable;
|
||||
}
|
||||
|
||||
void toggleEvSourceType() {
|
||||
if (!ServicesProvider.environmentOf(context).hasLightSensor) {
|
||||
if (!ServicesProvider.of(context).environment.hasLightSensor) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
|
@ -160,7 +160,7 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
|||
evSourceType = EvSourceType.camera;
|
||||
}
|
||||
});
|
||||
ServicesProvider.userPreferencesServiceOf(context).evSourceType = evSourceType;
|
||||
ServicesProvider.of(context).userPreferencesService.evSourceType = evSourceType;
|
||||
}
|
||||
|
||||
void setLocale(SupportedLocale locale) {
|
||||
|
@ -168,7 +168,7 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
|||
setState(() {
|
||||
this.locale = locale;
|
||||
});
|
||||
ServicesProvider.userPreferencesServiceOf(context).locale = locale;
|
||||
ServicesProvider.of(context).userPreferencesService.locale = locale;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -182,28 +182,28 @@ class _UserPreferencesProviderState extends State<UserPreferencesProvider>
|
|||
);
|
||||
});
|
||||
});
|
||||
ServicesProvider.userPreferencesServiceOf(context).meteringScreenLayout = meteringScreenLayout;
|
||||
ServicesProvider.of(context).userPreferencesService.meteringScreenLayout = meteringScreenLayout;
|
||||
}
|
||||
|
||||
void setPrimaryColor(Color primaryColor) {
|
||||
setState(() {
|
||||
this.primaryColor = primaryColor;
|
||||
});
|
||||
ServicesProvider.userPreferencesServiceOf(context).primaryColor = primaryColor;
|
||||
ServicesProvider.of(context).userPreferencesService.primaryColor = primaryColor;
|
||||
}
|
||||
|
||||
void setStopType(StopType stopType) {
|
||||
setState(() {
|
||||
this.stopType = stopType;
|
||||
});
|
||||
ServicesProvider.userPreferencesServiceOf(context).stopType = stopType;
|
||||
ServicesProvider.of(context).userPreferencesService.stopType = stopType;
|
||||
}
|
||||
|
||||
void setThemeType(ThemeType themeType) {
|
||||
setState(() {
|
||||
this.themeType = themeType;
|
||||
});
|
||||
ServicesProvider.userPreferencesServiceOf(context).themeType = themeType;
|
||||
ServicesProvider.of(context).userPreferencesService.themeType = themeType;
|
||||
}
|
||||
|
||||
Brightness get _themeBrightness {
|
||||
|
|
|
@ -19,12 +19,12 @@ class _MeteringFlowState extends State<MeteringFlow> {
|
|||
Widget build(BuildContext context) {
|
||||
return MeteringInteractorProvider(
|
||||
data: MeteringInteractor(
|
||||
ServicesProvider.userPreferencesServiceOf(context),
|
||||
ServicesProvider.caffeineServiceOf(context),
|
||||
ServicesProvider.hapticsServiceOf(context),
|
||||
ServicesProvider.permissionsServiceOf(context),
|
||||
ServicesProvider.lightSensorServiceOf(context),
|
||||
ServicesProvider.volumeEventsServiceOf(context),
|
||||
ServicesProvider.of(context).userPreferencesService,
|
||||
ServicesProvider.of(context).caffeineService,
|
||||
ServicesProvider.of(context).hapticsService,
|
||||
ServicesProvider.of(context).permissionsService,
|
||||
ServicesProvider.of(context).lightSensorService,
|
||||
ServicesProvider.of(context).volumeEventsService,
|
||||
)..initialize(),
|
||||
child: MultiBlocProvider(
|
||||
providers: [
|
||||
|
@ -32,7 +32,7 @@ class _MeteringFlowState extends State<MeteringFlow> {
|
|||
BlocProvider(
|
||||
create: (context) => MeteringBloc(
|
||||
MeteringInteractorProvider.of(context),
|
||||
VolumeKeysNotifier(ServicesProvider.volumeEventsServiceOf(context)),
|
||||
VolumeKeysNotifier(ServicesProvider.of(context).volumeEventsService),
|
||||
context.read<MeteringCommunicationBloc>(),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -47,7 +47,7 @@ class MeteringScreen extends StatelessWidget {
|
|||
builder: (context, state) => MeteringBottomControlsProvider(
|
||||
ev: state is MeteringDataState ? state.ev : null,
|
||||
isMetering: state.isMetering,
|
||||
onSwitchEvSourceType: ServicesProvider.environmentOf(context).hasLightSensor
|
||||
onSwitchEvSourceType: ServicesProvider.of(context).environment.hasLightSensor
|
||||
? UserPreferencesProvider.of(context).toggleEvSourceType
|
||||
: null,
|
||||
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
|
||||
|
|
|
@ -13,7 +13,7 @@ class ReportIssueListTile extends StatelessWidget {
|
|||
title: Text(S.of(context).reportIssue),
|
||||
onTap: () {
|
||||
launchUrl(
|
||||
Uri.parse(ServicesProvider.environmentOf(context).issuesReportUrl),
|
||||
Uri.parse(ServicesProvider.of(context).environment.issuesReportUrl),
|
||||
mode: LaunchMode.externalApplication,
|
||||
);
|
||||
},
|
||||
|
|
|
@ -13,7 +13,7 @@ class SourceCodeListTile extends StatelessWidget {
|
|||
title: Text(S.of(context).sourceCode),
|
||||
onTap: () {
|
||||
launchUrl(
|
||||
Uri.parse(ServicesProvider.environmentOf(context).sourceCodeUrl),
|
||||
Uri.parse(ServicesProvider.of(context).environment.sourceCodeUrl),
|
||||
mode: LaunchMode.externalApplication,
|
||||
);
|
||||
},
|
||||
|
|
|
@ -13,7 +13,7 @@ class WriteEmailListTile extends StatelessWidget {
|
|||
leading: const Icon(Icons.email),
|
||||
title: Text(S.of(context).writeEmail),
|
||||
onTap: () {
|
||||
final email = ServicesProvider.environmentOf(context).contactEmail;
|
||||
final email = ServicesProvider.of(context).environment.contactEmail;
|
||||
final mailToUrl = Uri.parse('mailto:$email?subject=M3 Lightmeter');
|
||||
canLaunchUrl(mailToUrl).then((canLaunch) {
|
||||
if (canLaunch) {
|
||||
|
|
|
@ -14,7 +14,7 @@ class CalibrationDialog extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool hasLightSensor = ServicesProvider.environmentOf(context).hasLightSensor;
|
||||
final bool hasLightSensor = ServicesProvider.of(context).environment.hasLightSensor;
|
||||
return AlertDialog(
|
||||
icon: const Icon(Icons.settings_brightness),
|
||||
titlePadding: Dimens.dialogIconTitlePadding,
|
||||
|
|
|
@ -10,10 +10,10 @@ class SettingsFlow extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
return SettingsInteractorProvider(
|
||||
data: SettingsInteractor(
|
||||
ServicesProvider.userPreferencesServiceOf(context),
|
||||
ServicesProvider.caffeineServiceOf(context),
|
||||
ServicesProvider.hapticsServiceOf(context),
|
||||
ServicesProvider.volumeEventsServiceOf(context),
|
||||
ServicesProvider.of(context).userPreferencesService,
|
||||
ServicesProvider.of(context).caffeineService,
|
||||
ServicesProvider.of(context).hapticsService,
|
||||
ServicesProvider.of(context).volumeEventsService,
|
||||
),
|
||||
child: const SettingsScreen(),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue