fixed dialog picker of optional values

This commit is contained in:
Vadim 2025-07-21 22:48:22 +02:00
parent 6f8231f721
commit 8ef734825d
6 changed files with 25 additions and 18 deletions

View file

@ -51,7 +51,7 @@ class LogbookPhotoEditBloc extends Bloc<LogbookPhotoEditEvent, LogbookPhotoEditS
_newPhoto = _newPhoto.copyWith(apertureValue: Optional(event.aperture)); _newPhoto = _newPhoto.copyWith(apertureValue: Optional(event.aperture));
emit( emit(
state.copyWith( state.copyWith(
aperture: event.aperture, aperture: Optional(event.aperture),
canSave: _canSave(), canSave: _canSave(),
), ),
); );
@ -61,7 +61,7 @@ class LogbookPhotoEditBloc extends Bloc<LogbookPhotoEditEvent, LogbookPhotoEditS
_newPhoto = _newPhoto.copyWith(shutterSpeedValue: Optional(event.shutterSpeed)); _newPhoto = _newPhoto.copyWith(shutterSpeedValue: Optional(event.shutterSpeed));
emit( emit(
state.copyWith( state.copyWith(
shutterSpeed: event.shutterSpeed, shutterSpeed: Optional(event.shutterSpeed),
canSave: _canSave(), canSave: _canSave(),
), ),
); );

View file

@ -8,7 +8,7 @@ class PickerListTile<T extends PhotographyValue> extends StatelessWidget {
final String title; final String title;
final T? selectedValue; final T? selectedValue;
final List<T> values; final List<T> values;
final ValueChanged<T?> onChanged; final ValueChanged<Optional<T>> onChanged;
const PickerListTile({ const PickerListTile({
required this.icon, required this.icon,
@ -26,14 +26,17 @@ class PickerListTile<T extends PhotographyValue> extends StatelessWidget {
title: Text(title), title: Text(title),
trailing: Text(selectedValue?.toString() ?? S.of(context).notSet), trailing: Text(selectedValue?.toString() ?? S.of(context).notSet),
onTap: () { onTap: () {
showDialog<T?>( showDialog<Optional<T>>(
context: context, context: context,
builder: (_) => DialogPicker<T?>( builder: (_) => DialogPicker<Optional<T>>(
icon: icon, icon: icon,
title: title, title: title,
selectedValue: selectedValue, selectedValue: Optional(selectedValue),
values: [null, ...values], values: [
titleAdapter: (context, value) => value?.toString() ?? S.of(context).notSet, const Optional(null),
...values.toSet().map((e) => Optional(e)),
],
titleAdapter: (context, value) => value.value?.toString() ?? S.of(context).notSet,
), ),
).then((value) { ).then((value) {
if (value != null) { if (value != null) {

View file

@ -224,7 +224,7 @@ class _AperturePickerListTile extends StatelessWidget {
values: ApertureValue.values, values: ApertureValue.values,
selectedValue: state.aperture, selectedValue: state.aperture,
onChanged: (value) { onChanged: (value) {
context.read<LogbookPhotoEditBloc>().add(LogbookPhotoApertureChangedEvent(value)); context.read<LogbookPhotoEditBloc>().add(LogbookPhotoApertureChangedEvent(value.value));
}, },
), ),
); );
@ -244,7 +244,7 @@ class _ShutterSpeedPickerListTile extends StatelessWidget {
values: ShutterSpeedValue.values, values: ShutterSpeedValue.values,
selectedValue: state.shutterSpeed, selectedValue: state.shutterSpeed,
onChanged: (value) { onChanged: (value) {
context.read<LogbookPhotoEditBloc>().add(LogbookPhotoShutterSpeedChangedEvent(value)); context.read<LogbookPhotoEditBloc>().add(LogbookPhotoShutterSpeedChangedEvent(value.value));
}, },
), ),
); );

View file

@ -31,8 +31,8 @@ class LogbookPhotoEditState {
LogbookPhotoEditState copyWith({ LogbookPhotoEditState copyWith({
String? name, String? name,
ApertureValue? aperture, Optional<ApertureValue>? aperture,
ShutterSpeedValue? shutterSpeed, Optional<ShutterSpeedValue>? shutterSpeed,
String? note, String? note,
bool? canSave, bool? canSave,
bool? isLoading, bool? isLoading,
@ -44,8 +44,8 @@ class LogbookPhotoEditState {
ev: ev, ev: ev,
iso: iso, iso: iso,
nd: nd, nd: nd,
aperture: aperture ?? this.aperture, aperture: aperture != null ? aperture.value : this.aperture,
shutterSpeed: shutterSpeed ?? this.shutterSpeed, shutterSpeed: shutterSpeed != null ? shutterSpeed.value : this.shutterSpeed,
note: note ?? this.note, note: note ?? this.note,
canSave: canSave ?? this.canSave, canSave: canSave ?? this.canSave,
isLoading: isLoading ?? this.isLoading, isLoading: isLoading ?? this.isLoading,

View file

@ -894,11 +894,11 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
path: "." path: "."
ref: "v2.3.0" ref: "v2.3.1"
resolved-ref: a8c419f21fcda06d76d26cc2416de459f0d51a60 resolved-ref: "8b39ac1927b791652618509abe0391f844229b93"
url: "https://github.com/vodemn/m3_lightmeter_resources" url: "https://github.com/vodemn/m3_lightmeter_resources"
source: git source: git
version: "2.3.0+11" version: "2.3.1+12"
macros: macros:
dependency: transitive dependency: transitive
description: description:

View file

@ -37,7 +37,7 @@ dependencies:
m3_lightmeter_resources: m3_lightmeter_resources:
git: git:
url: "https://github.com/vodemn/m3_lightmeter_resources" url: "https://github.com/vodemn/m3_lightmeter_resources"
ref: v2.3.0 ref: v2.3.1
map_launcher: 3.2.0 map_launcher: 3.2.0
material_color_utilities: 0.12.0 material_color_utilities: 0.12.0
package_info_plus: 8.1.3 package_info_plus: 8.1.3
@ -68,6 +68,10 @@ dev_dependencies:
dependency_overrides: dependency_overrides:
geolocator_android: 4.6.1 geolocator_android: 4.6.1
m3_lightmeter_resources:
git:
url: "https://github.com/vodemn/m3_lightmeter_resources"
ref: v2.3.1
material_color_utilities: 0.11.1 material_color_utilities: 0.11.1
flutter: flutter: