From 3fbe9ce046d9150702c3063e354b4ce227218386 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Mon, 15 Jan 2024 20:03:22 +0100 Subject: [PATCH] replaced `IAPProducts.isPurchased` with context extension --- lib/providers/equipment_profile_provider.dart | 5 +++-- lib/providers/films_provider.dart | 7 +++---- .../components/camera_preview/widget_camera_preview.dart | 4 ++-- .../camera_container/widget_container_camera.dart | 4 +--- .../readings_container/widget_container_readings.dart | 8 +++----- .../shared/iap_list_tile/widget_list_tile_iap.dart | 4 ++-- lib/screens/settings/screen_settings.dart | 5 ++--- 7 files changed, 16 insertions(+), 21 deletions(-) diff --git a/lib/providers/equipment_profile_provider.dart b/lib/providers/equipment_profile_provider.dart index 564c5ef..74397a5 100644 --- a/lib/providers/equipment_profile_provider.dart +++ b/lib/providers/equipment_profile_provider.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:lightmeter/utils/context_utils.dart'; import 'package:lightmeter/utils/selectable_provider.dart'; import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; @@ -52,9 +53,9 @@ class EquipmentProfileProviderState extends State { return EquipmentProfiles( values: [ _defaultProfile, - if (IAPProducts.isPurchased(context, IAPProductType.paidFeatures)) ..._customProfiles, + if (context.isPro) ..._customProfiles, ], - selected: IAPProducts.isPurchased(context, IAPProductType.paidFeatures) ? _selectedProfile : _defaultProfile, + selected: context.isPro ? _selectedProfile : _defaultProfile, child: widget.child, ); } diff --git a/lib/providers/films_provider.dart b/lib/providers/films_provider.dart index aff6d01..3e9d02d 100644 --- a/lib/providers/films_provider.dart +++ b/lib/providers/films_provider.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:lightmeter/utils/context_utils.dart'; import 'package:lightmeter/utils/selectable_provider.dart'; import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; @@ -44,11 +45,9 @@ class FilmsProviderState extends State { ], filmsInUse: [ const Film.other(), - if (IAPProducts.isPurchased(context, IAPProductType.paidFeatures)) ..._filmsInUse, + if (context.isPro) ..._filmsInUse, ], - selected: IAPProducts.isPurchased(context, IAPProductType.paidFeatures) - ? _selected - : const Film.other(), + selected: context.isPro ? _selected : const Film.other(), child: widget.child, ); } diff --git a/lib/screens/metering/components/camera_container/components/camera_preview/widget_camera_preview.dart b/lib/screens/metering/components/camera_container/components/camera_preview/widget_camera_preview.dart index e6f1699..464228f 100644 --- a/lib/screens/metering/components/camera_container/components/camera_preview/widget_camera_preview.dart +++ b/lib/screens/metering/components/camera_container/components/camera_preview/widget_camera_preview.dart @@ -9,7 +9,7 @@ import 'package:lightmeter/screens/metering/components/camera_container/componen import 'package:lightmeter/screens/metering/components/camera_container/components/camera_preview/components/camera_view_placeholder/widget_placeholder_camera_view.dart'; import 'package:lightmeter/screens/metering/components/camera_container/components/camera_preview/components/histogram/widget_histogram.dart'; import 'package:lightmeter/screens/metering/components/camera_container/models/camera_error_type.dart'; -import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; +import 'package:lightmeter/utils/context_utils.dart'; class CameraPreview extends StatefulWidget { final CameraController? controller; @@ -93,7 +93,7 @@ class _CameraPreviewBuilderState extends State<_CameraPreviewBuilder> { alignment: Alignment.bottomCenter, children: [ CameraView(controller: widget.controller), - if (IAPProducts.isPurchased(context, IAPProductType.paidFeatures)) ...[ + if (context.isPro) ...[ if (UserPreferencesProvider.cameraFeatureOf( context, CameraFeature.histogram, diff --git a/lib/screens/metering/components/camera_container/widget_container_camera.dart b/lib/screens/metering/components/camera_container/widget_container_camera.dart index a4cb3e8..5ed2b43 100644 --- a/lib/screens/metering/components/camera_container/widget_container_camera.dart +++ b/lib/screens/metering/components/camera_container/widget_container_camera.dart @@ -17,7 +17,6 @@ import 'package:lightmeter/screens/metering/components/shared/exposure_pairs_lis import 'package:lightmeter/screens/metering/components/shared/metering_top_bar/widget_top_bar_metering.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/widget_container_readings.dart'; import 'package:lightmeter/utils/context_utils.dart'; -import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; class CameraContainer extends StatelessWidget { @@ -102,9 +101,8 @@ class CameraContainer extends StatelessWidget { } double _meteringContainerHeight(BuildContext context) { - final isPro = IAPProducts.isPurchased(context, IAPProductType.paidFeatures); double enabledFeaturesHeight = 0; - if (!isPro) { + if (!context.isPro) { enabledFeaturesHeight += Dimens.readingContainerSingleValueHeight; enabledFeaturesHeight += Dimens.paddingS; } else { diff --git a/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart b/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart index 30d1392..ce373a8 100644 --- a/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart +++ b/lib/screens/metering/components/shared/readings_container/widget_container_readings.dart @@ -10,7 +10,6 @@ import 'package:lightmeter/screens/metering/components/shared/readings_container import 'package:lightmeter/screens/metering/components/shared/readings_container/components/lightmeter_pro/widget_lightmeter_pro.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/nd_picker/widget_picker_nd.dart'; import 'package:lightmeter/utils/context_utils.dart'; -import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; class ReadingsContainer extends StatelessWidget { @@ -33,15 +32,14 @@ class ReadingsContainer extends StatelessWidget { @override Widget build(BuildContext context) { - final isPro = IAPProducts.isPurchased(context, IAPProductType.paidFeatures); return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - if (!isPro) ...[ + if (!context.isPro) ...[ const LightmeterProAnimatedDialog(), const _InnerPadding(), ], - if (isPro && context.meteringFeature(MeteringScreenLayoutFeature.equipmentProfiles)) ...[ + if (context.isPro && context.meteringFeature(MeteringScreenLayoutFeature.equipmentProfiles)) ...[ const EquipmentProfilePicker(), const _InnerPadding(), ], @@ -52,7 +50,7 @@ class ReadingsContainer extends StatelessWidget { ), const _InnerPadding(), ], - if (isPro && context.meteringFeature(MeteringScreenLayoutFeature.filmPicker)) ...[ + if (context.isPro && context.meteringFeature(MeteringScreenLayoutFeature.filmPicker)) ...[ FilmPicker(selectedIso: iso), const _InnerPadding(), ], diff --git a/lib/screens/settings/components/shared/iap_list_tile/widget_list_tile_iap.dart b/lib/screens/settings/components/shared/iap_list_tile/widget_list_tile_iap.dart index 5fd1d3d..8cc522a 100644 --- a/lib/screens/settings/components/shared/iap_list_tile/widget_list_tile_iap.dart +++ b/lib/screens/settings/components/shared/iap_list_tile/widget_list_tile_iap.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/screens/settings/components/shared/disable/widget_disable.dart'; +import 'package:lightmeter/utils/context_utils.dart'; import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; /// Depends on the product status and replaces [onTap] with purchase callback @@ -22,9 +23,8 @@ class IAPListTile extends StatelessWidget { @override Widget build(BuildContext context) { - final isPurchased = IAPProducts.isPurchased(context, IAPProductType.paidFeatures); return Disable( - disable: !isPurchased, + disable: !context.isPro, child: ListTile( leading: leading, title: title, diff --git a/lib/screens/settings/screen_settings.dart b/lib/screens/settings/screen_settings.dart index ea8e1c5..295e01c 100644 --- a/lib/screens/settings/screen_settings.dart +++ b/lib/screens/settings/screen_settings.dart @@ -7,7 +7,7 @@ import 'package:lightmeter/screens/settings/components/metering/widget_settings_ import 'package:lightmeter/screens/settings/components/theme/widget_settings_section_theme.dart'; import 'package:lightmeter/screens/settings/flow_settings.dart'; import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart'; -import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; +import 'package:lightmeter/utils/context_utils.dart'; class SettingsScreen extends StatefulWidget { const SettingsScreen({super.key}); @@ -38,8 +38,7 @@ class _SettingsScreenState extends State { SliverList( delegate: SliverChildListDelegate( [ - if (!IAPProducts.isPurchased(context, IAPProductType.paidFeatures)) - const LightmeterProSettingsSection(), + if (!context.isPro) const LightmeterProSettingsSection(), const MeteringSettingsSection(), const GeneralSettingsSection(), const ThemeSettingsSection(),