-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
227 additions
and
5 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
lib/src/features/albums/presentation/albums_list/albums_list_filter_screen.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:vocadb_app/src/features/albums/presentation/albums_list/albums_list_params_state.dart'; | ||
import 'package:vocadb_app/src/features/albums/presentation/widgets/dropdown_album_sort.dart'; | ||
import 'package:vocadb_app/src/features/albums/presentation/widgets/dropdown_album_type.dart'; | ||
import 'package:vocadb_app/src/features/tags/presentation/tag_widgets/tag_input.dart'; | ||
|
||
class AlbumsFilterScreen extends StatelessWidget { | ||
const AlbumsFilterScreen( | ||
{super.key, this.onSortChanged, this.onAlbumTypesChanged}); | ||
|
||
final Function(String?)? onAlbumTypesChanged; | ||
|
||
final Function(String?)? onSortChanged; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Filter'), | ||
), | ||
body: Consumer( | ||
builder: (context, ref, child) { | ||
final state = ref.watch(albumsListParamsStateProvider); | ||
|
||
return ListView( | ||
children: [ | ||
DropdownAlbumType( | ||
value: state.discTypes ?? '', | ||
onChanged: (value) => | ||
onAlbumTypesChanged?.call(value) ?? | ||
ref | ||
.read(albumsListParamsStateProvider.notifier) | ||
.updateDiscTypes(value!), | ||
), | ||
DropdownAlbumSort( | ||
value: 'Name', | ||
onChanged: (value) => | ||
onAlbumTypesChanged?.call(value) ?? | ||
ref | ||
.read(albumsListParamsStateProvider.notifier) | ||
.updateSort(value!), | ||
), | ||
const Divider(), | ||
const TagInput(), | ||
], | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
lib/src/features/albums/presentation/albums_list/albums_list_params_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:vocadb_app/src/features/albums/domain/albums_list_params.dart'; | ||
import 'package:vocadb_app/src/features/settings/data/user_settings_repository.dart'; | ||
|
||
class AlbumsListParamsState extends StateNotifier<AlbumsListParams> { | ||
AlbumsListParamsState({String lang = 'Default'}) | ||
: super(AlbumsListParams(lang: lang)); | ||
void updateDiscTypes(String? value) => | ||
state = state.copyWith(discTypes: value); | ||
void updateQuery(String value) => state = state.copyWith(query: value); | ||
void updateSort(String value) => state = state.copyWith(sort: value); | ||
void clearQuery() => state = state.copyWith(query: null); | ||
} | ||
|
||
final albumsListParamsStateProvider = StateNotifierProvider.autoDispose< | ||
AlbumsListParamsState, AlbumsListParams>((ref) { | ||
final preferredLang = ref.watch(userSettingsRepositoryProvider | ||
.select((value) => value.currentPreferredLang)); | ||
return AlbumsListParamsState(lang: preferredLang); | ||
}); |
57 changes: 57 additions & 0 deletions
57
lib/src/features/albums/presentation/albums_list/albums_list_screen.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:vocadb_app/src/common_widgets/async_value_widget.dart'; | ||
import 'package:vocadb_app/src/common_widgets/search_appbar.dart'; | ||
import 'package:vocadb_app/src/features/albums/data/album_repository.dart'; | ||
import 'package:vocadb_app/src/features/albums/domain/album.dart'; | ||
import 'package:vocadb_app/src/features/albums/presentation/albums_list/album_list_view.dart'; | ||
import 'package:vocadb_app/src/features/albums/presentation/albums_list/albums_list_params_state.dart'; | ||
import 'package:vocadb_app/src/routing/app_route_context.dart'; | ||
|
||
class AlbumsListScreen extends ConsumerWidget { | ||
const AlbumsListScreen({super.key, this.onSelectAlbum}); | ||
|
||
static const filterKey = Key('icon-filter-key'); | ||
|
||
final Function(Album)? onSelectAlbum; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return Scaffold( | ||
appBar: SearchAppBar( | ||
titleText: 'Albums', | ||
actions: [ | ||
IconButton( | ||
key: filterKey, | ||
icon: const Icon(Icons.tune), | ||
onPressed: () => context.goAlbumsListFilterScreen(), | ||
), | ||
], | ||
onSubmitted: (value) { | ||
ref.read(albumsListParamsStateProvider.notifier).updateQuery(value); | ||
}, | ||
onCleared: () { | ||
ref.read(albumsListParamsStateProvider.notifier).clearQuery(); | ||
}, | ||
), | ||
body: Consumer(builder: ((context, ref, child) { | ||
final value = ref.watch(albumsListProvider); | ||
return AsyncValueWidget( | ||
value: value, | ||
data: (data) { | ||
return AlbumListView( | ||
albums: data, | ||
onSelect: (artist) => onSelectAlbum?.call(artist), | ||
); | ||
}); | ||
})), | ||
); | ||
} | ||
} | ||
|
||
// State | ||
final albumsListProvider = FutureProvider.autoDispose<List<Album>>((ref) { | ||
final params = ref.watch(albumsListParamsStateProvider); | ||
final albumRepository = ref.watch(albumRepositoryProvider); | ||
return albumRepository.fetchAlbums(params: params); | ||
}); |
48 changes: 48 additions & 0 deletions
48
lib/src/features/albums/presentation/widgets/dropdown_album_sort.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:vocadb_app/src/common_widgets/dropdown_tile.dart'; | ||
|
||
class DropdownAlbumSort extends StatelessWidget { | ||
const DropdownAlbumSort({super.key, required this.value, this.onChanged}); | ||
|
||
static const dropdownKey = Key('dropdown-album-sort-key'); | ||
|
||
final String value; | ||
|
||
final Function(String?)? onChanged; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return DropdownTile( | ||
dropdownButtonKey: dropdownKey, | ||
value: value, | ||
label: 'Sort', | ||
onChanged: onChanged, | ||
items: const [ | ||
DropdownMenuItem<String>( | ||
value: 'Name', | ||
child: Text('Name'), | ||
), | ||
DropdownMenuItem<String>( | ||
value: 'AdditionDate', | ||
child: Text('Addition date'), | ||
), | ||
DropdownMenuItem<String>( | ||
value: 'ReleaseDate', | ||
child: Text('Release date'), | ||
), | ||
DropdownMenuItem<String>( | ||
value: 'RatingAverage', | ||
child: Text('Rating average'), | ||
), | ||
DropdownMenuItem<String>( | ||
value: 'RatingTotal', | ||
child: Text('Total score'), | ||
), | ||
DropdownMenuItem<String>( | ||
value: 'CollectionCount', | ||
child: Text('Collection count'), | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters