Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import 'dart:convert';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:scrobbles/models/topartists.dart';
import 'package:scrobbles/network/scrobbles.dart';
import 'package:scrobbles/ui/widgets/card_content.dart';
import 'package:scrobbles/ui/widgets/charts/top_artists.dart';
import 'package:scrobbles/ui/widgets/error.dart';
class CardTopArtists extends StatelessWidget {
const CardTopArtists({super.key});
@override
Widget build(BuildContext context) {
final int daysCount = 14;
late Future<TopArtistsData> future = ScrobblesApi.fetchTopArtists(daysCount);
return FutureBuilder<TopArtistsData>(
future: future,
builder: (context, snapshot) {
if (snapshot.hasError) {
return ShowErrorWidget(message: '${snapshot.error}');
}
return CardContent(
color: Theme.of(context).colorScheme.surface,
title: 'top_artists_title'.tr(
namedArgs: {
'daysCount': daysCount.toString(),
},
),
content: ChartTopArtists(
chartData: snapshot.hasData
? TopArtistsData.fromJson(jsonDecode(snapshot.data.toString()))
: TopArtistsData.createEmpty(),
isLoading: !snapshot.hasData,
),
);
},
);
}
}