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

View file

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