Skip to content

Commit

Permalink
Add filter ranking songs logic
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed Dec 10, 2023
1 parent bd787b7 commit 669d070
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ app.*.map.json
/android/app/release

# Ignore test coverage data
coverage
coverage/lcov.info
16 changes: 16 additions & 0 deletions lib/src/features/home/domain/ranking_filter_params.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'ranking_filter_params.freezed.dart';
part 'ranking_filter_params.g.dart';

@freezed
class RankingFilterParams with _$RankingFilterParams {
@JsonSerializable(includeIfNull: false)
const factory RankingFilterParams({
@Default('CreateDate') String filterBy,
@Default('Nothing') String vocalist,
}) = _RankingFilterParams;

factory RankingFilterParams.fromJson(Map<String, dynamic> json) =>
_$RankingFilterParamsFromJson(json);
}
175 changes: 175 additions & 0 deletions lib/src/features/home/domain/ranking_filter_params.freezed.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target

part of 'ranking_filter_params.dart';

// **************************************************************************
// FreezedGenerator
// **************************************************************************

T _$identity<T>(T value) => value;

final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');

RankingFilterParams _$RankingFilterParamsFromJson(Map<String, dynamic> json) {
return _RankingFilterParams.fromJson(json);
}

/// @nodoc
mixin _$RankingFilterParams {
String get filterBy => throw _privateConstructorUsedError;
String get vocalist => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$RankingFilterParamsCopyWith<RankingFilterParams> get copyWith =>
throw _privateConstructorUsedError;
}

/// @nodoc
abstract class $RankingFilterParamsCopyWith<$Res> {
factory $RankingFilterParamsCopyWith(
RankingFilterParams value, $Res Function(RankingFilterParams) then) =
_$RankingFilterParamsCopyWithImpl<$Res, RankingFilterParams>;
@useResult
$Res call({String filterBy, String vocalist});
}

/// @nodoc
class _$RankingFilterParamsCopyWithImpl<$Res, $Val extends RankingFilterParams>
implements $RankingFilterParamsCopyWith<$Res> {
_$RankingFilterParamsCopyWithImpl(this._value, this._then);

// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;

@pragma('vm:prefer-inline')
@override
$Res call({
Object? filterBy = null,
Object? vocalist = null,
}) {
return _then(_value.copyWith(
filterBy: null == filterBy
? _value.filterBy
: filterBy // ignore: cast_nullable_to_non_nullable
as String,
vocalist: null == vocalist
? _value.vocalist
: vocalist // ignore: cast_nullable_to_non_nullable
as String,
) as $Val);
}
}

/// @nodoc
abstract class _$$_RankingFilterParamsCopyWith<$Res>
implements $RankingFilterParamsCopyWith<$Res> {
factory _$$_RankingFilterParamsCopyWith(_$_RankingFilterParams value,
$Res Function(_$_RankingFilterParams) then) =
__$$_RankingFilterParamsCopyWithImpl<$Res>;
@override
@useResult
$Res call({String filterBy, String vocalist});
}

/// @nodoc
class __$$_RankingFilterParamsCopyWithImpl<$Res>
extends _$RankingFilterParamsCopyWithImpl<$Res, _$_RankingFilterParams>
implements _$$_RankingFilterParamsCopyWith<$Res> {
__$$_RankingFilterParamsCopyWithImpl(_$_RankingFilterParams _value,
$Res Function(_$_RankingFilterParams) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
@override
$Res call({
Object? filterBy = null,
Object? vocalist = null,
}) {
return _then(_$_RankingFilterParams(
filterBy: null == filterBy
? _value.filterBy
: filterBy // ignore: cast_nullable_to_non_nullable
as String,
vocalist: null == vocalist
? _value.vocalist
: vocalist // ignore: cast_nullable_to_non_nullable
as String,
));
}
}

/// @nodoc
@JsonSerializable(includeIfNull: false)
class _$_RankingFilterParams implements _RankingFilterParams {
const _$_RankingFilterParams(
{this.filterBy = 'CreateDate', this.vocalist = 'Nothing'});

factory _$_RankingFilterParams.fromJson(Map<String, dynamic> json) =>
_$$_RankingFilterParamsFromJson(json);

@override
@JsonKey()
final String filterBy;
@override
@JsonKey()
final String vocalist;

@override
String toString() {
return 'RankingFilterParams(filterBy: $filterBy, vocalist: $vocalist)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_RankingFilterParams &&
(identical(other.filterBy, filterBy) ||
other.filterBy == filterBy) &&
(identical(other.vocalist, vocalist) ||
other.vocalist == vocalist));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, filterBy, vocalist);

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_RankingFilterParamsCopyWith<_$_RankingFilterParams> get copyWith =>
__$$_RankingFilterParamsCopyWithImpl<_$_RankingFilterParams>(
this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$_RankingFilterParamsToJson(
this,
);
}
}

abstract class _RankingFilterParams implements RankingFilterParams {
const factory _RankingFilterParams(
{final String filterBy, final String vocalist}) = _$_RankingFilterParams;

factory _RankingFilterParams.fromJson(Map<String, dynamic> json) =
_$_RankingFilterParams.fromJson;

@override
String get filterBy;
@override
String get vocalist;
@override
@JsonKey(ignore: true)
_$$_RankingFilterParamsCopyWith<_$_RankingFilterParams> get copyWith =>
throw _privateConstructorUsedError;
}
21 changes: 21 additions & 0 deletions lib/src/features/home/domain/ranking_filter_params.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:vocadb_app/src/common_widgets/simple_radio_group.dart';
import 'package:vocadb_app/src/features/home/presentation/ranking_screen/ranking_filter_params_state.dart';

class RankingFilterFilterByRadioGroup extends ConsumerWidget {
const RankingFilterFilterByRadioGroup({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final value = ref.watch(rankingFilterParamsStateProvider);

return SimpleRadioGroup(
title: Text('Filter by'),
groupValue: value.filterBy,
onChanged: (value) {
ref.read(rankingFilterParamsStateProvider.notifier).updateFilterBy(value!);
},
items: [
SimpleRadioItem(name: 'Newly added', value: 'CreateDate'),
SimpleRadioItem(name: 'Newly published', value: 'PublishDate'),
SimpleRadioItem(name: 'Popularity', value: 'Popularity')
],
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:vocadb_app/src/features/home/domain/ranking_filter_params.dart';

class RankingFilterParamsState extends StateNotifier<RankingFilterParams> {
RankingFilterParamsState()
: super(const RankingFilterParams());
void updateFilterBy(String value) =>
state = state.copyWith(filterBy: value);
void updateVocalist(String value) => state = state.copyWith(vocalist: value);
}

final rankingFilterParamsStateProvider = StateNotifierProvider.autoDispose<
RankingFilterParamsState, RankingFilterParams>((ref) {
return RankingFilterParamsState();
});
Original file line number Diff line number Diff line change
@@ -1,66 +1,18 @@
import 'package:flutter/material.dart';
import 'package:vocadb_app/src/features/home/presentation/ranking_screen/ranking_filter_filter_by_radio_group.dart';
import 'package:vocadb_app/src/features/home/presentation/ranking_screen/ranking_filter_vocalist_radio_group.dart';

// TODO : need implementation
class RankingFilterScreen extends StatelessWidget {
const RankingFilterScreen({super.key});

@override
Widget build(BuildContext context) {
const String selectedFilterByValue = 'CreateDate';
const String selectedVocalistValue = 'Nothing';

return Scaffold(
appBar: AppBar(),
body: ListView(
children: [
const ListTile(
title: Text('Filter by'),
),
RadioListTile<String>(
title: const Text('Newly added'),
value: 'CreateDate',
groupValue: selectedFilterByValue,
onChanged: (String? value) {},
),
RadioListTile<String>(
title: const Text('Newly published'),
value: 'PublishDate',
groupValue: selectedFilterByValue,
onChanged: (String? value) {},
),
RadioListTile<String>(
title: const Text('Popularity'),
value: 'Popularity',
groupValue: selectedFilterByValue,
onChanged: (String? value) {},
),
const ListTile(
title: Text('Vocalist'),
),
RadioListTile<String>(
title: const Text('All vocalists'),
value: 'Nothing',
groupValue: selectedVocalistValue,
onChanged: (String? value) {},
),
RadioListTile<String>(
title: const Text('Only Vocaloid'),
value: 'Vocaloid',
groupValue: selectedVocalistValue,
onChanged: (String? value) {},
),
RadioListTile<String>(
title: const Text('UTAU'),
value: 'UTAU',
groupValue: selectedVocalistValue,
onChanged: (String? value) {},
),
RadioListTile<String>(
title: const Text('Other vocalists'),
value: 'Other',
groupValue: selectedVocalistValue,
onChanged: (String? value) {},
),
children: const [
RankingFilterFilterByRadioGroup(),
RankingFilterVocalistRadioGroup(),
],
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:vocadb_app/src/common_widgets/simple_radio_group.dart';
import 'package:vocadb_app/src/features/home/presentation/ranking_screen/ranking_filter_params_state.dart';

class RankingFilterVocalistRadioGroup extends ConsumerWidget {
const RankingFilterVocalistRadioGroup({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final value = ref.watch(rankingFilterParamsStateProvider);

return SimpleRadioGroup(
title: Text('Vocalist'),
groupValue: value.vocalist,
onChanged: (value) {
ref.read(rankingFilterParamsStateProvider.notifier).updateVocalist(value!);
},
items: [
SimpleRadioItem(name: 'All vocalists', value: 'Nothing'),
SimpleRadioItem(name: 'Only Vocaloid', value: 'Vocaloid'),
SimpleRadioItem(name: 'UTAU', value: 'UTAU'),
SimpleRadioItem(name: 'Other', value: 'Other')
],
);
}
}
Loading

0 comments on commit 669d070

Please sign in to comment.