|
| 1 | +import 'package:fl_query_hooks/fl_query_hooks.dart'; |
| 2 | +import 'package:flutter/gestures.dart'; |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:gap/gap.dart'; |
| 5 | +import 'package:go_router/go_router.dart'; |
| 6 | +import 'package:hooks_riverpod/hooks_riverpod.dart'; |
| 7 | +import 'package:spotify/spotify.dart'; |
| 8 | +import 'package:spotube/collections/spotube_icons.dart'; |
| 9 | +import 'package:spotube/components/shared/image/universal_image.dart'; |
| 10 | +import 'package:spotube/models/spotify_friends.dart'; |
| 11 | +import 'package:spotube/provider/spotify_provider.dart'; |
| 12 | + |
| 13 | +class FriendItem extends HookConsumerWidget { |
| 14 | + final SpotifyFriendActivity friend; |
| 15 | + const FriendItem({ |
| 16 | + Key? key, |
| 17 | + required this.friend, |
| 18 | + }) : super(key: key); |
| 19 | + |
| 20 | + @override |
| 21 | + Widget build(BuildContext context, ref) { |
| 22 | + final ThemeData( |
| 23 | + textTheme: textTheme, |
| 24 | + colorScheme: colorScheme, |
| 25 | + ) = Theme.of(context); |
| 26 | + |
| 27 | + final queryClient = useQueryClient(); |
| 28 | + final spotify = ref.watch(spotifyProvider); |
| 29 | + |
| 30 | + return Container( |
| 31 | + padding: const EdgeInsets.all(8), |
| 32 | + decoration: BoxDecoration( |
| 33 | + color: colorScheme.surfaceVariant.withOpacity(0.3), |
| 34 | + borderRadius: BorderRadius.circular(15), |
| 35 | + ), |
| 36 | + constraints: const BoxConstraints( |
| 37 | + minWidth: 300, |
| 38 | + ), |
| 39 | + height: 80, |
| 40 | + child: Row( |
| 41 | + children: [ |
| 42 | + CircleAvatar( |
| 43 | + backgroundImage: UniversalImage.imageProvider( |
| 44 | + friend.user.imageUrl, |
| 45 | + ), |
| 46 | + ), |
| 47 | + const Gap(8), |
| 48 | + Column( |
| 49 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 50 | + children: [ |
| 51 | + Text( |
| 52 | + friend.user.name, |
| 53 | + style: textTheme.bodyLarge, |
| 54 | + ), |
| 55 | + RichText( |
| 56 | + text: TextSpan( |
| 57 | + style: textTheme.bodySmall, |
| 58 | + children: [ |
| 59 | + TextSpan( |
| 60 | + text: friend.track.name, |
| 61 | + recognizer: TapGestureRecognizer() |
| 62 | + ..onTap = () { |
| 63 | + context.push("/track/${friend.track.id}"); |
| 64 | + }, |
| 65 | + ), |
| 66 | + const TextSpan(text: " • "), |
| 67 | + const WidgetSpan( |
| 68 | + child: Icon( |
| 69 | + SpotubeIcons.artist, |
| 70 | + size: 12, |
| 71 | + ), |
| 72 | + ), |
| 73 | + TextSpan( |
| 74 | + text: " ${friend.track.artist.name}", |
| 75 | + recognizer: TapGestureRecognizer() |
| 76 | + ..onTap = () { |
| 77 | + context.push( |
| 78 | + "/artist/${friend.track.artist.id}", |
| 79 | + ); |
| 80 | + }, |
| 81 | + ), |
| 82 | + const TextSpan(text: "\n"), |
| 83 | + TextSpan( |
| 84 | + text: friend.track.context.name, |
| 85 | + recognizer: TapGestureRecognizer() |
| 86 | + ..onTap = () async { |
| 87 | + context.push( |
| 88 | + "/${friend.track.context.path}", |
| 89 | + extra: !friend.track.context.path |
| 90 | + .startsWith("album") |
| 91 | + ? null |
| 92 | + : await queryClient.fetchQuery<Album, dynamic>( |
| 93 | + "album/${friend.track.album.id}", |
| 94 | + () => spotify.albums.get( |
| 95 | + friend.track.album.id, |
| 96 | + ), |
| 97 | + ), |
| 98 | + ); |
| 99 | + }, |
| 100 | + ), |
| 101 | + const TextSpan(text: " • "), |
| 102 | + const WidgetSpan( |
| 103 | + child: Icon( |
| 104 | + SpotubeIcons.album, |
| 105 | + size: 12, |
| 106 | + ), |
| 107 | + ), |
| 108 | + TextSpan( |
| 109 | + text: " ${friend.track.album.name}", |
| 110 | + recognizer: TapGestureRecognizer() |
| 111 | + ..onTap = () async { |
| 112 | + final album = |
| 113 | + await queryClient.fetchQuery<Album, dynamic>( |
| 114 | + "album/${friend.track.album.id}", |
| 115 | + () => spotify.albums.get( |
| 116 | + friend.track.album.id, |
| 117 | + ), |
| 118 | + ); |
| 119 | + if (context.mounted) { |
| 120 | + context.push( |
| 121 | + "/album/${friend.track.album.id}", |
| 122 | + extra: album, |
| 123 | + ); |
| 124 | + } |
| 125 | + }, |
| 126 | + ), |
| 127 | + ], |
| 128 | + ), |
| 129 | + ), |
| 130 | + ], |
| 131 | + ), |
| 132 | + ], |
| 133 | + ), |
| 134 | + ); |
| 135 | + } |
| 136 | +} |
0 commit comments