Refactoring: improve code

This commit is contained in:
Ming Ming 2022-01-28 05:05:02 +08:00
parent d8f157838f
commit d418364fee
2 changed files with 12 additions and 7 deletions

View file

@ -24,6 +24,7 @@ class AlbumGridItemBuilder {
AlbumGridItem build(BuildContext context) {
var subtitle = "";
String? subtitle2;
IconData? icon;
if (album.provider is AlbumStaticProvider) {
subtitle =
L10n.global().albumSize(AlbumStaticProvider.of(album).items.length);
@ -33,6 +34,7 @@ class AlbumGridItemBuilder {
if (provider.dirs.length > 1) {
subtitle2 = "+${provider.dirs.length - 1}";
}
icon = Icons.folder;
}
if (isShared) {
subtitle = "${L10n.global().albumSharedLabel} | $subtitle";
@ -42,7 +44,7 @@ class AlbumGridItemBuilder {
title: album.name,
subtitle: subtitle,
subtitle2: subtitle2,
icon: album.provider is AlbumDirProvider ? Icons.folder : null,
icon: icon,
);
}

View file

@ -70,7 +70,7 @@ class _NewAlbumDialogState extends State<NewAlbumDialog> {
DropdownButtonHideUnderline(
child: DropdownButtonFormField<_Provider>(
value: _provider,
items: [_Provider.static, _Provider.dir]
items: _Provider.values
.map((e) => DropdownMenuItem<_Provider>(
value: e,
child: Text(e.toValueString(context)),
@ -109,11 +109,14 @@ class _NewAlbumDialogState extends State<NewAlbumDialog> {
void _onOkPressed(BuildContext context) {
if (_formKey.currentState?.validate() == true) {
_formKey.currentState!.save();
if (_formValue.provider == _Provider.static ||
_formValue.provider == null) {
switch (_formValue.provider) {
case _Provider.static:
case null:
_onConfirmStaticAlbum();
} else {
break;
case _Provider.dir:
_onConfirmDirAlbum();
break;
}
}
}