mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-26 09:20:45 +00:00
added features dialog subtitles
This commit is contained in:
parent
b0210d1e8c
commit
e029cea713
4 changed files with 39 additions and 15 deletions
|
@ -42,7 +42,9 @@
|
||||||
"meteringScreenFeatureHistogram": "Histogram",
|
"meteringScreenFeatureHistogram": "Histogram",
|
||||||
"cameraFeatures": "Camera features",
|
"cameraFeatures": "Camera features",
|
||||||
"cameraFeatureSpotMetering": "Spot metering",
|
"cameraFeatureSpotMetering": "Spot metering",
|
||||||
|
"cameraFeatureSpotMeteringHint": "Long press the camera view to remove metering spot",
|
||||||
"cameraFeatureHistogram": "Histogram",
|
"cameraFeatureHistogram": "Histogram",
|
||||||
|
"cameraFeatureHistogramHint": "Enabling histogram can encrease battery drain",
|
||||||
"film": "Film",
|
"film": "Film",
|
||||||
"filmPush": "Film (push)",
|
"filmPush": "Film (push)",
|
||||||
"filmPull": "Film (pull)",
|
"filmPull": "Film (pull)",
|
||||||
|
|
|
@ -23,7 +23,7 @@ const primaryColorsList = [
|
||||||
|
|
||||||
ThemeData themeFrom(Color primaryColor, Brightness brightness) {
|
ThemeData themeFrom(Color primaryColor, Brightness brightness) {
|
||||||
final scheme = _colorSchemeFromColor(primaryColor, brightness);
|
final scheme = _colorSchemeFromColor(primaryColor, brightness);
|
||||||
return ThemeData(
|
final theme = ThemeData(
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
brightness: scheme.brightness,
|
brightness: scheme.brightness,
|
||||||
primaryColor: primaryColor,
|
primaryColor: primaryColor,
|
||||||
|
@ -60,12 +60,18 @@ ThemeData themeFrom(Color primaryColor, Brightness brightness) {
|
||||||
),
|
),
|
||||||
scaffoldBackgroundColor: scheme.surface,
|
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) {
|
ColorScheme _colorSchemeFromColor(Color primaryColor, Brightness brightness) {
|
||||||
final scheme = brightness == Brightness.light
|
final scheme = brightness == Brightness.light ? Scheme.light(primaryColor.value) : Scheme.dark(primaryColor.value);
|
||||||
? Scheme.light(primaryColor.value)
|
|
||||||
: Scheme.dark(primaryColor.value);
|
|
||||||
|
|
||||||
return ColorScheme(
|
return ColorScheme(
|
||||||
brightness: brightness,
|
brightness: brightness,
|
||||||
|
|
|
@ -19,20 +19,26 @@ class CameraFeaturesListTile extends StatelessWidget {
|
||||||
icon: Icons.layers_outlined,
|
icon: Icons.layers_outlined,
|
||||||
title: S.of(context).cameraFeatures,
|
title: S.of(context).cameraFeatures,
|
||||||
values: UserPreferencesProvider.cameraConfigOf(context),
|
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,
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,15 @@ 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';
|
||||||
|
|
||||||
|
typedef StringAdapter<T> = String Function(BuildContext context, T value);
|
||||||
|
|
||||||
class DialogSwitch<T> extends StatefulWidget {
|
class DialogSwitch<T> extends StatefulWidget {
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
final String title;
|
final String title;
|
||||||
final String? description;
|
final String? description;
|
||||||
final Map<T, bool> values;
|
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;
|
final ValueChanged<Map<T, bool>> onSave;
|
||||||
|
|
||||||
const DialogSwitch({
|
const DialogSwitch({
|
||||||
|
@ -16,6 +19,7 @@ class DialogSwitch<T> extends StatefulWidget {
|
||||||
this.description,
|
this.description,
|
||||||
required this.values,
|
required this.values,
|
||||||
required this.titleAdapter,
|
required this.titleAdapter,
|
||||||
|
this.subtitleAdapter,
|
||||||
required this.onSave,
|
required this.onSave,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
@ -53,6 +57,12 @@ class _DialogSwitchState<T> extends State<DialogSwitch<T>> {
|
||||||
(entry) => SwitchListTile(
|
(entry) => 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
|
||||||
|
? Text(
|
||||||
|
widget.subtitleAdapter!.call(context, entry.key),
|
||||||
|
style: Theme.of(context).listTileTheme.subtitleTextStyle,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
value: _features[entry.key]!,
|
value: _features[entry.key]!,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
Loading…
Reference in a new issue