mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 15:30:59 +00:00
disable pro features in settings
This commit is contained in:
parent
bab8679159
commit
2d143c48de
5 changed files with 56 additions and 18 deletions
|
@ -5,6 +5,7 @@ import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
||||||
import 'package:lightmeter/providers/films_provider.dart';
|
import 'package:lightmeter/providers/films_provider.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_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/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';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class MeteringScreenLayoutListTile extends StatelessWidget {
|
class MeteringScreenLayoutListTile extends StatelessWidget {
|
||||||
|
@ -24,6 +25,15 @@ class MeteringScreenLayoutListTile extends StatelessWidget {
|
||||||
description: S.of(context).meteringScreenLayoutHint,
|
description: S.of(context).meteringScreenLayoutHint,
|
||||||
values: UserPreferencesProvider.meteringScreenConfigOf(context),
|
values: UserPreferencesProvider.meteringScreenConfigOf(context),
|
||||||
titleAdapter: _toStringLocalized,
|
titleAdapter: _toStringLocalized,
|
||||||
|
enabledAdapter: (value) {
|
||||||
|
switch (value) {
|
||||||
|
case MeteringScreenLayoutFeature.equipmentProfiles:
|
||||||
|
case MeteringScreenLayoutFeature.filmPicker:
|
||||||
|
return context.isPro;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
onSave: (value) {
|
onSave: (value) {
|
||||||
if (!value[MeteringScreenLayoutFeature.equipmentProfiles]!) {
|
if (!value[MeteringScreenLayoutFeature.equipmentProfiles]!) {
|
||||||
EquipmentProfileProvider.of(context).setProfile(EquipmentProfiles.of(context).first);
|
EquipmentProfileProvider.of(context).setProfile(EquipmentProfiles.of(context).first);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/res/dimens.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);
|
typedef StringAdapter<T> = String Function(BuildContext context, T value);
|
||||||
|
|
||||||
|
@ -11,6 +12,7 @@ class DialogSwitch<T> extends StatefulWidget {
|
||||||
final Map<T, bool> values;
|
final Map<T, bool> values;
|
||||||
final StringAdapter<T> titleAdapter;
|
final StringAdapter<T> titleAdapter;
|
||||||
final StringAdapter<T>? subtitleAdapter;
|
final StringAdapter<T>? subtitleAdapter;
|
||||||
|
final bool Function(T value)? enabledAdapter;
|
||||||
final ValueChanged<Map<T, bool>> onSave;
|
final ValueChanged<Map<T, bool>> onSave;
|
||||||
|
|
||||||
const DialogSwitch({
|
const DialogSwitch({
|
||||||
|
@ -20,6 +22,7 @@ class DialogSwitch<T> extends StatefulWidget {
|
||||||
required this.values,
|
required this.values,
|
||||||
required this.titleAdapter,
|
required this.titleAdapter,
|
||||||
this.subtitleAdapter,
|
this.subtitleAdapter,
|
||||||
|
this.enabledAdapter,
|
||||||
required this.onSave,
|
required this.onSave,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
@ -52,9 +55,12 @@ class _DialogSwitchState<T> extends State<DialogSwitch<T>> {
|
||||||
],
|
],
|
||||||
ListView(
|
ListView(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
children: _features.entries
|
children: _features.entries.map(
|
||||||
.map(
|
(entry) {
|
||||||
(entry) => SwitchListTile(
|
final isEnabled = widget.enabledAdapter?.call(entry.key) ?? true;
|
||||||
|
return Disable(
|
||||||
|
disable: !isEnabled,
|
||||||
|
child: SwitchListTile(
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: Dimens.dialogTitlePadding.left),
|
contentPadding: EdgeInsets.symmetric(horizontal: Dimens.dialogTitlePadding.left),
|
||||||
title: Text(widget.titleAdapter(context, entry.key)),
|
title: Text(widget.titleAdapter(context, entry.key)),
|
||||||
subtitle: widget.subtitleAdapter != null
|
subtitle: widget.subtitleAdapter != null
|
||||||
|
@ -63,15 +69,16 @@ class _DialogSwitchState<T> extends State<DialogSwitch<T>> {
|
||||||
style: Theme.of(context).listTileTheme.subtitleTextStyle,
|
style: Theme.of(context).listTileTheme.subtitleTextStyle,
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
value: _features[entry.key]!,
|
value: isEnabled && _features[entry.key]!,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_features.update(entry.key, (_) => value);
|
_features.update(entry.key, (_) => value);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
);
|
||||||
.toList(),
|
},
|
||||||
|
).toList(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -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,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
import 'package:flutter/material.dart';
|
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';
|
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||||
|
|
||||||
/// Depends on the product status and replaces [onTap] with purchase callback
|
/// Depends on the product status and replaces [onTap] with purchase callback
|
||||||
|
@ -23,12 +23,12 @@ class IAPListTile extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final isPurchased = IAPProducts.isPurchased(context, IAPProductType.paidFeatures);
|
final isPurchased = IAPProducts.isPurchased(context, IAPProductType.paidFeatures);
|
||||||
return Opacity(
|
return Disable(
|
||||||
opacity: isPurchased ? Dimens.enabledOpacity : Dimens.disabledOpacity,
|
disable: !isPurchased,
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: leading,
|
leading: leading,
|
||||||
title: title,
|
title: title,
|
||||||
onTap: isPurchased ? onTap : null,
|
onTap: onTap,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/data/models/dynamic_colors_state.dart';
|
import 'package:lightmeter/data/models/dynamic_colors_state.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.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';
|
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 {
|
class PrimaryColorListTile extends StatelessWidget {
|
||||||
|
@ -11,13 +11,10 @@ class PrimaryColorListTile extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (UserPreferencesProvider.dynamicColorStateOf(context) == DynamicColorState.enabled) {
|
if (UserPreferencesProvider.dynamicColorStateOf(context) == DynamicColorState.enabled) {
|
||||||
return Opacity(
|
return Disable(
|
||||||
opacity: Dimens.disabledOpacity,
|
child: ListTile(
|
||||||
child: IgnorePointer(
|
leading: const Icon(Icons.palette),
|
||||||
child: ListTile(
|
title: Text(S.of(context).primaryColor),
|
||||||
leading: const Icon(Icons.palette),
|
|
||||||
title: Text(S.of(context).primaryColor),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue