@@ -20,16 +20,25 @@ class StatsStreamFeesPage extends HookConsumerWidget {
20
20
@override
21
21
Widget build (BuildContext context, ref) {
22
22
final ThemeData (: textTheme, : hintColor) = Theme .of (context);
23
+ final duration = useState <HistoryDuration >(HistoryDuration .days30);
23
24
24
25
final topTracks = ref.watch (
25
- historyTopTracksProvider (HistoryDuration .allTime ),
26
+ historyTopTracksProvider (duration.value ),
26
27
);
27
28
final topTracksNotifier =
28
- ref.watch (historyTopTracksProvider (HistoryDuration .allTime ).notifier);
29
+ ref.watch (historyTopTracksProvider (duration.value ).notifier);
29
30
30
31
final artistsData = useMemoized (
31
32
() => topTracks.asData? .value.artists ?? [], [topTracks.asData? .value]);
32
33
34
+ final total = useMemoized (
35
+ () => artistsData.fold <double >(
36
+ 0 ,
37
+ (previousValue, element) => previousValue + element.count * 0.005 ,
38
+ ),
39
+ [artistsData],
40
+ );
41
+
33
42
return Scaffold (
34
43
appBar: const PageWindowTitleBar (
35
44
automaticallyImplyLeading: true ,
@@ -57,23 +66,72 @@ class StatsStreamFeesPage extends HookConsumerWidget {
57
66
),
58
67
),
59
68
),
60
- Skeletonizer .sliver (
61
- enabled: topTracks.isLoading && ! topTracks.isLoadingNextPage,
62
- child: SliverInfiniteList (
63
- onFetchData: () async {
64
- await topTracksNotifier.fetchMore ();
65
- },
66
- hasError: topTracks.hasError,
67
- isLoading: topTracks.isLoading && ! topTracks.isLoadingNextPage,
68
- hasReachedMax: topTracks.asData? .value.hasMore ?? true ,
69
- itemCount: artistsData.length,
70
- itemBuilder: (context, index) {
71
- final artist = artistsData[index];
72
- return StatsArtistItem (
73
- artist: artist.artist,
74
- info: Text (usdFormatter.format (artist.count * 0.005 )),
75
- );
76
- },
69
+ SliverToBoxAdapter (
70
+ child: Padding (
71
+ padding: const EdgeInsets .symmetric (horizontal: 16 ),
72
+ child: Row (
73
+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
74
+ children: [
75
+ Text (
76
+ "Total ${usdFormatter .format (total )}" ,
77
+ style: textTheme.titleLarge,
78
+ ),
79
+ DropdownButton <HistoryDuration >(
80
+ value: duration.value,
81
+ onChanged: (value) {
82
+ if (value == null ) return ;
83
+ duration.value = value;
84
+ },
85
+ items: const [
86
+ DropdownMenuItem (
87
+ value: HistoryDuration .days7,
88
+ child: Text ("This week" ),
89
+ ),
90
+ DropdownMenuItem (
91
+ value: HistoryDuration .days30,
92
+ child: Text ("This month" ),
93
+ ),
94
+ DropdownMenuItem (
95
+ value: HistoryDuration .months6,
96
+ child: Text ("Last 6 months" ),
97
+ ),
98
+ DropdownMenuItem (
99
+ value: HistoryDuration .year,
100
+ child: Text ("This year" ),
101
+ ),
102
+ DropdownMenuItem (
103
+ value: HistoryDuration .years2,
104
+ child: Text ("Last 2 years" ),
105
+ ),
106
+ DropdownMenuItem (
107
+ value: HistoryDuration .allTime,
108
+ child: Text ("All time" ),
109
+ ),
110
+ ],
111
+ ),
112
+ ],
113
+ ),
114
+ ),
115
+ ),
116
+ SliverSafeArea (
117
+ sliver: Skeletonizer .sliver (
118
+ enabled: topTracks.isLoading && ! topTracks.isLoadingNextPage,
119
+ child: SliverInfiniteList (
120
+ onFetchData: () async {
121
+ await topTracksNotifier.fetchMore ();
122
+ },
123
+ hasError: topTracks.hasError,
124
+ isLoading: topTracks.isLoading && ! topTracks.isLoadingNextPage,
125
+ hasReachedMax: topTracks.asData? .value.hasMore ?? true ,
126
+ itemCount: artistsData.length,
127
+ itemBuilder: (context, index) {
128
+ final artist = artistsData[index];
129
+ return StatsArtistItem (
130
+ artist: artist.artist,
131
+ info: Text (usdFormatter.format (artist.count * 0.005 )),
132
+ );
133
+ },
134
+ ),
77
135
),
78
136
),
79
137
],
0 commit comments