artists.dart 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:http/http.dart' as http;
  4. import '../utils/url.dart';
  5. Future<List<String>> fetchArtists(String apiUrl) async {
  6. final response = await http.get(formattedUrl(apiUrl, '/artists'));
  7. if (response.statusCode == 200) {
  8. return List<String>.from(jsonDecode(response.body)['artists']);
  9. } else {
  10. throw Exception('Failed to load artists');
  11. }
  12. }
  13. class Artist extends StatelessWidget {
  14. final String artist;
  15. final void Function(String) onSelect;
  16. Artist({
  17. @required this.artist,
  18. @required this.onSelect,
  19. });
  20. @override
  21. Widget build(BuildContext context) {
  22. return InkWell(
  23. onTap: () {
  24. onSelect(artist);
  25. },
  26. child: SizedBox(
  27. height: 40,
  28. width: MediaQuery.of(context).size.width,
  29. child: Container(
  30. child: Align(
  31. alignment: Alignment.centerLeft,
  32. child: Text(
  33. artist.length == 0 ? 'Unknown artist' : artist,
  34. style: TextStyle(
  35. fontSize: 18,
  36. ),
  37. ),
  38. ),
  39. ),
  40. ),
  41. );
  42. }
  43. }