mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2025-09-18 14:16:40 +00:00
input custom aperture value
This commit is contained in:
parent
f260d8d5ca
commit
59be88f0e6
6 changed files with 132 additions and 18 deletions
|
@ -23,7 +23,8 @@ sealed class IEquipmentProfileEditBloc<T extends IEquipmentProfile>
|
||||||
super(
|
super(
|
||||||
EquipmentProfileEditState<T>(
|
EquipmentProfileEditState<T>(
|
||||||
profile: profile,
|
profile: profile,
|
||||||
canSave: false,
|
hasChanges: false,
|
||||||
|
isValid: true,
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
on<IEquipmentProfileEditEvent<T>>(mapEventToState);
|
on<IEquipmentProfileEditEvent<T>>(mapEventToState);
|
||||||
|
@ -51,7 +52,8 @@ sealed class IEquipmentProfileEditBloc<T extends IEquipmentProfile>
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(
|
state.copyWith(
|
||||||
profile: profile,
|
profile: profile,
|
||||||
canSave: _canSave(profile),
|
hasChanges: _hasChanges(profile),
|
||||||
|
isValid: _isValid(profile),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -76,7 +78,9 @@ sealed class IEquipmentProfileEditBloc<T extends IEquipmentProfile>
|
||||||
emit(state.copyWith(isLoading: false));
|
emit(state.copyWith(isLoading: false));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _canSave(T profile) => profile != originalEquipmentProfile;
|
bool _hasChanges(T profile) => profile != originalEquipmentProfile;
|
||||||
|
|
||||||
|
bool _isValid(T profile) => profile.name.isNotEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
class EquipmentProfileEditBloc extends IEquipmentProfileEditBloc<EquipmentProfile> {
|
class EquipmentProfileEditBloc extends IEquipmentProfileEditBloc<EquipmentProfile> {
|
||||||
|
@ -163,7 +167,7 @@ class PinholeEquipmentProfileEditBloc extends IEquipmentProfileEditBloc<PinholeE
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case final EquipmentProfileNameChangedEvent e:
|
case final EquipmentProfileNameChangedEvent e:
|
||||||
await _onNameChanged(e, emit);
|
await _onNameChanged(e, emit);
|
||||||
case final EquipmentProfileApertureValuesChangedEvent e:
|
case final EquipmentProfileApertureValueChangedEvent e:
|
||||||
await _onApertureValuesChanged(e, emit);
|
await _onApertureValuesChanged(e, emit);
|
||||||
case final EquipmentProfileIsoValuesChangedEvent e:
|
case final EquipmentProfileIsoValuesChangedEvent e:
|
||||||
await _onIsoValuesChanged(e, emit);
|
await _onIsoValuesChanged(e, emit);
|
||||||
|
@ -195,9 +199,19 @@ class PinholeEquipmentProfileEditBloc extends IEquipmentProfileEditBloc<PinholeE
|
||||||
emitProfile(state.profile.copyWith(name: event.name), emit);
|
emitProfile(state.profile.copyWith(name: event.name), emit);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onApertureValuesChanged(EquipmentProfileApertureValuesChangedEvent event, Emitter emit) async {
|
Future<void> _onApertureValuesChanged(EquipmentProfileApertureValueChangedEvent event, Emitter emit) async {
|
||||||
//emitProfile(state.profile.copyWith(apertureValues: event.apertureValues), emit);
|
emitProfile(state.profile.copyWith(aperture: event.aperture ?? 0), emit);
|
||||||
|
|
||||||
|
final profile = state.profile.copyWith(aperture: event.aperture);
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
profile: profile,
|
||||||
|
hasChanges: _hasChanges(profile),
|
||||||
|
isValid: _isValid(profile) && event.aperture != null,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onIsoValuesChanged(EquipmentProfileIsoValuesChangedEvent event, Emitter emit) async {
|
Future<void> _onIsoValuesChanged(EquipmentProfileIsoValuesChangedEvent event, Emitter emit) async {
|
||||||
emitProfile(state.profile.copyWith(isoValues: event.isoValues), emit);
|
emitProfile(state.profile.copyWith(isoValues: event.isoValues), emit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
|
import 'package:lightmeter/screens/shared/text_field/widget_text_field.dart';
|
||||||
|
|
||||||
|
class EquipmentProfileApertureInput extends StatefulWidget {
|
||||||
|
final double? value;
|
||||||
|
final ValueChanged<double?> onChanged;
|
||||||
|
|
||||||
|
const EquipmentProfileApertureInput({
|
||||||
|
super.key,
|
||||||
|
required this.value,
|
||||||
|
required this.onChanged,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<EquipmentProfileApertureInput> createState() => _EquipmentProfileApertureInputState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EquipmentProfileApertureInputState extends State<EquipmentProfileApertureInput> {
|
||||||
|
TextStyle get style =>
|
||||||
|
Theme.of(context).textTheme.bodyMedium!.copyWith(color: Theme.of(context).listTileTheme.textColor);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ListTile(
|
||||||
|
leading: const Icon(Icons.camera),
|
||||||
|
title: Text(
|
||||||
|
S.of(context).apertureValue,
|
||||||
|
style: Theme.of(context).listTileTheme.titleTextStyle,
|
||||||
|
),
|
||||||
|
trailing: SizedBox(
|
||||||
|
width: _textInputWidth(context),
|
||||||
|
child: LightmeterTextField(
|
||||||
|
initialValue: widget.value?.toString() ?? '',
|
||||||
|
inputFormatters: [
|
||||||
|
FilteringTextInputFormatter.allow(RegExp("[0-9.]")),
|
||||||
|
LengthLimitingTextInputFormatter(6),
|
||||||
|
],
|
||||||
|
onChanged: (value) {
|
||||||
|
final parsed = double.tryParse(value);
|
||||||
|
widget.onChanged(parsed != null && parsed > 0 ? parsed : null);
|
||||||
|
},
|
||||||
|
validator: (value) {
|
||||||
|
final parsed = double.tryParse(value);
|
||||||
|
if (parsed != null && parsed > 0) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
textAlign: TextAlign.end,
|
||||||
|
style: style,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
double _textInputWidth(BuildContext context) {
|
||||||
|
final textPainter = TextPainter(
|
||||||
|
text: TextSpan(text: widget.value.toString(), style: style),
|
||||||
|
maxLines: 1,
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
)..layout();
|
||||||
|
return textPainter.maxIntrinsicWidth + Dimens.grid4;
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,12 @@ class EquipmentProfileApertureValuesChangedEvent extends IEquipmentProfileEditEv
|
||||||
const EquipmentProfileApertureValuesChangedEvent(this.apertureValues);
|
const EquipmentProfileApertureValuesChangedEvent(this.apertureValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class EquipmentProfileApertureValueChangedEvent extends IEquipmentProfileEditEvent<PinholeEquipmentProfile> {
|
||||||
|
final double? aperture;
|
||||||
|
|
||||||
|
const EquipmentProfileApertureValueChangedEvent(this.aperture);
|
||||||
|
}
|
||||||
|
|
||||||
class EquipmentProfileShutterSpeedValuesChangedEvent extends IEquipmentProfileEditEvent<EquipmentProfile> {
|
class EquipmentProfileShutterSpeedValuesChangedEvent extends IEquipmentProfileEditEvent<EquipmentProfile> {
|
||||||
final List<ShutterSpeedValue> shutterSpeedValues;
|
final List<ShutterSpeedValue> shutterSpeedValues;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/navigation/routes.dart';
|
import 'package:lightmeter/navigation/routes.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:lightmeter/screens/equipment_profile_edit/bloc_equipment_profile_edit.dart';
|
import 'package:lightmeter/screens/equipment_profile_edit/bloc_equipment_profile_edit.dart';
|
||||||
|
import 'package:lightmeter/screens/equipment_profile_edit/components/aperture_input/widget_input_aperture_equipment_profile.dart';
|
||||||
import 'package:lightmeter/screens/equipment_profile_edit/components/filter_list_tile/widget_list_tile_filter.dart';
|
import 'package:lightmeter/screens/equipment_profile_edit/components/filter_list_tile/widget_list_tile_filter.dart';
|
||||||
import 'package:lightmeter/screens/equipment_profile_edit/components/range_picker_list_tile/widget_list_tile_range_picker.dart';
|
import 'package:lightmeter/screens/equipment_profile_edit/components/range_picker_list_tile/widget_list_tile_range_picker.dart';
|
||||||
import 'package:lightmeter/screens/equipment_profile_edit/components/slider_picker_list_tile/widget_list_tile_slider_picker.dart';
|
import 'package:lightmeter/screens/equipment_profile_edit/components/slider_picker_list_tile/widget_list_tile_slider_picker.dart';
|
||||||
|
@ -58,9 +59,10 @@ class _EquipmentProfileEditScreenState<T extends IEquipmentProfile> extends Stat
|
||||||
title: Text(widget.isEdit ? S.of(context).editEquipmentProfileTitle : S.of(context).addEquipmentProfileTitle),
|
title: Text(widget.isEdit ? S.of(context).editEquipmentProfileTitle : S.of(context).addEquipmentProfileTitle),
|
||||||
appBarActions: [
|
appBarActions: [
|
||||||
BlocBuilder<IEquipmentProfileEditBloc<T>, EquipmentProfileEditState<T>>(
|
BlocBuilder<IEquipmentProfileEditBloc<T>, EquipmentProfileEditState<T>>(
|
||||||
buildWhen: (previous, current) => previous.canSave != current.canSave,
|
buildWhen: (previous, current) =>
|
||||||
|
previous.hasChanges != current.hasChanges || previous.isValid != current.isValid,
|
||||||
builder: (context, state) => IconButton(
|
builder: (context, state) => IconButton(
|
||||||
onPressed: state.canSave
|
onPressed: state.hasChanges && state.isValid
|
||||||
? () {
|
? () {
|
||||||
context.read<IEquipmentProfileEditBloc<T>>().add(const EquipmentProfileSaveEvent());
|
context.read<IEquipmentProfileEditBloc<T>>().add(const EquipmentProfileSaveEvent());
|
||||||
}
|
}
|
||||||
|
@ -70,13 +72,13 @@ class _EquipmentProfileEditScreenState<T extends IEquipmentProfile> extends Stat
|
||||||
),
|
),
|
||||||
if (widget.isEdit)
|
if (widget.isEdit)
|
||||||
BlocBuilder<IEquipmentProfileEditBloc<T>, EquipmentProfileEditState<T>>(
|
BlocBuilder<IEquipmentProfileEditBloc<T>, EquipmentProfileEditState<T>>(
|
||||||
buildWhen: (previous, current) => previous.canSave != current.canSave,
|
buildWhen: (previous, current) => previous.isValid != current.isValid,
|
||||||
builder: (context, state) => IconButton(
|
builder: (context, state) => IconButton(
|
||||||
onPressed: state.canSave
|
onPressed: state.isValid
|
||||||
? null
|
? () {
|
||||||
: () {
|
|
||||||
context.read<IEquipmentProfileEditBloc<T>>().add(const EquipmentProfileCopyEvent());
|
context.read<IEquipmentProfileEditBloc<T>>().add(const EquipmentProfileCopyEvent());
|
||||||
},
|
}
|
||||||
|
: null,
|
||||||
icon: const Icon(Icons.copy_outlined),
|
icon: const Icon(Icons.copy_outlined),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -106,7 +108,7 @@ class _EquipmentProfileEditScreenState<T extends IEquipmentProfile> extends Stat
|
||||||
children: [
|
children: [
|
||||||
_NameFieldBuilder<T>(),
|
_NameFieldBuilder<T>(),
|
||||||
if (state.profile is PinholeEquipmentProfile)
|
if (state.profile is PinholeEquipmentProfile)
|
||||||
const SizedBox.shrink()
|
const _ApertureValueListTileBuilder()
|
||||||
else ...[
|
else ...[
|
||||||
const _ApertureValuesListTileBuilder(),
|
const _ApertureValuesListTileBuilder(),
|
||||||
const _ShutterSpeedValuesListTileBuilder(),
|
const _ShutterSpeedValuesListTileBuilder(),
|
||||||
|
@ -220,6 +222,22 @@ class _ApertureValuesListTileBuilder extends StatelessWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _ApertureValueListTileBuilder extends StatelessWidget {
|
||||||
|
const _ApertureValueListTileBuilder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocBuilder<PinholeEquipmentProfileEditBloc, EquipmentProfileEditState<PinholeEquipmentProfile>>(
|
||||||
|
builder: (context, state) => EquipmentProfileApertureInput(
|
||||||
|
value: state.profile.aperture,
|
||||||
|
onChanged: (value) {
|
||||||
|
context.read<PinholeEquipmentProfileEditBloc>().add(EquipmentProfileApertureValueChangedEvent(value));
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class _ShutterSpeedValuesListTileBuilder extends StatelessWidget {
|
class _ShutterSpeedValuesListTileBuilder extends StatelessWidget {
|
||||||
const _ShutterSpeedValuesListTileBuilder();
|
const _ShutterSpeedValuesListTileBuilder();
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,14 @@ import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
class EquipmentProfileEditState<T extends IEquipmentProfile> {
|
class EquipmentProfileEditState<T extends IEquipmentProfile> {
|
||||||
final T profile;
|
final T profile;
|
||||||
final T? profileToCopy;
|
final T? profileToCopy;
|
||||||
final bool canSave;
|
final bool hasChanges;
|
||||||
|
final bool isValid;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
|
|
||||||
const EquipmentProfileEditState({
|
const EquipmentProfileEditState({
|
||||||
required this.profile,
|
required this.profile,
|
||||||
required this.canSave,
|
required this.hasChanges,
|
||||||
|
required this.isValid,
|
||||||
this.isLoading = false,
|
this.isLoading = false,
|
||||||
this.profileToCopy,
|
this.profileToCopy,
|
||||||
});
|
});
|
||||||
|
@ -16,13 +18,15 @@ class EquipmentProfileEditState<T extends IEquipmentProfile> {
|
||||||
EquipmentProfileEditState<T> copyWith({
|
EquipmentProfileEditState<T> copyWith({
|
||||||
T? profile,
|
T? profile,
|
||||||
T? profileToCopy,
|
T? profileToCopy,
|
||||||
bool? canSave,
|
bool? isValid,
|
||||||
|
bool? hasChanges,
|
||||||
bool? isLoading,
|
bool? isLoading,
|
||||||
}) =>
|
}) =>
|
||||||
EquipmentProfileEditState<T>(
|
EquipmentProfileEditState<T>(
|
||||||
profile: profile ?? this.profile,
|
profile: profile ?? this.profile,
|
||||||
profileToCopy: profileToCopy ?? this.profileToCopy,
|
profileToCopy: profileToCopy ?? this.profileToCopy,
|
||||||
canSave: canSave ?? this.canSave,
|
isValid: isValid ?? this.isValid,
|
||||||
|
hasChanges: hasChanges ?? this.hasChanges,
|
||||||
isLoading: isLoading ?? this.isLoading,
|
isLoading: isLoading ?? this.isLoading,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ class LightmeterTextField extends StatefulWidget {
|
||||||
this.hintText,
|
this.hintText,
|
||||||
this.initialValue,
|
this.initialValue,
|
||||||
this.inputFormatters,
|
this.inputFormatters,
|
||||||
|
this.validator,
|
||||||
this.leading,
|
this.leading,
|
||||||
this.maxLength,
|
this.maxLength,
|
||||||
this.maxLines = 1,
|
this.maxLines = 1,
|
||||||
|
@ -21,6 +22,7 @@ class LightmeterTextField extends StatefulWidget {
|
||||||
final String? hintText;
|
final String? hintText;
|
||||||
final String? initialValue;
|
final String? initialValue;
|
||||||
final List<TextInputFormatter>? inputFormatters;
|
final List<TextInputFormatter>? inputFormatters;
|
||||||
|
final String? Function(String)? validator;
|
||||||
final Widget? leading;
|
final Widget? leading;
|
||||||
final int? maxLength;
|
final int? maxLength;
|
||||||
final int? maxLines;
|
final int? maxLines;
|
||||||
|
@ -62,6 +64,8 @@ class _LightmeterTextFieldState extends State<LightmeterTextField> {
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
return '';
|
return '';
|
||||||
|
} else if (widget.validator != null) {
|
||||||
|
return widget.validator!(value);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue