Files
logic-puzzle/lib/ui/library.dart
T
2026-11-15 16:20:17 +01:00

294 lines
11 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import '../services/browser_assets.dart';
import 'package:flutter/material.dart';
import '../domain/book.dart';
import 'translation.dart';
const _shelfPaper = Color(0xfff6f1e7);
const _shelfInk = Color(0xff283e37);
const _shelfMuted = Color(0xff746f62);
TextStyle _type(double size, {Color color = _shelfInk, bool serif = false}) =>
TextStyle(
fontFamily: serif ? 'serif' : 'sans-serif',
fontSize: size,
height: serif ? 1.2 : 1.5,
color: color,
);
/// The collection has its own quiet surface, outside any one story's notebook.
class LibraryShelf extends StatelessWidget {
const LibraryShelf({
super.key,
required this.builder,
required this.onSettings,
this.activities,
});
final Widget Function(BuildContext context, double width) builder;
final VoidCallback onSettings;
final Widget? activities;
@override
Widget build(BuildContext context) => ColoredBox(
color: _shelfPaper,
child: SafeArea(
child: LayoutBuilder(
builder: (context, constraints) {
final compact = constraints.maxWidth < 600;
final padding = compact ? 24.0 : 48.0;
return SingleChildScrollView(
key: const ValueKey('library-scroll'),
padding: EdgeInsets.fromLTRB(padding, 20, padding, 48),
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 1120),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Wrap(
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 24,
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.auto_stories_outlined,
color: _shelfInk,
size: 22,
),
const SizedBox(width: 10),
Text('L U M E N', style: _type(13)),
],
),
TextButton.icon(
onPressed: onSettings,
icon: const Icon(Icons.tune_rounded, size: 18),
label: CopyText('Settings', style: _type(13)),
style: TextButton.styleFrom(
foregroundColor: _shelfInk,
minimumSize: const Size(48, 48),
),
),
],
),
const SizedBox(height: 20),
Divider(color: _shelfInk.withValues(alpha: .18)),
SizedBox(height: compact ? 28 : 44),
?activities,
CopyText(
'Choose a book',
style: _type(compact ? 36 : 48, serif: true),
),
const SizedBox(height: 12),
CopyText(
'Open a book to continue where you left off.',
style: _type(15, color: _shelfMuted),
),
SizedBox(height: compact ? 30 : 40),
LayoutBuilder(
builder: (context, c) => builder(context, c.maxWidth),
),
],
),
),
),
);
},
),
),
);
}
class LibraryBookCard extends StatelessWidget {
const LibraryBookCard({
super.key,
required this.story,
required this.restored,
required this.resuming,
required this.languages,
required this.onOpen,
});
final Book story;
final int restored;
final bool resuming;
final List<String> languages;
final VoidCallback onOpen;
@override
Widget build(BuildContext context) {
final (cloth, light) = switch (story.id) {
'mara-island' => (const Color(0xff355751), const Color(0xffe0e5d6)),
'paper-boat' => (const Color(0xff526c85), const Color(0xffe1e9e8)),
_ => (const Color(0xff51445e), const Color(0xffe8dfd8)),
};
return Semantics(
button: true,
child: Material(
color: Colors.transparent,
child: InkWell(
key: ValueKey('library-book-${story.id}'),
onTap: onOpen,
borderRadius: BorderRadius.circular(8),
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (story.id == 'mara-island' && story.coverAsset != null)
Center(
child: AspectRatio(
aspectRatio: 1.5,
child: Stack(
fit: StackFit.expand,
children: [
Image.asset(
artworkAsset(story.coverAsset!),
fit: BoxFit.contain,
excludeFromSemantics: true,
errorBuilder: (_, _, _) =>
Icon(Icons.menu_book, size: 64, color: light),
),
Center(
child: FractionallySizedBox(
widthFactor: .49,
child: ExcludeSemantics(
child: FittedBox(
fit: BoxFit.scaleDown,
child: CopyText(
'Mara’s\nisland notebook',
textAlign: TextAlign.center,
style: const TextStyle(
fontFamily: 'MaraHand',
fontSize: 28,
color: Color(0xff5e5140),
),
),
),
),
),
),
],
),
),
)
else
Container(
height: 276,
padding: const EdgeInsets.fromLTRB(22, 20, 14, 20),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [cloth, Color.lerp(cloth, Colors.black, .2)!],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
boxShadow: [
BoxShadow(
color: cloth.withValues(alpha: .22),
offset: const Offset(0, 10),
blurRadius: 16,
spreadRadius: -5,
),
],
border: Border(
left: BorderSide(
color: Color.lerp(cloth, Colors.black, .35)!,
width: 7,
),
right: BorderSide(color: light, width: 3),
),
),
child: Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
border: Border.all(color: light.withValues(alpha: .4)),
),
child: Column(
children: [
Icon(
Icons.auto_awesome_outlined,
size: 18,
color: light,
),
const SizedBox(height: 12),
Expanded(
child: story.coverAsset == null
? Icon(Icons.menu_book, size: 64, color: light)
: Image.asset(
artworkAsset(story.coverAsset!),
fit: BoxFit.contain,
excludeFromSemantics: true,
errorBuilder: (_, _, _) => Icon(
Icons.menu_book,
size: 64,
color: light,
),
),
),
const SizedBox(height: 12),
SizedBox(width: 38, child: Divider(color: light)),
],
),
),
),
const SizedBox(height: 24),
CopyText(story.title, style: _type(25, serif: true)),
const SizedBox(height: 10),
if (story.description.isNotEmpty)
CopyText(
story.description,
style: _type(14, color: _shelfMuted),
),
if (languages.length > 1) ...[
const SizedBox(height: 10),
Text(
languages.join(' · '),
style: _type(12, color: _shelfMuted),
),
],
const SizedBox(height: 20),
if (story.levels.isNotEmpty) ...[
ClipRRect(
borderRadius: BorderRadius.circular(2),
child: LinearProgressIndicator(
value: restored / story.levels.length,
minHeight: 3,
color: cloth,
backgroundColor: cloth.withValues(alpha: .13),
),
),
const SizedBox(height: 8),
CopyText(
'$restored / ${story.levels.length} memories restored',
style: _type(12, color: _shelfMuted),
),
],
const SizedBox(height: 16),
Row(
children: [
Expanded(
child: CopyText(
resuming ? 'Continue reading' : 'Open this book ›',
style: _type(
14,
color: cloth,
).copyWith(fontWeight: FontWeight.w600),
),
),
Icon(Icons.arrow_forward_rounded, size: 18, color: cloth),
],
),
const SizedBox(height: 8),
],
),
),
),
),
);
}
}