added features dialog subtitles

This commit is contained in:
Vadim 2023-11-08 13:14:37 +01:00
parent b0210d1e8c
commit e029cea713
4 changed files with 39 additions and 15 deletions

View file

@ -42,7 +42,9 @@
"meteringScreenFeatureHistogram": "Histogram",
"cameraFeatures": "Camera features",
"cameraFeatureSpotMetering": "Spot metering",
"cameraFeatureSpotMeteringHint": "Long press the camera view to remove metering spot",
"cameraFeatureHistogram": "Histogram",
"cameraFeatureHistogramHint": "Enabling histogram can encrease battery drain",
"film": "Film",
"filmPush": "Film (push)",
"filmPull": "Film (pull)",

View file

@ -23,7 +23,7 @@ const primaryColorsList = [
ThemeData themeFrom(Color primaryColor, Brightness brightness) {
final scheme = _colorSchemeFromColor(primaryColor, brightness);
return ThemeData(
final theme = ThemeData(
useMaterial3: true,
brightness: scheme.brightness,
primaryColor: primaryColor,
@ -60,12 +60,18 @@ ThemeData themeFrom(Color primaryColor, Brightness brightness) {
),
scaffoldBackgroundColor: scheme.surface,
);
return theme.copyWith(
listTileTheme: ListTileThemeData(
style: ListTileStyle.list,
iconColor: scheme.onSurface,
textColor: scheme.onSurface,
subtitleTextStyle: theme.textTheme.bodyMedium!.copyWith(color: scheme.onSurfaceVariant),
),
);
}
ColorScheme _colorSchemeFromColor(Color primaryColor, Brightness brightness) {
final scheme = brightness == Brightness.light
? Scheme.light(primaryColor.value)
: Scheme.dark(primaryColor.value);
final scheme = brightness == Brightness.light ? Scheme.light(primaryColor.value) : Scheme.dark(primaryColor.value);
return ColorScheme(
brightness: brightness,

View file

@ -19,20 +19,26 @@ class CameraFeaturesListTile extends StatelessWidget {
icon: Icons.layers_outlined,
title: S.of(context).cameraFeatures,
values: UserPreferencesProvider.cameraConfigOf(context),
titleAdapter: _toStringLocalized,
titleAdapter: (context, feature) {
switch (feature) {
case CameraFeature.spotMetering:
return S.of(context).cameraFeatureSpotMetering;
case CameraFeature.histogram:
return S.of(context).cameraFeatureHistogram;
}
},
subtitleAdapter: (context, feature) {
switch (feature) {
case CameraFeature.spotMetering:
return S.of(context).cameraFeatureSpotMeteringHint;
case CameraFeature.histogram:
return S.of(context).cameraFeatureHistogramHint;
}
},
onSave: UserPreferencesProvider.of(context).setCameraFeature,
),
);
},
);
}
String _toStringLocalized(BuildContext context, CameraFeature feature) {
switch (feature) {
case CameraFeature.spotMetering:
return S.of(context).cameraFeatureSpotMetering;
case CameraFeature.histogram:
return S.of(context).cameraFeatureHistogram;
}
}
}

View file

@ -2,12 +2,15 @@ import 'package:flutter/material.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/res/dimens.dart';
typedef StringAdapter<T> = String Function(BuildContext context, T value);
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 StringAdapter<T> titleAdapter;
final StringAdapter<T>? subtitleAdapter;
final ValueChanged<Map<T, bool>> onSave;
const DialogSwitch({
@ -16,6 +19,7 @@ class DialogSwitch<T> extends StatefulWidget {
this.description,
required this.values,
required this.titleAdapter,
this.subtitleAdapter,
required this.onSave,
super.key,
});
@ -53,6 +57,12 @@ class _DialogSwitchState<T> extends State<DialogSwitch<T>> {
(entry) => SwitchListTile(
contentPadding: EdgeInsets.symmetric(horizontal: Dimens.dialogTitlePadding.left),
title: Text(widget.titleAdapter(context, entry.key)),
subtitle: widget.subtitleAdapter != null
? Text(
widget.subtitleAdapter!.call(context, entry.key),
style: Theme.of(context).listTileTheme.subtitleTextStyle,
)
: null,
value: _features[entry.key]!,
onChanged: (value) {
setState(() {