Fix NPE pressing edit before album initialized

This commit is contained in:
Ming Ming 2021-07-26 04:25:16 +08:00
parent 1c476be689
commit 7321c04dc1
3 changed files with 34 additions and 23 deletions

View file

@ -97,6 +97,9 @@ class _AlbumViewerState extends State<AlbumViewer>
);
}
@protected
get canEdit => _album != null;
@override
enterEditMode() {
super.enterEditMode();

View file

@ -56,31 +56,33 @@ mixin AlbumViewerMixin<T extends StatefulWidget>
},
),
...(actions ?? []),
PopupMenuButton<int>(
tooltip: MaterialLocalizations.of(context).moreButtonTooltip,
itemBuilder: (context) => [
PopupMenuItem(
value: -1,
child: Text(L10n.of(context).editAlbumMenuLabel),
),
...(menuItemBuilder?.call(context) ?? []),
],
onSelected: (option) {
if (option >= 0) {
onSelectedMenuItem?.call(option);
} else {
switch (option) {
case _menuValueEdit:
_onAppBarEditPressed(context, album);
break;
if (menuItemBuilder != null || canEdit)
PopupMenuButton<int>(
tooltip: MaterialLocalizations.of(context).moreButtonTooltip,
itemBuilder: (context) => [
if (canEdit)
PopupMenuItem(
value: -1,
child: Text(L10n.of(context).editAlbumMenuLabel),
),
...(menuItemBuilder?.call(context) ?? []),
],
onSelected: (option) {
if (option >= 0) {
onSelectedMenuItem?.call(option);
} else {
switch (option) {
case _menuValueEdit:
_onAppBarEditPressed(context, album);
break;
default:
_log.shout("[buildNormalAppBar] Unknown value: $option");
break;
default:
_log.shout("[buildNormalAppBar] Unknown value: $option");
break;
}
}
}
},
),
},
),
],
);
}
@ -127,6 +129,9 @@ mixin AlbumViewerMixin<T extends StatefulWidget>
@protected
bool get isEditMode => _isEditMode;
@protected
bool get canEdit => true;
@protected
@mustCallSuper
void enterEditMode() {}

View file

@ -98,6 +98,9 @@ class _DynamicAlbumViewerState extends State<DynamicAlbumViewer>
);
}
@protected
get canEdit => _album != null;
@override
enterEditMode() {
super.enterEditMode();