@@ -7,17 +7,20 @@ import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
77import 'package:flutter_riverpod/flutter_riverpod.dart' ;
88
99class SortButton extends ConsumerWidget {
10- SortButton ({super .key});
11-
12- final Map <String , String > sortOptions = {
13- "media.metadata.title" : S .current.title,
14- "media.metadata.seriesName" : S .current.series,
15- "media.metadata.authorName" : S .current.author,
16- "media.metadata.publisher" : S .current.publisher,
17- "media.metadata.language" : S .current.language,
18- "media.duration" : S .current.duration,
19- "sequence" : S .current.sequence,
20- };
10+ final Map <String , String >? overwriteSortOptions;
11+ late final Map <String , String > sortOptions;
12+ SortButton ({super .key, this .overwriteSortOptions}) {
13+ sortOptions = overwriteSortOptions ??
14+ {
15+ "media.metadata.title" : S .current.title,
16+ "media.metadata.seriesName" : S .current.series,
17+ "media.metadata.authorName" : S .current.author,
18+ "media.metadata.publisher" : S .current.publisher,
19+ "media.metadata.language" : S .current.language,
20+ "media.duration" : S .current.duration,
21+ "sequence" : S .current.sequence,
22+ };
23+ }
2124
2225 @override
2326 Widget build (BuildContext context, WidgetRef ref) {
@@ -57,11 +60,19 @@ class SortButton extends ConsumerWidget {
5760 Navigator .of (context).pop ();
5861 }
5962
63+ void onItemLongPress () {
64+ sort.state = sort.state.copyWith (
65+ sort: sortKey,
66+ desc: isSelected ? (isDescending ? 1 : 0 ) : 1 ,
67+ );
68+ Navigator .of (context).pop ();
69+ }
70+
6071 return PlatformWidget (
61- material: (_, __) => _buildMaterialListTile (
62- sortValue, isSelected, isDescending, onItemTap),
63- cupertino: (_, __) => _buildCupertinoListTile (
64- sortValue, isSelected, isDescending, onItemTap),
72+ material: (_, __) => _buildMaterialListTile (sortValue, isSelected,
73+ isDescending, onItemTap, onItemLongPress ),
74+ cupertino: (_, __) => _buildCupertinoListTile (sortValue,
75+ isSelected, isDescending, onItemTap, onItemLongPress ),
6576 );
6677 },
6778 );
@@ -70,55 +81,62 @@ class SortButton extends ConsumerWidget {
7081 }
7182
7283 Widget _buildMaterialListTile (String sortValue, bool isSelected,
73- bool isDescending, VoidCallback onTap) {
74- return ListTile (
75- title: Row (
76- mainAxisAlignment: MainAxisAlignment .spaceBetween,
77- children: [
78- Text (sortValue),
79- if (isSelected)
80- Row (
81- children: [
82- Tooltip (
83- message: isDescending
84- ? S .current.ascending
85- : S .current.descending,
86- child: Icon (isDescending
87- ? Icons .arrow_upward
88- : Icons .arrow_downward)),
89- const SizedBox (width: 8 ),
90- const Icon (Icons .check),
91- ],
92- ),
93- ],
84+ bool isDescending, VoidCallback onTap, VoidCallback onLongPress) {
85+ return GestureDetector (
86+ onLongPress: onLongPress,
87+ child: ListTile (
88+ title: Row (
89+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
90+ children: [
91+ Text (sortValue),
92+ if (isSelected)
93+ Row (
94+ children: [
95+ Tooltip (
96+ message: isDescending
97+ ? S .current.ascending
98+ : S .current.descending,
99+ child: Icon (isDescending
100+ ? Icons .arrow_upward
101+ : Icons .arrow_downward)),
102+ const SizedBox (width: 8 ),
103+ const Icon (Icons .check),
104+ ],
105+ ),
106+ ],
107+ ),
108+ onTap: onTap,
94109 ),
95- onTap: onTap,
96110 );
97111 }
98112
99113 Widget _buildCupertinoListTile (String sortValue, bool isSelected,
100- bool isDescending, VoidCallback onTap) {
101- return CupertinoListTile (
102- title: Text (sortValue),
103- trailing: isSelected
104- ? Row (
105- mainAxisSize: MainAxisSize .min,
106- children: [
107- Tooltip (
108- message:
109- isDescending ? S .current.ascending : S .current.descending,
110- child: Icon (
111- isDescending
112- ? CupertinoIcons .arrow_up
113- : CupertinoIcons .arrow_down,
114- size: 16 ),
115- ),
116- const SizedBox (width: 8 ),
117- const Icon (CupertinoIcons .check_mark),
118- ],
119- )
120- : null ,
121- onTap: onTap,
114+ bool isDescending, VoidCallback onTap, VoidCallback onLongPress) {
115+ return GestureDetector (
116+ onLongPress: onLongPress,
117+ child: CupertinoListTile (
118+ title: Text (sortValue),
119+ trailing: isSelected
120+ ? Row (
121+ mainAxisSize: MainAxisSize .min,
122+ children: [
123+ Tooltip (
124+ message: isDescending
125+ ? S .current.ascending
126+ : S .current.descending,
127+ child: Icon (
128+ isDescending
129+ ? CupertinoIcons .arrow_up
130+ : CupertinoIcons .arrow_down,
131+ size: 16 ),
132+ ),
133+ const SizedBox (width: 8 ),
134+ const Icon (CupertinoIcons .check_mark),
135+ ],
136+ )
137+ : null ,
138+ onTap: onTap,
139+ ),
122140 );
123141 }
124142}
0 commit comments