spotube/lib/modules/stats/top/top.dart
Alessio fece073def This pull request primarily involves the removal of several configuration files and assets, as well as minor updates to documentation. The most significant changes are the deletion of various .vscode configuration files and the removal of unused assets from the project.
Configuration File Removals:

    .vscode/c_cpp_properties.json: Removed the entire configuration for C/C++ properties.
    .vscode/launch.json: Removed the Dart launch configurations for different environments and modes.
    .vscode/settings.json: Removed settings related to CMake, spell checking, file nesting, and Dart Flutter SDK path.
    .vscode/snippets.code-snippets: Removed code snippets for Dart, including PaginatedState and PaginatedNotifier templates.
    .vscode/tasks.json: Removed the tasks configuration file.

Documentation Updates:

    CONTRIBUTION.md: Removed heart emoji from the introductory text.
    README.md: Updated the logo image and made minor text adjustments, including removing emojis and updating section titles. [1] [2] [3] [4] [5]

Asset Removals:

    lib/collections/assets.gen.dart: Removed multiple unused asset references, including images related to Spotube logos and banners. [1] [2] [3]

Minor Code Cleanups:

    cli/commands/build/linux.dart, cli/commands/build/windows.dart, cli/commands/translated.dart, cli/commands/untranslated.dart: Adjusted import statements for consistency. [1] [2] [3] [4]
    integration_test/app_test.dart: Removed an unnecessary blank line.
    lib/collections/routes.dart: Commented out the TrackRoute configuration.
2025-04-13 18:40:37 +02:00

111 lines
3.8 KiB
Dart

import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart';
import 'package:shadcn_flutter/shadcn_flutter_extension.dart';
import 'package:spotube/extensions/constrains.dart';
import 'package:spotube/extensions/context.dart';
import 'package:spotube/modules/stats/top/albums.dart';
import 'package:spotube/modules/stats/top/artists.dart';
import 'package:spotube/modules/stats/top/tracks.dart';
import 'package:spotube/provider/history/top.dart';
class StatsPageTopSection extends HookConsumerWidget {
const StatsPageTopSection({super.key});
@override
Widget build(BuildContext context, ref) {
final selectedIndex = useState(0);
final historyDuration = ref.watch(playbackHistoryTopDurationProvider);
final historyDurationNotifier =
ref.watch(playbackHistoryTopDurationProvider.notifier);
final translations = <HistoryDuration, String>{
HistoryDuration.days7: context.l10n.this_week,
HistoryDuration.days30: context.l10n.this_month,
HistoryDuration.months6: context.l10n.last_6_months,
HistoryDuration.year: context.l10n.this_year,
HistoryDuration.years2: context.l10n.last_2_years,
HistoryDuration.allTime: context.l10n.all_time,
};
final dropdown = Select<HistoryDuration>(
popupConstraints: const BoxConstraints(maxWidth: 150),
popupWidthConstraint: PopoverConstraint.flexible,
padding: const EdgeInsets.all(4),
borderRadius: BorderRadius.circular(4),
value: historyDuration,
onChanged: (value) {
if (value == null) return;
historyDurationNotifier.update((_) => value);
},
itemBuilder: (context, item) => Text(translations[item]!),
popup: (context) {
return SelectPopup(
items: SelectItemBuilder(
childCount: HistoryDuration.values.length,
builder: (context, index) {
final item = HistoryDuration.values[index];
return SelectItemButton(
value: item,
child: Text(translations[item]!),
);
},
),
);
});
return SliverLayoutBuilder(builder: (context, constraints) {
return SliverMainAxisGroup(
slivers: [
SliverAppBar(
floating: true,
elevation: 0,
backgroundColor: context.theme.colorScheme.background,
automaticallyImplyLeading: false,
flexibleSpace: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
TabList(
index: selectedIndex.value,
onChanged: (value) {
selectedIndex.value = value;
},
children: [
TabItem(
child: Text(context.l10n.top_tracks),
),
TabItem(
child: Text(context.l10n.top_artists),
),
TabItem(
child: Text(context.l10n.top_albums),
),
],
),
if (constraints.mdAndUp) ...[
const Spacer(),
dropdown,
]
],
),
),
),
if (constraints.smAndDown)
SliverToBoxAdapter(
child: Align(
alignment: Alignment.centerRight,
child: dropdown,
),
),
switch (selectedIndex.value) {
1 => const TopArtists(),
2 => const TopAlbums(),
_ => const TopTracks(),
},
],
);
});
}
}