Skip to content

Commit a6d4ed8

Browse files
committed
refactor: improve sort button code
1 parent d29728c commit a6d4ed8

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

lib/screens/playlist_page.dart

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,15 @@ class _PlaylistPageState extends State<PlaylistPage> {
214214
if (_playlist['list'].isNotEmpty) ...[
215215
SliverToBoxAdapter(
216216
child: Padding(
217-
padding: const EdgeInsets.symmetric(
218-
vertical: 10,
219-
horizontal: 20,
217+
padding: const EdgeInsets.only(
218+
top: 15,
219+
bottom: 20,
220+
right: 20,
221+
),
222+
child: Align(
223+
alignment: Alignment.centerRight,
224+
child: _buildSortSongActionButton(),
220225
),
221-
child: buildSongActionsRow(),
222226
),
223227
),
224228
SliverPadding(
@@ -616,13 +620,6 @@ class _PlaylistPageState extends State<PlaylistPage> {
616620
_pagingController.refresh();
617621
}
618622

619-
Widget buildSongActionsRow() {
620-
return Row(
621-
mainAxisAlignment: MainAxisAlignment.end,
622-
children: [_buildSortSongActionButton()],
623-
);
624-
}
625-
626623
Widget _buildSongListItem(dynamic song, int index, bool isRemovable) {
627624
final items = _pagingController.items ?? [];
628625
final totalItems = items.length;

lib/widgets/sort_button.dart

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
2323
import 'package:flutter/material.dart';
24+
import 'package:musify/utilities/common_variables.dart';
2425

2526
typedef SortTypeToStringConverter<T> = String Function(T type);
2627
typedef OnSortTypeSelected<T> = void Function(T type);
@@ -42,29 +43,33 @@ class SortButton<T extends Enum> extends StatelessWidget {
4243
@override
4344
Widget build(BuildContext context) {
4445
return PopupMenuButton<T>(
45-
padding: EdgeInsets.zero,
46-
elevation: 2,
46+
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
47+
elevation: 1,
4748
offset: const Offset(0, 40),
48-
child: Row(
49-
mainAxisSize: MainAxisSize.min,
50-
children: [
51-
Icon(
52-
FluentIcons.filter_16_filled,
53-
color: Theme.of(context).colorScheme.primary,
54-
size: 20,
55-
),
56-
const SizedBox(width: 8),
57-
Text(
58-
sortTypeToString(currentSortType),
59-
style: TextStyle(
60-
color: Theme.of(context).colorScheme.onSurface,
61-
fontSize: 15,
62-
fontWeight: FontWeight.w600,
63-
letterSpacing: 0.15,
64-
height: 1.2,
49+
borderRadius: commonBarRadius,
50+
child: Padding(
51+
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
52+
child: Row(
53+
mainAxisSize: MainAxisSize.min,
54+
children: [
55+
Icon(
56+
FluentIcons.filter_16_filled,
57+
color: Theme.of(context).colorScheme.primary,
58+
size: 20,
6559
),
66-
),
67-
],
60+
const SizedBox(width: 8),
61+
Text(
62+
sortTypeToString(currentSortType),
63+
style: TextStyle(
64+
color: Theme.of(context).colorScheme.onSurface,
65+
fontSize: 15,
66+
fontWeight: FontWeight.w600,
67+
letterSpacing: 0.15,
68+
height: 1.2,
69+
),
70+
),
71+
],
72+
),
6873
),
6974
itemBuilder: (context) {
7075
return sortTypes.map((type) {

0 commit comments

Comments
 (0)