content: import 'package:flutter/material.dart';
  import 'package:mangayomi/main.dart';
  import 'package:mangayomi/models/chapter.dart';
  import 'package:mangayomi/models/download.dart';
  import 'package:mangayomi/modules/manga/reader/providers/push_router.dart';
  import 'package:mangayomi/modules/manga/reader/providers/reader_controller_provider.dart';
  import 'package:mangayomi/services/download_manager/m3u8/m3u8_downloader.dart';
  
  extension ChapterExtension on Chapter {
    Future<void> pushToReaderView(
      BuildContext context, {
      bool ignoreIsRead = false,
    }) async {
      if (ignoreIsRead || !isRead!) {
        await pushMangaReaderView(context: context, chapter: this);
      } else {
        final filteredChaps = manga.value!.getFilteredChapterList();
        bool exist = false;
        for (var filteredChap in filteredChaps.reversed) {
          if (filteredChap.toJson().toString() == toJson().toString()) {
            exist = true;
          }
          if (exist && !filteredChap.isRead!) {
            await pushMangaReaderView(context: context, chapter: filteredChap);
            break;
          }
        }
      }
    }
  
    void cancelDownloads(int? downloadId) {
      final (receivePort, isolate) = isolateChapsSendPorts['$id'] ?? (null, null);
      isolate?.kill();
      receivePort?.close();
      isar.writeTxnSync(() {
        isar.downloads.deleteSync(id!);
        if (downloadId != null) {
          isar.downloads.deleteSync(downloadId);
        }
      });
    }
  }
  