softplayer-web/lib/api/third_party/chartmuseum.dart

34 lines
789 B
Dart
Raw Normal View History

2024-03-27 21:07:53 +00:00
import 'dart:async';
import 'dart:convert';
import 'package:dio/dio.dart';
class HelmChart {
final String name;
final String version;
const HelmChart({
required this.name,
required this.version,
});
}
Future<List<HelmChart>> fetchCharts() async {
final dio = Dio();
final response = await dio.get('https://helm.badhouseplants.net/api/charts',
options: Options(headers: {
"Accept": "application/json",
}));
if (response.statusCode == 200) {
final Map<dynamic, dynamic> charsRaw = json.decode(response.data);
List<HelmChart> charts = [];
charsRaw.forEach((key, value) {
charts.add(HelmChart(name: key, version: value.first["version"]));
});
return charts;
} else {
throw Exception('Failed to load album');
}
}