From 2d143c48dee9ff5f0bd241e6a393656b6ad1db3d Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Thu, 11 Jan 2024 13:13:26 +0100 Subject: [PATCH] disable pro features in settings --- ...dget_list_tile_metering_screen_layout.dart | 10 ++++++++ .../dialog_switch/widget_dialog_switch.dart | 19 ++++++++++----- .../shared/disable/widget_disable.dart | 24 +++++++++++++++++++ .../iap_list_tile/widget_list_tile_iap.dart | 8 +++---- .../widget_list_tile_primary_color.dart | 13 ++++------ 5 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 lib/screens/settings/components/shared/disable/widget_disable.dart diff --git a/lib/screens/settings/components/metering/components/metering_screen_layout/widget_list_tile_metering_screen_layout.dart b/lib/screens/settings/components/metering/components/metering_screen_layout/widget_list_tile_metering_screen_layout.dart index 1f89b4b..9dfb026 100644 --- a/lib/screens/settings/components/metering/components/metering_screen_layout/widget_list_tile_metering_screen_layout.dart +++ b/lib/screens/settings/components/metering/components/metering_screen_layout/widget_list_tile_metering_screen_layout.dart @@ -5,6 +5,7 @@ import 'package:lightmeter/providers/equipment_profile_provider.dart'; import 'package:lightmeter/providers/films_provider.dart'; import 'package:lightmeter/providers/user_preferences_provider.dart'; import 'package:lightmeter/screens/settings/components/shared/dialog_switch/widget_dialog_switch.dart'; +import 'package:lightmeter/utils/context_utils.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; class MeteringScreenLayoutListTile extends StatelessWidget { @@ -24,6 +25,15 @@ class MeteringScreenLayoutListTile extends StatelessWidget { description: S.of(context).meteringScreenLayoutHint, values: UserPreferencesProvider.meteringScreenConfigOf(context), titleAdapter: _toStringLocalized, + enabledAdapter: (value) { + switch (value) { + case MeteringScreenLayoutFeature.equipmentProfiles: + case MeteringScreenLayoutFeature.filmPicker: + return context.isPro; + default: + return true; + } + }, onSave: (value) { if (!value[MeteringScreenLayoutFeature.equipmentProfiles]!) { EquipmentProfileProvider.of(context).setProfile(EquipmentProfiles.of(context).first); diff --git a/lib/screens/settings/components/shared/dialog_switch/widget_dialog_switch.dart b/lib/screens/settings/components/shared/dialog_switch/widget_dialog_switch.dart index aa3a370..fdf7cc5 100644 --- a/lib/screens/settings/components/shared/dialog_switch/widget_dialog_switch.dart +++ b/lib/screens/settings/components/shared/dialog_switch/widget_dialog_switch.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/res/dimens.dart'; +import 'package:lightmeter/screens/settings/components/shared/disable/widget_disable.dart'; typedef StringAdapter = String Function(BuildContext context, T value); @@ -11,6 +12,7 @@ class DialogSwitch extends StatefulWidget { final Map values; final StringAdapter titleAdapter; final StringAdapter? subtitleAdapter; + final bool Function(T value)? enabledAdapter; final ValueChanged> onSave; const DialogSwitch({ @@ -20,6 +22,7 @@ class DialogSwitch extends StatefulWidget { required this.values, required this.titleAdapter, this.subtitleAdapter, + this.enabledAdapter, required this.onSave, super.key, }); @@ -52,9 +55,12 @@ class _DialogSwitchState extends State> { ], ListView( shrinkWrap: true, - children: _features.entries - .map( - (entry) => SwitchListTile( + children: _features.entries.map( + (entry) { + final isEnabled = widget.enabledAdapter?.call(entry.key) ?? true; + return Disable( + disable: !isEnabled, + child: SwitchListTile( contentPadding: EdgeInsets.symmetric(horizontal: Dimens.dialogTitlePadding.left), title: Text(widget.titleAdapter(context, entry.key)), subtitle: widget.subtitleAdapter != null @@ -63,15 +69,16 @@ class _DialogSwitchState extends State> { style: Theme.of(context).listTileTheme.subtitleTextStyle, ) : null, - value: _features[entry.key]!, + value: isEnabled && _features[entry.key]!, onChanged: (value) { setState(() { _features.update(entry.key, (_) => value); }); }, ), - ) - .toList(), + ); + }, + ).toList(), ), ], ), diff --git a/lib/screens/settings/components/shared/disable/widget_disable.dart b/lib/screens/settings/components/shared/disable/widget_disable.dart new file mode 100644 index 0000000..3b1d276 --- /dev/null +++ b/lib/screens/settings/components/shared/disable/widget_disable.dart @@ -0,0 +1,24 @@ +import 'package:flutter/material.dart'; +import 'package:lightmeter/res/dimens.dart'; + +class Disable extends StatelessWidget { + final bool disable; + final Widget? child; + + const Disable({ + this.disable = true, + this.child, + super.key, + }); + + @override + Widget build(BuildContext context) { + return Opacity( + opacity: disable ? Dimens.disabledOpacity : Dimens.enabledOpacity, + child: IgnorePointer( + ignoring: disable, + child: child, + ), + ); + } +} 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 a2b980f..5fd1d3d 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,5 @@ import 'package:flutter/material.dart'; -import 'package:lightmeter/res/dimens.dart'; +import 'package:lightmeter/screens/settings/components/shared/disable/widget_disable.dart'; import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; /// Depends on the product status and replaces [onTap] with purchase callback @@ -23,12 +23,12 @@ class IAPListTile extends StatelessWidget { @override Widget build(BuildContext context) { final isPurchased = IAPProducts.isPurchased(context, IAPProductType.paidFeatures); - return Opacity( - opacity: isPurchased ? Dimens.enabledOpacity : Dimens.disabledOpacity, + return Disable( + disable: !isPurchased, child: ListTile( leading: leading, title: title, - onTap: isPurchased ? onTap : null, + onTap: onTap, ), ); } diff --git a/lib/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart b/lib/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart index 44de22e..1cf8762 100644 --- a/lib/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart +++ b/lib/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/data/models/dynamic_colors_state.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/providers/user_preferences_provider.dart'; -import 'package:lightmeter/res/dimens.dart'; +import 'package:lightmeter/screens/settings/components/shared/disable/widget_disable.dart'; import 'package:lightmeter/screens/settings/components/theme/components/primary_color/components/primary_color_picker_dialog/widget_dialog_picker_primary_color.dart'; class PrimaryColorListTile extends StatelessWidget { @@ -11,13 +11,10 @@ class PrimaryColorListTile extends StatelessWidget { @override Widget build(BuildContext context) { if (UserPreferencesProvider.dynamicColorStateOf(context) == DynamicColorState.enabled) { - return Opacity( - opacity: Dimens.disabledOpacity, - child: IgnorePointer( - child: ListTile( - leading: const Icon(Icons.palette), - title: Text(S.of(context).primaryColor), - ), + return Disable( + child: ListTile( + leading: const Icon(Icons.palette), + title: Text(S.of(context).primaryColor), ), ); }