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:
10
bookshelf_flutter/lib/models/app_screen.dart
Normal file
10
bookshelf_flutter/lib/models/app_screen.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
// App screen enum
|
||||
enum AppScreen {
|
||||
library,
|
||||
categories,
|
||||
wishlist,
|
||||
settings,
|
||||
details,
|
||||
addBook,
|
||||
scanner,
|
||||
}
|
||||
127
bookshelf_flutter/lib/models/book.dart
Normal file
127
bookshelf_flutter/lib/models/book.dart
Normal file
@@ -0,0 +1,127 @@
|
||||
import 'book_status.dart';
|
||||
|
||||
// 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 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
20
bookshelf_flutter/lib/models/book_status.dart
Normal file
20
bookshelf_flutter/lib/models/book_status.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
// 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';
|
||||
}
|
||||
}
|
||||
}
|
||||
27
bookshelf_flutter/lib/models/category.dart
Normal file
27
bookshelf_flutter/lib/models/category.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Category record - using Dart records as data classes
|
||||
typedef Category = ({
|
||||
String id,
|
||||
String name,
|
||||
int count,
|
||||
IconData icon,
|
||||
String colorClass,
|
||||
});
|
||||
|
||||
// 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,
|
||||
);
|
||||
}
|
||||
@@ -1,185 +1,5 @@
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
// Barrel export for all models
|
||||
export 'app_screen.dart';
|
||||
export 'book_status.dart';
|
||||
export 'category.dart';
|
||||
export 'book.dart';
|
||||
Reference in New Issue
Block a user