fix: dangling objects, removed old state provider for getPagesNumber

This commit is contained in:
Whiskas101 2025-11-20 22:19:21 +05:30
parent 20f8f1ad7c
commit 18e8abce94

View file

@ -180,7 +180,7 @@ class _MangaChapterPageGalleryState
); );
} }
discordRpc?.showIdleText(); discordRpc?.showIdleText();
_readerController.keepAliveLink?.close(); // _readerController.keepAliveLink?.close();
super.dispose(); super.dispose();
} }
@ -285,9 +285,9 @@ class _MangaChapterPageGalleryState
Axis _scrollDirection = Axis.vertical; Axis _scrollDirection = Axis.vertical;
bool _isReverseHorizontal = false; bool _isReverseHorizontal = false;
late final _showPagesNumber = StateProvider( // late final _showPagesNumber = StateProvider(
() => _readerController.getShowPageNumber(), // () => _readerController.getShowPageNumber(),
); // );
Color _backgroundColor(BuildContext context) => Color _backgroundColor(BuildContext context) =>
Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0.9); Theme.of(context).scaffoldBackgroundColor.withValues(alpha: 0.9);
@ -949,7 +949,7 @@ class _MangaChapterPageGalleryState
return const Duration(milliseconds: 200); return const Duration(milliseconds: 200);
} }
void _readProgressListener() { void _readProgressListener() async {
final itemPositions = _itemPositionsListener.itemPositions.value; final itemPositions = _itemPositionsListener.itemPositions.value;
if (itemPositions.isNotEmpty) { if (itemPositions.isNotEmpty) {
_currentIndex = itemPositions.first.index; _currentIndex = itemPositions.first.index;
@ -994,16 +994,16 @@ class _MangaChapterPageGalleryState
if (_isNextChapterPreloading) return; if (_isNextChapterPreloading) return;
try { try {
_isNextChapterPreloading = true; _isNextChapterPreloading = true;
ref if (!mounted) return;
.watch( final value = await ref.read(
getChapterPagesProvider( getChapterPagesProvider(
chapter: _readerController.getNextChapter(), chapter: _readerController.getNextChapter(),
).future, ).future,
) );
.then((value) { if (mounted) {
_preloadNextChapter(value, chapter); _preloadNextChapter(value, chapter);
_isNextChapterPreloading = false; _isNextChapterPreloading = false;
}); }
} on RangeError { } on RangeError {
_isNextChapterPreloading = false; _isNextChapterPreloading = false;
_addLastPageTransition(chapter); _addLastPageTransition(chapter);
@ -1136,7 +1136,7 @@ class _MangaChapterPageGalleryState
} }
} }
void _onPageChanged(int index) { Future<void> _onPageChanged(int index) async {
final cropBorders = ref.watch(cropBordersStateProvider); final cropBorders = ref.watch(cropBordersStateProvider);
if (cropBorders) { if (cropBorders) {
_processCropBordersByIndex(index); _processCropBordersByIndex(index);
@ -1178,16 +1178,16 @@ class _MangaChapterPageGalleryState
if (_isNextChapterPreloading) return; if (_isNextChapterPreloading) return;
try { try {
_isNextChapterPreloading = true; _isNextChapterPreloading = true;
ref if (!mounted) return;
.watch( final value = await ref.watch(
getChapterPagesProvider( getChapterPagesProvider(
chapter: _readerController.getNextChapter(), chapter: _readerController.getNextChapter(),
).future, ).future,
) );
.then((value) { if (mounted) {
_preloadNextChapter(value, chapter); _preloadNextChapter(value, chapter);
_isNextChapterPreloading = false; _isNextChapterPreloading = false;
}); }
} on RangeError { } on RangeError {
_isNextChapterPreloading = false; _isNextChapterPreloading = false;
_addLastPageTransition(chapter); _addLastPageTransition(chapter);
@ -1380,41 +1380,40 @@ class _MangaChapterPageGalleryState
void _processCropBordersByIndex(int index) async { void _processCropBordersByIndex(int index) async {
if (!_cropBorderCheckList.contains(index)) { if (!_cropBorderCheckList.contains(index)) {
_cropBorderCheckList.add(index); _cropBorderCheckList.add(index);
ref if (!mounted) return;
.watch( final value = await ref.read(
cropBordersProvider( cropBordersProvider(
data: _uChapDataPreload[index], data: _uChapDataPreload[index],
cropBorder: true, cropBorder: true,
).future, ).future,
) );
.then((value) {
_uChapDataPreload[index] = _uChapDataPreload[index]
..cropImage = value;
});
if (mounted) { if (mounted) {
setState(() {}); setState(() {
_uChapDataPreload[index] = _uChapDataPreload[index]
..cropImage = value;
});
} }
} }
} }
void _processCropBorders() async { void _processCropBorders() async {
if (_cropBorderCheckList.length == _uChapDataPreload.length) return; if (_cropBorderCheckList.length == _uChapDataPreload.length) return;
for (var i = 0; i < _uChapDataPreload.length; i++) { for (var i = 0; i < _uChapDataPreload.length; i++) {
if (!_cropBorderCheckList.contains(i)) { if (!_cropBorderCheckList.contains(i)) {
_cropBorderCheckList.add(i); _cropBorderCheckList.add(i);
ref if (!mounted) return;
.watch( final value = await ref.read(
cropBordersProvider( cropBordersProvider(
data: _uChapDataPreload[i], data: _uChapDataPreload[i],
cropBorder: true, cropBorder: true,
).future, ).future,
) );
.then((value) { if (mounted) {
_uChapDataPreload[i] = _uChapDataPreload[i]..cropImage = value; setState(() {
if (mounted) { _uChapDataPreload[i] = _uChapDataPreload[i]..cropImage = value;
setState(() {}); });
} }
});
} }
} }
} }
@ -1944,9 +1943,10 @@ class _MangaChapterPageGalleryState
return Consumer( return Consumer(
builder: (context, ref, child) { builder: (context, ref, child) {
final currentIndex = ref.watch(currentIndexProvider(chapter)); final currentIndex = ref.watch(currentIndexProvider(chapter));
final showPagesNumber = ref.watch(showPagesNumberStateProvider);
return _isView return _isView
? const SizedBox.shrink() ? const SizedBox.shrink()
: ref.watch(_showPagesNumber) : showPagesNumber
? Align( ? Align(
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
child: Text( child: Text(
@ -2328,13 +2328,14 @@ class _MangaChapterPageGalleryState
), ),
Consumer( Consumer(
builder: (context, ref, chil) { builder: (context, ref, chil) {
final showPageNumber = ref.watch(_showPagesNumber); final showPagesNumber = ref.watch(showPagesNumberStateProvider);
final animatePageTransitions = ref.watch( final animatePageTransitions = ref.watch(
animatePageTransitionsStateProvider, animatePageTransitionsStateProvider,
); );
final scaleType = ref.watch(scaleTypeStateProvider); final scaleType = ref.watch(scaleTypeStateProvider);
final fullScreenReader = ref.watch(fullScreenReaderStateProvider); final fullScreenReader = ref.watch(fullScreenReaderStateProvider);
final backgroundColor = ref.watch(backgroundColorStateProvider); final backgroundColor = ref.watch(backgroundColorStateProvider);
return SingleChildScrollView( return SingleChildScrollView(
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(vertical: 20), padding: const EdgeInsets.symmetric(vertical: 20),
@ -2393,7 +2394,7 @@ class _MangaChapterPageGalleryState
}, },
), ),
SwitchListTile( SwitchListTile(
value: showPageNumber, value: showPagesNumber,
title: Text( title: Text(
l10n.show_page_number, l10n.show_page_number,
style: TextStyle( style: TextStyle(
@ -2404,8 +2405,7 @@ class _MangaChapterPageGalleryState
), ),
), ),
onChanged: (value) { onChanged: (value) {
ref.read(_showPagesNumber.notifier).state = value; ref.read(showPagesNumber.notifier).set(value);
_readerController.setShowPageNumber(value);
}, },
), ),
SwitchListTile( SwitchListTile(