Ensure isEditMode is false when calling done

This commit is contained in:
Ming Ming 2021-07-09 03:26:14 +08:00
parent a07fb0d9a4
commit 8eef2a2084
3 changed files with 54 additions and 51 deletions

View file

@ -104,9 +104,11 @@ class _AlbumViewerState extends State<AlbumViewer>
}
}
@override
validateEditMode() => _editFormKey?.currentState?.validate() == true;
@override
doneEditMode() {
if (_editFormKey?.currentState?.validate() == true) {
try {
// persist the changes
_editFormKey.currentState.save();
@ -127,7 +129,6 @@ class _AlbumViewerState extends State<AlbumViewer>
} else {
_log.fine("[doneEditMode] Album not modified");
}
return true;
} finally {
setState(() {
// reset edits
@ -137,8 +138,6 @@ class _AlbumViewerState extends State<AlbumViewer>
});
}
}
return false;
}
void _initAlbum() {
assert(widget.album.provider is AlbumStaticProvider);

View file

@ -168,10 +168,11 @@ mixin AlbumViewerMixin<T extends StatefulWidget>
color: Theme.of(context).colorScheme.primary,
tooltip: AppLocalizations.of(context).doneButtonTooltip,
onPressed: () {
if (doneEditMode()) {
if (validateEditMode()) {
setState(() {
_isEditMode = false;
});
doneEditMode();
}
},
),
@ -186,8 +187,12 @@ mixin AlbumViewerMixin<T extends StatefulWidget>
@mustCallSuper
void enterEditMode() {}
/// Validates the pending modifications
@protected
bool doneEditMode();
bool validateEditMode();
@protected
void doneEditMode();
/// Return a new album with the edits
@protected

View file

@ -90,9 +90,11 @@ class _DynamicAlbumViewerState extends State<DynamicAlbumViewer>
);
}
@override
validateEditMode() => _editFormKey?.currentState?.validate() == true;
@override
doneEditMode() {
if (_editFormKey?.currentState?.validate() == true) {
_editFormKey.currentState.save();
final newAlbum = makeEdited(_album);
if (newAlbum.copyWith(lastUpdated: _album.lastUpdated) != _album) {
@ -111,9 +113,6 @@ class _DynamicAlbumViewerState extends State<DynamicAlbumViewer>
} else {
_log.fine("[doneEditMode] Album not modified");
}
return true;
}
return false;
}
void _initAlbum() {