Fix edit label view not activating in album

This commit is contained in:
Ming Ming 2024-10-31 00:18:15 +08:00
parent 94d042dfa0
commit 3a1f6d64cf
4 changed files with 56 additions and 42 deletions

View file

@ -68,6 +68,7 @@ import 'package:to_string/to_string.dart';
part 'collection_browser.g.dart';
part 'collection_browser/app_bar.dart';
part 'collection_browser/bloc.dart';
part 'collection_browser/item_view.dart';
part 'collection_browser/state_event.dart';
part 'collection_browser/type.dart';
part 'collection_browser/view.dart';

View file

@ -497,22 +497,14 @@ class _Bloc extends Bloc<_Event, _State>
"[_transformItems] Unsupported file format: ${item.file.fdMime}");
}
} else if (item is CollectionLabelItem) {
if (state.isEditMode) {
transformed.add(_EditLabelListItem(
original: item,
id: item.id,
text: item.text,
onEditPressed: () {
// TODO
},
));
} else {
transformed.add(_LabelItem(
original: item,
id: item.id,
text: item.text,
));
}
transformed.add(_LabelItem(
original: item,
id: item.id,
text: item.text,
onEditPressed: () {
// TODO
},
));
}
}
return _TransformResult(

View file

@ -0,0 +1,32 @@
part of '../collection_browser.dart';
class _LabelView extends StatelessWidget {
const _LabelView({
required this.text,
});
@override
Widget build(BuildContext context) {
return PhotoListLabel(text: text);
}
final String text;
}
class _EditLabelView extends StatelessWidget {
const _EditLabelView({
required this.text,
required this.onEditPressed,
});
@override
Widget build(BuildContext context) {
return PhotoListLabelEdit(
text: text,
onEditPressed: onEditPressed,
);
}
final String text;
final VoidCallback? onEditPressed;
}

View file

@ -101,8 +101,12 @@ class _LabelItem extends _ActualItem {
required super.original,
required this.id,
required this.text,
required this.onEditPressed,
});
@override
bool get isDraggable => true;
@override
bool operator ==(Object other) =>
identical(this, other) || (other is _LabelItem && id == other.id);
@ -115,39 +119,24 @@ class _LabelItem extends _ActualItem {
@override
Widget buildWidget(BuildContext context) {
return PhotoListLabel(
text: text,
);
}
final Object id;
final String text;
}
class _EditLabelListItem extends _LabelItem {
const _EditLabelListItem({
required super.original,
required super.id,
required super.text,
required this.onEditPressed,
});
@override
bool get isDraggable => true;
@override
Widget buildWidget(BuildContext context) {
return PhotoListLabelEdit(
text: text,
onEditPressed: onEditPressed,
return _BlocSelector(
selector: (state) => state.isEditMode,
builder: (context, isEditMode) => isEditMode
? _EditLabelView(
text: text,
onEditPressed: onEditPressed,
)
: _LabelView(text: text),
);
}
@override
Widget? buildDragFeedbackWidget(BuildContext context) {
return super.buildWidget(context);
return _LabelView(text: text);
}
final Object id;
final String text;
final VoidCallback? onEditPressed;
}