mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2025-03-12 13:20:42 +00:00
separated generic DialogSwitch
This commit is contained in:
parent
d54d2a121a
commit
5d75ac4a11
3 changed files with 118 additions and 100 deletions
|
@ -1,97 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||
import 'package:lightmeter/generated/l10n.dart';
|
||||
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/res/dimens.dart';
|
||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||
|
||||
class MeteringScreenLayoutFeaturesDialog extends StatefulWidget {
|
||||
const MeteringScreenLayoutFeaturesDialog({super.key});
|
||||
|
||||
@override
|
||||
State<MeteringScreenLayoutFeaturesDialog> createState() => _MeteringScreenLayoutFeaturesDialogState();
|
||||
}
|
||||
|
||||
class _MeteringScreenLayoutFeaturesDialogState extends State<MeteringScreenLayoutFeaturesDialog> {
|
||||
late final _features = MeteringScreenLayoutConfig.from(UserPreferencesProvider.meteringScreenConfigOf(context));
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(Icons.layers_outlined),
|
||||
titlePadding: Dimens.dialogIconTitlePadding,
|
||||
title: Text(S.of(context).meteringScreenLayout),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
content: SizedBox(
|
||||
width: double.maxFinite,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingL),
|
||||
child: Text(S.of(context).meteringScreenLayoutHint),
|
||||
),
|
||||
const SizedBox(height: Dimens.grid16),
|
||||
ListView(
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
_featureListTile(MeteringScreenLayoutFeature.equipmentProfiles),
|
||||
_featureListTile(MeteringScreenLayoutFeature.extremeExposurePairs),
|
||||
_featureListTile(MeteringScreenLayoutFeature.filmPicker),
|
||||
_featureListTile(MeteringScreenLayoutFeature.histogram),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actionsPadding: Dimens.dialogActionsPadding,
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: Navigator.of(context).pop,
|
||||
child: Text(S.of(context).cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (!_features[MeteringScreenLayoutFeature.equipmentProfiles]!) {
|
||||
EquipmentProfileProvider.of(context).setProfile(EquipmentProfiles.of(context).first);
|
||||
}
|
||||
if (!_features[MeteringScreenLayoutFeature.filmPicker]!) {
|
||||
FilmsProvider.of(context).setFilm(const Film.other());
|
||||
}
|
||||
UserPreferencesProvider.of(context).setMeteringScreenLayout(_features);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(S.of(context).save),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _featureListTile(MeteringScreenLayoutFeature f) {
|
||||
return SwitchListTile(
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: Dimens.dialogTitlePadding.left),
|
||||
title: Text(_toStringLocalized(context, f)),
|
||||
value: _features[f]!,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_features.update(f, (_) => value);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
String _toStringLocalized(BuildContext context, MeteringScreenLayoutFeature feature) {
|
||||
switch (feature) {
|
||||
case MeteringScreenLayoutFeature.equipmentProfiles:
|
||||
return S.of(context).meteringScreenLayoutHintEquipmentProfiles;
|
||||
case MeteringScreenLayoutFeature.extremeExposurePairs:
|
||||
return S.of(context).meteringScreenFeatureExtremeExposurePairs;
|
||||
case MeteringScreenLayoutFeature.filmPicker:
|
||||
return S.of(context).meteringScreenFeatureFilmPicker;
|
||||
case MeteringScreenLayoutFeature.histogram:
|
||||
return S.of(context).meteringScreenFeatureHistogram;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||
import 'package:lightmeter/generated/l10n.dart';
|
||||
|
||||
import 'package:lightmeter/screens/settings/components/metering/components/metering_screen_layout/components/meterins_screen_layout_features_dialog/widget_dialog_metering_screen_layout_features.dart';
|
||||
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:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||
|
||||
class MeteringScreenLayoutListTile extends StatelessWidget {
|
||||
const MeteringScreenLayoutListTile({super.key});
|
||||
|
@ -14,9 +18,37 @@ class MeteringScreenLayoutListTile extends StatelessWidget {
|
|||
onTap: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => const MeteringScreenLayoutFeaturesDialog(),
|
||||
builder: (_) => DialogSwitch<MeteringScreenLayoutFeature>(
|
||||
icon: Icons.layers_outlined,
|
||||
title: S.of(context).meteringScreenLayout,
|
||||
description: S.of(context).meteringScreenLayoutHint,
|
||||
values: UserPreferencesProvider.meteringScreenConfigOf(context),
|
||||
titleAdapter: _toStringLocalized,
|
||||
onSave: (value) {
|
||||
if (!value[MeteringScreenLayoutFeature.equipmentProfiles]!) {
|
||||
EquipmentProfileProvider.of(context).setProfile(EquipmentProfiles.of(context).first);
|
||||
}
|
||||
if (!value[MeteringScreenLayoutFeature.filmPicker]!) {
|
||||
FilmsProvider.of(context).setFilm(const Film.other());
|
||||
}
|
||||
UserPreferencesProvider.of(context).setMeteringScreenLayout(value);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
String _toStringLocalized(BuildContext context, MeteringScreenLayoutFeature feature) {
|
||||
switch (feature) {
|
||||
case MeteringScreenLayoutFeature.equipmentProfiles:
|
||||
return S.of(context).meteringScreenLayoutHintEquipmentProfiles;
|
||||
case MeteringScreenLayoutFeature.extremeExposurePairs:
|
||||
return S.of(context).meteringScreenFeatureExtremeExposurePairs;
|
||||
case MeteringScreenLayoutFeature.filmPicker:
|
||||
return S.of(context).meteringScreenFeatureFilmPicker;
|
||||
case MeteringScreenLayoutFeature.histogram:
|
||||
return S.of(context).meteringScreenFeatureHistogram;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/generated/l10n.dart';
|
||||
import 'package:lightmeter/res/dimens.dart';
|
||||
|
||||
class DialogSwitch<T> extends StatefulWidget {
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String description;
|
||||
final Map<T, bool> values;
|
||||
final String Function(BuildContext context, T value) titleAdapter;
|
||||
final ValueChanged<Map<T, bool>> onSave;
|
||||
|
||||
const DialogSwitch({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.values,
|
||||
required this.titleAdapter,
|
||||
required this.onSave,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<DialogSwitch<T>> createState() => _DialogSwitchState<T>();
|
||||
}
|
||||
|
||||
class _DialogSwitchState<T> extends State<DialogSwitch<T>> {
|
||||
late final Map<T, bool> _features = Map.from(widget.values);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: Icon(widget.icon),
|
||||
titlePadding: Dimens.dialogIconTitlePadding,
|
||||
title: Text(widget.title),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
content: SizedBox(
|
||||
width: double.maxFinite,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingL),
|
||||
child: Text(widget.description),
|
||||
),
|
||||
const SizedBox(height: Dimens.grid16),
|
||||
ListView(
|
||||
shrinkWrap: true,
|
||||
children: _features.entries
|
||||
.map(
|
||||
(entry) => SwitchListTile(
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: Dimens.dialogTitlePadding.left),
|
||||
title: Text(widget.titleAdapter(context, entry.key)),
|
||||
value: _features[entry.key]!,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_features.update(entry.key, (_) => value);
|
||||
});
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actionsPadding: Dimens.dialogActionsPadding,
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: Navigator.of(context).pop,
|
||||
child: Text(S.of(context).cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
widget.onSave(_features);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(S.of(context).save),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue