mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-10-19 14:50:40 +00:00
![Vadim](/assets/img/avatar_default.png)
* implemented `MockCameraContainerBloc` to stub camera on simulator * hide pro features from metering screen * disable pro features in settings * use closed child background color in `AnimatedDialog` * adjust `AnimatedDialogPicker` to items count * close `AnimatedDialog` through context * cleanup * fixed `ReadingValueContainer` text color * removed legacy translations * fixed tests * fixed `AnimatedDialog` scaling * added `evFromImage` test * added no EXIF test to `evFromImage`
102 lines
3.3 KiB
Dart
102 lines
3.3 KiB
Dart
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);
|
|
|
|
class DialogSwitch<T> extends StatefulWidget {
|
|
final IconData icon;
|
|
final String title;
|
|
final String? description;
|
|
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({
|
|
required this.icon,
|
|
required this.title,
|
|
this.description,
|
|
required this.values,
|
|
required this.titleAdapter,
|
|
this.subtitleAdapter,
|
|
this.enabledAdapter,
|
|
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: [
|
|
if (widget.description != null) ...[
|
|
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) {
|
|
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
|
|
? Text(
|
|
widget.subtitleAdapter!.call(context, entry.key),
|
|
style: Theme.of(context).listTileTheme.subtitleTextStyle,
|
|
)
|
|
: null,
|
|
value: isEnabled && _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),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|