Fix import paths and test issues
- 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
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../models/models.dart';
|
||||
import 'book_details_event.dart';
|
||||
import 'book_details_state.dart';
|
||||
|
||||
class BookDetailsBloc extends Bloc<BookDetailsEvent, BookDetailsState> {
|
||||
BookDetailsBloc() : super(BookDetailsState.initial()) {
|
||||
on<LoadBookDetails>(_onLoadBookDetails);
|
||||
on<ToggleFavorite>(_onToggleFavorite);
|
||||
on<UpdateProgress>(_onUpdateProgress);
|
||||
on<UpdateStatus>(_onUpdateStatus);
|
||||
on<DeleteBook>(_onDeleteBook);
|
||||
}
|
||||
|
||||
void _onLoadBookDetails(LoadBookDetails event, Emitter<BookDetailsState> emit) {
|
||||
emit(state.copyWith(
|
||||
book: event.book,
|
||||
isLoading: false,
|
||||
));
|
||||
}
|
||||
|
||||
void _onToggleFavorite(ToggleFavorite event, Emitter<BookDetailsState> emit) {
|
||||
if (state.book == null) return;
|
||||
|
||||
final updatedBook = state.book!.copyWith(
|
||||
isFavorite: !state.book!.isFavorite,
|
||||
);
|
||||
|
||||
emit(state.copyWith(
|
||||
book: updatedBook,
|
||||
));
|
||||
}
|
||||
|
||||
void _onUpdateProgress(UpdateProgress event, Emitter<BookDetailsState> emit) {
|
||||
if (state.book == null) return;
|
||||
|
||||
final updatedBook = state.book!.copyWith(
|
||||
progress: event.progress,
|
||||
status: event.progress >= 100 ? BookStatus.done : BookStatus.reading,
|
||||
);
|
||||
|
||||
emit(state.copyWith(
|
||||
book: updatedBook,
|
||||
));
|
||||
}
|
||||
|
||||
void _onUpdateStatus(UpdateStatus event, Emitter<BookDetailsState> emit) {
|
||||
if (state.book == null) return;
|
||||
|
||||
final updatedBook = state.book!.copyWith(
|
||||
status: event.status,
|
||||
);
|
||||
|
||||
emit(state.copyWith(
|
||||
book: updatedBook,
|
||||
));
|
||||
}
|
||||
|
||||
void _onDeleteBook(DeleteBook event, Emitter<BookDetailsState> emit) {
|
||||
emit(state.copyWith(
|
||||
isDeleted: true,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import '../../../models/models.dart';
|
||||
|
||||
abstract class BookDetailsEvent {
|
||||
const BookDetailsEvent();
|
||||
}
|
||||
|
||||
class LoadBookDetails extends BookDetailsEvent {
|
||||
final Book book;
|
||||
const LoadBookDetails(this.book);
|
||||
}
|
||||
|
||||
class ToggleFavorite extends BookDetailsEvent {
|
||||
const ToggleFavorite();
|
||||
}
|
||||
|
||||
class UpdateProgress extends BookDetailsEvent {
|
||||
final int progress;
|
||||
const UpdateProgress(this.progress);
|
||||
}
|
||||
|
||||
class UpdateStatus extends BookDetailsEvent {
|
||||
final BookStatus status;
|
||||
const UpdateStatus(this.status);
|
||||
}
|
||||
|
||||
class DeleteBook extends BookDetailsEvent {
|
||||
const DeleteBook();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../../models/models.dart';
|
||||
|
||||
class BookDetailsState extends Equatable {
|
||||
final Book? book;
|
||||
final bool isLoading;
|
||||
final bool isDeleted;
|
||||
final String? errorMessage;
|
||||
|
||||
const BookDetailsState({
|
||||
this.book,
|
||||
this.isLoading = false,
|
||||
this.isDeleted = false,
|
||||
this.errorMessage,
|
||||
});
|
||||
|
||||
factory BookDetailsState.initial() {
|
||||
return const BookDetailsState(
|
||||
isLoading: true,
|
||||
);
|
||||
}
|
||||
|
||||
BookDetailsState copyWith({
|
||||
Book? book,
|
||||
bool? isLoading,
|
||||
bool? isDeleted,
|
||||
String? errorMessage,
|
||||
}) {
|
||||
return BookDetailsState(
|
||||
book: book ?? this.book,
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
isDeleted: isDeleted ?? this.isDeleted,
|
||||
errorMessage: errorMessage ?? this.errorMessage,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
book,
|
||||
isLoading,
|
||||
isDeleted,
|
||||
errorMessage,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user