- Fixed test file import paths to point to correct Bloc file locations - Fixed Bloc file import paths for models (../../../models/models.dart) - Added explicit type annotations to resolve null safety warnings - Fixed null safety issues in wishlist_bloc_test.dart - All 70 tests now passing
288 lines
10 KiB
Dart
288 lines
10 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import '../../bloc/app_bloc.dart';
|
|
import '../../bloc/app_event.dart';
|
|
import '../../../models/models.dart';
|
|
|
|
class BookDetailsScreen extends StatelessWidget {
|
|
final Book book;
|
|
|
|
const BookDetailsScreen({super.key, required this.book});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: const Color(0xFF112116),
|
|
body: CustomScrollView(
|
|
slivers: [
|
|
SliverAppBar(
|
|
expandedHeight: 460,
|
|
pinned: true,
|
|
backgroundColor: Colors.transparent,
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back_ios_new, color: Colors.white),
|
|
onPressed: () {
|
|
context.read<AppBloc>().add(const ScreenChanged(AppScreen.library));
|
|
},
|
|
),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.more_horiz, color: Colors.white),
|
|
onPressed: () {},
|
|
),
|
|
],
|
|
flexibleSpace: FlexibleSpaceBar(
|
|
background: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
CachedNetworkImage(
|
|
imageUrl: book.coverUrl ??
|
|
'https://picsum.photos/seed/placeholder/400/600',
|
|
fit: BoxFit.cover,
|
|
width: double.infinity,
|
|
),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Colors.transparent,
|
|
const Color(0xFF112116),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
SliverToBoxAdapter(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 12,
|
|
vertical: 6,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: Colors.black.withValues(alpha: 0.4),
|
|
borderRadius: BorderRadius.circular(20),
|
|
border: Border.all(
|
|
color: Colors.white.withValues(alpha: 0.1),
|
|
),
|
|
),
|
|
child: Text(
|
|
book.status.displayName,
|
|
style: const TextStyle(
|
|
color: Color(0xFF17CF54),
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
letterSpacing: 1,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
book.title,
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(
|
|
fontSize: 28,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
book.author,
|
|
style: const TextStyle(
|
|
fontSize: 18,
|
|
color: Color(0xFF93C8A5),
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
Wrap(
|
|
spacing: 8,
|
|
runSpacing: 8,
|
|
children: book.genre.split(',').map((genre) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 8,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF244730),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Text(
|
|
genre.trim(),
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
const SizedBox(height: 24),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: ElevatedButton.icon(
|
|
onPressed: () {
|
|
context.read<AppBloc>().add(const ScreenChanged(AppScreen.addBook));
|
|
},
|
|
icon: const Icon(Icons.edit_square),
|
|
label: const Text('Edit Details'),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: const Color(0xFF17CF54),
|
|
foregroundColor: Colors.white,
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: ElevatedButton.icon(
|
|
onPressed: () {
|
|
context.read<AppBloc>().add(BookDeleted(book.id));
|
|
},
|
|
icon: const Icon(Icons.delete),
|
|
label: const Text('Delete'),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.white.withValues(alpha: 0.05),
|
|
foregroundColor: Colors.white,
|
|
side: BorderSide(
|
|
color: Colors.white.withValues(alpha: 0.1),
|
|
),
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 32),
|
|
const Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: Text(
|
|
'About',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withValues(alpha: 0.05),
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(
|
|
color: Colors.white.withValues(alpha: 0.05),
|
|
),
|
|
),
|
|
child: Text(
|
|
book.annotation,
|
|
style: const TextStyle(
|
|
fontSize: 15,
|
|
color: Color(0xFF93C8A5),
|
|
height: 1.5,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
GridView.count(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
crossAxisCount: 2,
|
|
crossAxisSpacing: 12,
|
|
mainAxisSpacing: 12,
|
|
childAspectRatio: 1.2,
|
|
children: [
|
|
_buildInfoCard(
|
|
Icons.menu_book,
|
|
'Pages',
|
|
book.pages?.toString() ?? 'N/A',
|
|
Colors.blue,
|
|
),
|
|
_buildInfoCard(
|
|
Icons.language,
|
|
'Language',
|
|
book.language ?? 'Russian',
|
|
Colors.purple,
|
|
),
|
|
_buildInfoCard(
|
|
Icons.calendar_month,
|
|
'Published',
|
|
book.publishedYear?.toString() ?? 'N/A',
|
|
Colors.orange,
|
|
),
|
|
_buildInfoCard(
|
|
Icons.star,
|
|
'Rating',
|
|
'${book.rating ?? 0}/5',
|
|
Colors.amber,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildInfoCard(IconData icon, String label, String value, Color color) {
|
|
return Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withValues(alpha: 0.05),
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(
|
|
color: Colors.white.withValues(alpha: 0.05),
|
|
),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(6),
|
|
decoration: BoxDecoration(
|
|
color: color.withValues(alpha: 0.2),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Icon(icon, color: color, size: 18),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: 11,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.grey.shade500,
|
|
letterSpacing: 0.5,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
value,
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
} |