disable pro features in settings

This commit is contained in:
Vadim 2024-01-11 13:13:26 +01:00
parent bab8679159
commit 2d143c48de
5 changed files with 56 additions and 18 deletions

View file

@ -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);

View file

@ -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<T> = String Function(BuildContext context, T value);
@ -11,6 +12,7 @@ class DialogSwitch<T> extends StatefulWidget {
final Map<T, bool> values;
final StringAdapter<T> titleAdapter;
final StringAdapter<T>? subtitleAdapter;
final bool Function(T value)? enabledAdapter;
final ValueChanged<Map<T, bool>> onSave;
const DialogSwitch({
@ -20,6 +22,7 @@ class DialogSwitch<T> extends StatefulWidget {
required this.values,
required this.titleAdapter,
this.subtitleAdapter,
this.enabledAdapter,
required this.onSave,
super.key,
});
@ -52,9 +55,12 @@ class _DialogSwitchState<T> extends State<DialogSwitch<T>> {
],
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<T> extends State<DialogSwitch<T>> {
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(),
),
],
),

View file

@ -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,
),
);
}
}

View file

@ -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,
),
);
}

View file

@ -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,14 +11,11 @@ class PrimaryColorListTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (UserPreferencesProvider.dynamicColorStateOf(context) == DynamicColorState.enabled) {
return Opacity(
opacity: Dimens.disabledOpacity,
child: IgnorePointer(
return Disable(
child: ListTile(
leading: const Icon(Icons.palette),
title: Text(S.of(context).primaryColor),
),
),
);
}
return ListTile(