Remove yaru dep

This commit is contained in:
Henry Hiles 2025-01-05 20:49:45 -05:00
parent a15fae89eb
commit 26a2bd3f5e
21 changed files with 291 additions and 311 deletions

View file

@ -1,13 +1,12 @@
import 'package:brook/helpers/extension_helper.dart';
import 'package:brook/providers/home_sections_provider.dart';
import 'package:brook/screens/album_page.dart';
import 'package:brook/screens/playlist_page.dart';
import 'package:brook/screens/album.dart';
import 'package:brook/screens/playlist.dart';
import 'package:brook/widgets/thumbnail.dart';
import 'package:dart_ytmusic_api/dart_ytmusic_api.dart';
import 'package:flutter/material.dart';
import 'package:brook/models/tab.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:yaru/yaru.dart';
class HomeTab extends ConsumerWidget implements TabPage {
const HomeTab({super.key});
@ -19,46 +18,56 @@ class HomeTab extends ConsumerWidget implements TabPage {
String get title => "Home";
@override
Widget build(BuildContext context, WidgetRef ref) => ref
.watch(homeSectionsProvider)
.betterWhen(
data: (sections) => ListView(
padding: EdgeInsets.symmetric(vertical: 4),
children: sections
.where(
(element) => element.contents.isNotEmpty,
)
.map(
(section) => YaruSection(
margin: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
headline: Text(section.title),
child: SizedBox(
height: 262,
child: ListView(
itemExtent: 268,
scrollDirection: Axis.horizontal,
children: section.contents
.map((song) => Padding(
padding:
EdgeInsets.only(right: 12, bottom: 4, top: 2),
child: Thumbnail(
url: song.thumbnails.first.url,
onClick: () => Navigator.of(context)
.push(MaterialPageRoute(
builder: (_) => switch (song) {
PlaylistDetailed _ =>
PlaylistPage(),
AlbumDetailed _ => AlbumPage(),
_ => throw "Unknown type",
})),
)))
.toList(),
Widget build(BuildContext context, WidgetRef ref) =>
ref.watch(homeSectionsProvider).betterWhen(
data: (sections) => ListView(
padding: EdgeInsets.symmetric(vertical: 4),
children: sections
.where((element) => element.contents.isNotEmpty)
.map(
(section) => Column(
children: [
ListTile(
title: Text(
section.title,
style: Theme.of(context).textTheme.displayMedium,
),
subtitle: SizedBox(
height: 266,
child: ListView(
padding: EdgeInsets.only(top: 6),
itemExtent: 268,
scrollDirection: Axis.horizontal,
children: section.contents
.map(
(song) => Padding(
padding: EdgeInsets.only(
right: 12,
bottom: 4,
top: 2,
),
child: Thumbnail(
url: song.thumbnails.first.url,
onClick: () => Navigator.of(context)
.push(MaterialPageRoute(
builder: (_) => switch (song) {
PlaylistDetailed _ =>
PlaylistPage(),
AlbumDetailed _ => AlbumPage(),
_ => throw "Unknown type",
},
)),
),
),
)
.toList(),
),
),
),
],
),
),
),
)
.toList(),
),
);
)
.toList(),
),
);
}

View file

@ -1,4 +1,5 @@
import 'package:brook/helpers/extension_helper.dart';
import 'package:brook/widgets/result.dart';
import 'package:collection/collection.dart';
import 'package:brook/providers/search_provider.dart';
import 'package:brook/widgets/thumbnail.dart';
@ -9,7 +10,6 @@ import 'package:brook/models/search_type.dart';
import 'package:brook/models/tab.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:yaru/yaru.dart';
class SearchTab extends HookConsumerWidget implements TabPage {
const SearchTab({super.key});
@ -28,9 +28,8 @@ class SearchTab extends HookConsumerWidget implements TabPage {
return ListView(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),
children: [
YaruSearchField(
hintText: "Search YouTube music...",
fillColor: Theme.of(context).colorScheme.surface,
SearchBar(
hintText: "Search YouTube Music...",
onChanged: (value) => search.value = value,
),
Padding(
@ -42,66 +41,71 @@ class SearchTab extends HookConsumerWidget implements TabPage {
),
),
Divider(),
SizedBox(height: 8),
ref
.watch(searchProviderProvider(
search: search.value,
searchType: type.value,
))
.betterWhen(
data: (results) => Column(
children: results
.mapIndexed((index, result) => switch (result) {
SongDetailed _ => Builder(builder: (_) {
final padding =
EdgeInsets.symmetric(horizontal: 16);
final leading = Thumbnail(
url: result.thumbnails.first.url,
onClick: () {},
);
return index == 0
? SizedBox(
height: 128,
child: YaruBanner.tile(
padding: padding,
icon: leading,
title: Text(result.name),
subtitle: Text(result.artist.name),
),
)
: YaruTile(
padding: padding,
leading: leading,
title: Text(result.name),
subtitle: Text(result.artist.name),
);
}),
AlbumDetailed _ => Thumbnail(
url: result.thumbnails.first.url,
onClick: () {},
),
VideoDetailed _ => Thumbnail(
url: result.thumbnails.first.url,
onClick: () {},
radius: 0,
),
ArtistDetailed _ => Thumbnail(
url: result.thumbnails.first.url,
onClick: () {},
),
PlaylistDetailed _ => Thumbnail(
url: result.thumbnails.first.url,
onClick: () {},
),
_ => throw Exception(
"Unknown Detailed Result: ${result.runtimeType}",
),
})
.map((element) => Padding(
padding: EdgeInsets.only(bottom: 16),
child: element,
))
.toList(),
data: (results) => LayoutBuilder(
builder: (_, constraints) {
final maxGridSize = (constraints.maxWidth / 3) - 4 * 3 * 2;
final gridSize = maxGridSize < 300 ? null : maxGridSize;
return Wrap(
children: [
...results
.mapIndexed((index, result) => switch (result) {
SongDetailed _ => Result(
thumb: result.thumbnails.first.url,
onClick: () {},
title: result.name,
subtitle: result.artist.name,
),
AlbumDetailed _ => Result(
thumb: result.thumbnails.first.url,
onClick: () {},
title: result.name,
subtitle: result.artist.name,
),
VideoDetailed _ => Thumbnail(
url: result.thumbnails.first.url,
onClick: () {},
child: Icon(
Icons.play_circle,
size: 48,
),
),
ArtistDetailed _ => Result(
thumb: result.thumbnails.first.url,
onClick: () {},
title: result.name,
),
PlaylistDetailed _ => Result(
thumb: result.thumbnails.first.url,
subtitle: result.artist.name,
onClick: () {},
title: result.name,
),
_ => throw Exception(
"Unknown Detailed Result: ${result.runtimeType}",
),
})
.mapIndexed((index, element) => index == 0
? element
: Padding(
padding: EdgeInsets.symmetric(
horizontal: 4,
vertical: 6,
),
child: SizedBox(
width: gridSize?.toDouble(),
child: element,
),
))
],
);
},
),
),
],