mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-05-10 15:40:38 +00:00
- Add `ChapterWithPages` model and `MangaReaderController` (FamilyAsyncNotifier) to load chapter + pages in a single provider (`mangaReaderProvider`) - Replace synchronous Isar fetch in `MangaReaderView` with `ref.watch(mangaReaderProvider)` - Unify loading, error, and data states using a shared `scaffoldWith` helper - Remove duplicated `Scaffold`/`AppBar` boilerplate and inline SystemChrome restore logic - Simplify error handling
30 lines
944 B
Dart
30 lines
944 B
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:mangayomi/main.dart';
|
|
import 'package:mangayomi/models/chapter.dart';
|
|
import 'package:mangayomi/services/get_chapter_pages.dart';
|
|
|
|
class ChapterWithPages {
|
|
final Chapter chapter;
|
|
final GetChapterPagesModel pages;
|
|
|
|
ChapterWithPages({required this.chapter, required this.pages});
|
|
}
|
|
|
|
class MangaReaderController extends FamilyAsyncNotifier<ChapterWithPages, int> {
|
|
@override
|
|
Future<ChapterWithPages> build(int chapterId) async {
|
|
final chap = await isar.chapters.get(chapterId);
|
|
if (chap == null) {
|
|
throw Exception('Chapter #$chapterId not found');
|
|
}
|
|
|
|
final pages = await ref.read(getChapterPagesProvider(chapter: chap).future);
|
|
|
|
return ChapterWithPages(chapter: chap, pages: pages);
|
|
}
|
|
}
|
|
|
|
final mangaReaderProvider =
|
|
AsyncNotifierProvider.family<MangaReaderController, ChapterWithPages, int>(
|
|
MangaReaderController.new,
|
|
);
|