Remove yaru dep
This commit is contained in:
parent
a15fae89eb
commit
26a2bd3f5e
21 changed files with 291 additions and 311 deletions
|
@ -20,3 +20,15 @@ extension Capitalize on String {
|
|||
String toCapitalized() =>
|
||||
length > 0 ? "${this[0].toUpperCase()}${substring(1).toLowerCase()}" : "";
|
||||
}
|
||||
|
||||
extension GetTheme on ThemeData {
|
||||
ThemeData tweaked() => copyWith(
|
||||
textTheme: (brightness == Brightness.light
|
||||
? ThemeData.light()
|
||||
: ThemeData.dark())
|
||||
.textTheme,
|
||||
navigationRailTheme: NavigationRailThemeData(
|
||||
backgroundColor: Colors.transparent,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:brook/widgets/app.dart';
|
||||
import 'package:window_size/window_size.dart';
|
||||
import 'package:yaru/yaru.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
void main() async {
|
||||
await YaruWindowTitleBar.ensureInitialized();
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setWindowMinSize(const Size.square(500));
|
||||
await windowManager.ensureInitialized();
|
||||
windowManager.waitUntilReadyToShow(WindowOptions(
|
||||
minimumSize: Size.square(500),
|
||||
titleBarStyle: TitleBarStyle.hidden,
|
||||
));
|
||||
|
||||
runApp(const ProviderScope(child: App()));
|
||||
}
|
||||
|
|
6
lib/models/decoration_type.dart
Normal file
6
lib/models/decoration_type.dart
Normal file
|
@ -0,0 +1,6 @@
|
|||
enum DecorationType {
|
||||
close,
|
||||
maximize,
|
||||
restore,
|
||||
minimize,
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
import 'package:brook/models/decoration_type.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:yaru/yaru.dart';
|
||||
part "decorations.freezed.dart";
|
||||
|
||||
@freezed
|
||||
class Decorations with _$Decorations {
|
||||
const factory Decorations({
|
||||
required List<YaruWindowControlType> leading,
|
||||
required List<YaruWindowControlType> trailing,
|
||||
required List<DecorationType> leading,
|
||||
required List<DecorationType> trailing,
|
||||
}) = _Decorations;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import 'package:brook/models/decoration_type.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import "package:riverpod_annotation/riverpod_annotation.dart";
|
||||
import 'package:brook/models/decorations.dart';
|
||||
import 'package:brook/providers/button_layout_provider.dart';
|
||||
import 'package:yaru/yaru.dart';
|
||||
import "package:collection/collection.dart";
|
||||
part 'decorations_provider.g.dart';
|
||||
|
||||
@riverpod
|
||||
Decorations decorations(Ref ref) {
|
||||
List<YaruWindowControlType> parse(String section) => section
|
||||
List<DecorationType> parse(String section) => section
|
||||
.split(",")
|
||||
.map((button) => YaruWindowControlType.values.firstWhereOrNull(
|
||||
.map((button) => DecorationType.values.firstWhereOrNull(
|
||||
(element) => element.name == button,
|
||||
))
|
||||
.nonNulls
|
||||
|
|
|
@ -20,7 +20,7 @@ Future<IList<SearchResult>> searchProvider(
|
|||
SearchType.songs => await yt.searchSongs(search),
|
||||
SearchType.albums => await yt.searchAlbums(search),
|
||||
SearchType.videos => await yt.searchVideos(search),
|
||||
SearchType.artists => await yt.searchAlbums(search),
|
||||
SearchType.artists => await yt.searchArtists(search),
|
||||
SearchType.playlists => await yt.searchPlaylists(search),
|
||||
},
|
||||
);
|
||||
|
|
|
@ -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(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
),
|
||||
))
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -10,7 +10,6 @@ import "package:flutter/material.dart";
|
|||
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:yaru/yaru.dart';
|
||||
import 'package:brook/providers/button_layout_provider.dart';
|
||||
import 'package:brook/providers/warmup_provider.dart';
|
||||
|
||||
|
@ -30,30 +29,28 @@ class App extends HookConsumerWidget {
|
|||
ytmusicProvider,
|
||||
])))
|
||||
.betterWhen(
|
||||
data: (_) => YaruDetailPage(
|
||||
appBar: const Appbar(title: "Brook"),
|
||||
body: tabs[selected.value],
|
||||
data: (_) => Scaffold(
|
||||
appBar: Appbar(title: "Brook"),
|
||||
bottomNavigationBar: NavigationBar(
|
||||
destinations: tabs
|
||||
.map(
|
||||
(tab) => NavigationDestination(
|
||||
icon: Icon(tab.icon),
|
||||
icon: Icon(
|
||||
tab.icon,
|
||||
),
|
||||
label: tab.title,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
selectedIndex: selected.value,
|
||||
onDestinationSelected: (index) => selected.value = index,
|
||||
selectedIndex: selected.value,
|
||||
),
|
||||
body: tabs[selected.value],
|
||||
),
|
||||
),
|
||||
),
|
||||
theme: AdwaitaThemeData.light().copyWith(
|
||||
textTheme: const YaruThemeData().theme?.textTheme,
|
||||
),
|
||||
darkTheme: AdwaitaThemeData.dark().copyWith(
|
||||
textTheme: const YaruThemeData().darkTheme?.textTheme,
|
||||
),
|
||||
theme: AdwaitaThemeData.light().tweaked(),
|
||||
darkTheme: AdwaitaThemeData.dark(),
|
||||
debugShowCheckedModeBanner: false,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import 'package:adwaita_icons/adwaita_icons.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:brook/providers/decorations_provider.dart';
|
||||
import 'package:yaru/yaru.dart';
|
||||
import 'package:brook/models/decoration_type.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
class Appbar extends ConsumerWidget implements PreferredSizeWidget {
|
||||
final String title;
|
||||
|
@ -11,42 +13,61 @@ class Appbar extends ConsumerWidget implements PreferredSizeWidget {
|
|||
});
|
||||
|
||||
@override
|
||||
Size get preferredSize => const YaruWindowTitleBar().preferredSize;
|
||||
Size get preferredSize => AppBar().preferredSize;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final window = YaruWindow.of(context);
|
||||
|
||||
List<Widget> getControl(List<YaruWindowControlType> types) => [
|
||||
const SizedBox(width: 6),
|
||||
List<Widget> getControl(List<DecorationType> types) => [
|
||||
SizedBox(width: 6),
|
||||
...types.map(
|
||||
(type) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
child: YaruWindowControl(
|
||||
type: type,
|
||||
onTap: switch (type) {
|
||||
YaruWindowControlType.close => window.close,
|
||||
YaruWindowControlType.maximize => () => window.state().then(
|
||||
(state) => state.isMaximized!
|
||||
? window.restore()
|
||||
: window.maximize(),
|
||||
(type) {
|
||||
final decoration = switch (type) {
|
||||
DecorationType.close => (
|
||||
onClick: windowManager.close,
|
||||
icon: AdwaitaIcons.window_close,
|
||||
),
|
||||
DecorationType.maximize => (
|
||||
onClick: windowManager.maximize,
|
||||
icon: AdwaitaIcons.window_maximize,
|
||||
),
|
||||
DecorationType.minimize => (
|
||||
onClick: windowManager.minimize,
|
||||
icon: AdwaitaIcons.window_minimize,
|
||||
),
|
||||
DecorationType.restore => (
|
||||
onClick: windowManager.restore,
|
||||
icon: AdwaitaIcons.window_restore,
|
||||
),
|
||||
};
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
child: SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: IconButton(
|
||||
padding: EdgeInsets.all(4),
|
||||
onPressed: decoration.onClick,
|
||||
style: ButtonStyle(
|
||||
backgroundColor: WidgetStatePropertyAll(
|
||||
Theme.of(context).colorScheme.surface,
|
||||
),
|
||||
YaruWindowControlType.minimize => window.minimize,
|
||||
YaruWindowControlType.restore => window.restore,
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
icon: AdwaitaIcon(decoration.icon),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
SizedBox(width: 6),
|
||||
];
|
||||
|
||||
final decorations = ref.watch(decorationsProvider);
|
||||
|
||||
return YaruWindowTitleBar(
|
||||
return AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
title: Text(title),
|
||||
leading: Row(children: [
|
||||
SizedBox(width: 12),
|
||||
...getControl(decorations.leading),
|
||||
if (Navigator.of(context).canPop())
|
||||
BackButton(
|
||||
style: ButtonStyle(
|
||||
|
@ -55,12 +76,9 @@ class Appbar extends ConsumerWidget implements PreferredSizeWidget {
|
|||
padding: WidgetStatePropertyAll(EdgeInsets.zero),
|
||||
),
|
||||
),
|
||||
...getControl(decorations.leading)
|
||||
]),
|
||||
buttonPadding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
actions: getControl(decorations.trailing),
|
||||
border: BorderSide.none,
|
||||
style: YaruTitleBarStyle.undecorated,
|
||||
centerTitle: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
35
lib/widgets/result.dart
Normal file
35
lib/widgets/result.dart
Normal file
|
@ -0,0 +1,35 @@
|
|||
import 'package:brook/widgets/thumbnail.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Result extends StatelessWidget {
|
||||
final String thumb;
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final VoidCallback onClick;
|
||||
const Result({
|
||||
required this.thumb,
|
||||
required this.onClick,
|
||||
required this.title,
|
||||
this.subtitle,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SizedBox(
|
||||
height: 64,
|
||||
child: ListTile(
|
||||
leading: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: Thumbnail(
|
||||
url: thumb,
|
||||
onClick: onClick,
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
title,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: subtitle == null ? null : Text(subtitle!),
|
||||
),
|
||||
);
|
||||
}
|
|
@ -17,6 +17,10 @@ class SelectButton<T extends Enum> extends HookWidget {
|
|||
Widget build(BuildContext context) {
|
||||
final oldValue = useState(<T>{});
|
||||
return SegmentedButton(
|
||||
style: SegmentedButton.styleFrom(
|
||||
side: BorderSide.none,
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
),
|
||||
segments: values
|
||||
.map((value) => ButtonSegment(
|
||||
value: value,
|
||||
|
|
|
@ -4,21 +4,29 @@ class Thumbnail extends StatelessWidget {
|
|||
final String url;
|
||||
final VoidCallback onClick;
|
||||
final double radius;
|
||||
final ShapeBorder? border;
|
||||
final Widget? child;
|
||||
const Thumbnail({
|
||||
super.key,
|
||||
required this.url,
|
||||
required this.onClick,
|
||||
this.radius = 16,
|
||||
this.border,
|
||||
this.child,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ClipRRect(
|
||||
borderRadius: BorderRadius.all(Radius.circular(radius)),
|
||||
child: InkWell(
|
||||
onTap: onClick,
|
||||
child: Image.network(
|
||||
url,
|
||||
fit: BoxFit.fill,
|
||||
)),
|
||||
child: Material(
|
||||
child: Ink.image(
|
||||
image: NetworkImage(url),
|
||||
fit: BoxFit.fill,
|
||||
child: InkWell(
|
||||
onTap: onClick,
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
Reference in a new issue