- Created 8 separate BLoCs (Home, Library, BookDetails, AddBook, Scanner, Categories, Wishlist, Settings) - Each BLoC has its own event, state, and bloc files - Added 70 comprehensive tests covering all BLoC functionality - All tests passing (70/70) - Fixed linting issues and updated deprecated APIs - Improved code organization and maintainability
185 lines
4.1 KiB
Dart
185 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
// App screen enum
|
|
enum AppScreen {
|
|
library,
|
|
categories,
|
|
wishlist,
|
|
settings,
|
|
details,
|
|
addBook,
|
|
scanner,
|
|
}
|
|
|
|
// Book status enum
|
|
enum BookStatus {
|
|
reading,
|
|
done,
|
|
wantToRead,
|
|
}
|
|
|
|
// Extension for BookStatus to get display name
|
|
extension BookStatusExtension on BookStatus {
|
|
String get displayName {
|
|
switch (this) {
|
|
case BookStatus.reading:
|
|
return 'Reading Now';
|
|
case BookStatus.done:
|
|
return 'Completed';
|
|
case BookStatus.wantToRead:
|
|
return 'Wishlist';
|
|
}
|
|
}
|
|
}
|
|
|
|
// Category record - using Dart records as data classes
|
|
typedef Category = ({
|
|
String id,
|
|
String name,
|
|
int count,
|
|
IconData icon,
|
|
String colorClass,
|
|
});
|
|
|
|
// Book record - using Dart records as data classes
|
|
typedef Book = ({
|
|
String id,
|
|
String title,
|
|
String author,
|
|
String genre,
|
|
String annotation,
|
|
String? coverUrl,
|
|
int? pages,
|
|
String? language,
|
|
int? publishedYear,
|
|
double? rating,
|
|
BookStatus status,
|
|
int? progress,
|
|
bool isFavorite,
|
|
});
|
|
|
|
// Helper function to create a Category record
|
|
Category createCategory({
|
|
required String id,
|
|
required String name,
|
|
required int count,
|
|
required IconData icon,
|
|
required String colorClass,
|
|
}) {
|
|
return (
|
|
id: id,
|
|
name: name,
|
|
count: count,
|
|
icon: icon,
|
|
colorClass: colorClass,
|
|
);
|
|
}
|
|
|
|
// Helper function to create a Book record
|
|
Book createBook({
|
|
required String id,
|
|
required String title,
|
|
required String author,
|
|
required String genre,
|
|
required String annotation,
|
|
String? coverUrl,
|
|
int? pages,
|
|
String? language,
|
|
int? publishedYear,
|
|
double? rating,
|
|
required BookStatus status,
|
|
int? progress,
|
|
required bool isFavorite,
|
|
}) {
|
|
return (
|
|
id: id,
|
|
title: title,
|
|
author: author,
|
|
genre: genre,
|
|
annotation: annotation,
|
|
coverUrl: coverUrl,
|
|
pages: pages,
|
|
language: language,
|
|
publishedYear: publishedYear,
|
|
rating: rating,
|
|
status: status,
|
|
progress: progress,
|
|
isFavorite: isFavorite,
|
|
);
|
|
}
|
|
|
|
// Extension to create Book from partial data
|
|
extension BookExtension on Book {
|
|
Book copyWith({
|
|
String? id,
|
|
String? title,
|
|
String? author,
|
|
String? genre,
|
|
String? annotation,
|
|
String? coverUrl,
|
|
int? pages,
|
|
String? language,
|
|
int? publishedYear,
|
|
double? rating,
|
|
BookStatus? status,
|
|
int? progress,
|
|
bool? isFavorite,
|
|
}) {
|
|
return createBook(
|
|
id: id ?? this.id,
|
|
title: title ?? this.title,
|
|
author: author ?? this.author,
|
|
genre: genre ?? this.genre,
|
|
annotation: annotation ?? this.annotation,
|
|
coverUrl: coverUrl ?? this.coverUrl,
|
|
pages: pages ?? this.pages,
|
|
language: language ?? this.language,
|
|
publishedYear: publishedYear ?? this.publishedYear,
|
|
rating: rating ?? this.rating,
|
|
status: status ?? this.status,
|
|
progress: progress ?? this.progress,
|
|
isFavorite: isFavorite ?? this.isFavorite,
|
|
);
|
|
}
|
|
|
|
// Convert to JSON for storage/transport
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'title': title,
|
|
'author': author,
|
|
'genre': genre,
|
|
'annotation': annotation,
|
|
'coverUrl': coverUrl,
|
|
'pages': pages,
|
|
'language': language,
|
|
'publishedYear': publishedYear,
|
|
'rating': rating,
|
|
'status': status.name,
|
|
'progress': progress,
|
|
'isFavorite': isFavorite,
|
|
};
|
|
}
|
|
|
|
// Create Book from JSON
|
|
static Book fromJson(Map<String, dynamic> json) {
|
|
return (
|
|
id: json['id'] as String,
|
|
title: json['title'] as String,
|
|
author: json['author'] as String,
|
|
genre: json['genre'] as String,
|
|
annotation: json['annotation'] as String,
|
|
coverUrl: json['coverUrl'] as String?,
|
|
pages: json['pages'] as int?,
|
|
language: json['language'] as String?,
|
|
publishedYear: json['publishedYear'] as int?,
|
|
rating: (json['rating'] as num?)?.toDouble(),
|
|
status: BookStatus.values.firstWhere(
|
|
(e) => e.name == json['status'],
|
|
orElse: () => BookStatus.wantToRead,
|
|
),
|
|
progress: json['progress'] as int?,
|
|
isFavorite: json['isFavorite'] as bool? ?? false,
|
|
);
|
|
}
|
|
} |