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