open ai service

This commit is contained in:
2026-02-08 12:05:05 +06:00
parent d7722ad81d
commit 3209827e92
29 changed files with 2175 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../constants/constants.dart';
import 'book_event.dart';
import 'book_state.dart';
class BookBloc extends Bloc<BookEvent, BookState> {
BookBloc() : super(const BookState(books: initialBooks)) {
on<AddBook>((event, emit) {
emit(BookState(books: [...state.books, event.book]));
});
on<UpdateBook>((event, emit) {
final updated = state.books.map((b) {
return b.id == event.book.id ? event.book : b;
}).toList();
emit(BookState(books: updated));
});
on<DeleteBook>((event, emit) {
emit(
BookState(books: state.books.where((b) => b.id != event.id).toList()),
);
});
on<ToggleFavorite>((event, emit) {
final updated = state.books.map((b) {
if (b.id != event.id) return b;
return (
id: b.id,
title: b.title,
author: b.author,
genre: b.genre,
annotation: b.annotation,
coverUrl: b.coverUrl,
pages: b.pages,
language: b.language,
publishedYear: b.publishedYear,
rating: b.rating,
status: b.status,
progress: b.progress,
isFavorite: !b.isFavorite,
);
}).toList();
emit(BookState(books: updated));
});
}
}