spotube/lib/components/shared/sort_tracks_dropdown.dart

96 lines
2.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:spotube/collections/spotube_icons.dart';
import 'package:spotube/components/library/user_local_tracks.dart';
import 'package:spotube/components/shared/adaptive/adaptive_pop_sheet_list.dart';
import 'package:spotube/extensions/context.dart';
class SortTracksDropdown extends StatelessWidget {
final SortBy? value;
final void Function(SortBy)? onChanged;
const SortTracksDropdown({
this.onChanged,
this.value,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return ListTileTheme(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
child: AdaptivePopSheetList<SortBy>(
children: [
PopSheetEntry(
value: SortBy.none,
enabled: value != SortBy.none,
child: ListTile(
enabled: value != SortBy.none,
title: Text(context.l10n.none),
),
),
PopSheetEntry(
value: SortBy.ascending,
enabled: value != SortBy.ascending,
child: ListTile(
enabled: value != SortBy.ascending,
title: Text(context.l10n.sort_a_z),
),
),
PopSheetEntry(
value: SortBy.descending,
enabled: value != SortBy.descending,
child: ListTile(
enabled: value != SortBy.descending,
title: Text(context.l10n.sort_z_a),
),
),
PopSheetEntry(
value: SortBy.dateAdded,
enabled: value != SortBy.dateAdded,
child: ListTile(
enabled: value != SortBy.dateAdded,
title: Text(context.l10n.sort_date),
),
),
PopSheetEntry(
value: SortBy.artist,
enabled: value != SortBy.artist,
child: ListTile(
enabled: value != SortBy.artist,
title: Text(context.l10n.sort_artist),
),
),
PopSheetEntry(
value: SortBy.album,
enabled: value != SortBy.album,
child: ListTile(
enabled: value != SortBy.album,
title: Text(context.l10n.sort_album),
),
),
],
headings: [
Text(context.l10n.sort_tracks),
],
onSelected: onChanged,
tooltip: context.l10n.sort_tracks,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
child: DefaultTextStyle(
style: Theme.of(context).textTheme.titleSmall!,
child: Row(
children: [
const Icon(SpotubeIcons.sort),
const SizedBox(width: 8),
Text(context.l10n.sort_tracks),
],
),
),
),
),
);
}
}