mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-06 19:19:28 +00:00
84 lines
2.3 KiB
Dart
84 lines
2.3 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:shelfsdk/audiobookshelf_api.dart';
|
|
import 'package:whispering_pages/widgets/shelves/author_shelf.dart';
|
|
import 'package:whispering_pages/widgets/shelves/book_shelf.dart';
|
|
|
|
/// A shelf that displays books/authors/series on the home page
|
|
///
|
|
/// this will build the appropriate shelf based on the type of the shelf
|
|
class HomeShelf extends HookConsumerWidget {
|
|
const HomeShelf({
|
|
super.key,
|
|
required this.shelf,
|
|
required this.title,
|
|
});
|
|
|
|
final String title;
|
|
final Shelf shelf;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
return switch (shelf.type) {
|
|
ShelfType.book => BookHomeShelf(
|
|
title: title,
|
|
shelf: LibraryItemShelf.fromJson(shelf.toJson()),
|
|
),
|
|
ShelfType.authors => AuthorHomeShelf(
|
|
title: title,
|
|
shelf: AuthorShelf.fromJson(shelf.toJson()),
|
|
),
|
|
_ => Container(),
|
|
};
|
|
}
|
|
}
|
|
|
|
/// A shelf that displays children on the home page
|
|
class SimpleHomeShelf extends HookConsumerWidget {
|
|
const SimpleHomeShelf({
|
|
super.key,
|
|
required this.children,
|
|
required this.title,
|
|
this.height,
|
|
});
|
|
|
|
/// the title of the shelf
|
|
final String title;
|
|
|
|
/// the children to display on the shelf
|
|
final List<Widget> children;
|
|
final double? height;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
// if height is null take up 30% of the smallest screen dimension
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(title, style: Theme.of(context).textTheme.titleLarge),
|
|
const SizedBox(height: 16),
|
|
SizedBox(
|
|
height: max(
|
|
min(
|
|
height ?? 0.3 * MediaQuery.of(context).size.shortestSide,
|
|
200.0,
|
|
),
|
|
150.0,
|
|
),
|
|
child: ListView.separated(
|
|
scrollDirection: Axis.horizontal,
|
|
itemBuilder: (context, index) => children[index],
|
|
separatorBuilder: (context, index) => const SizedBox(width: 16),
|
|
itemCount: children.length,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|