mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-05-08 05:20:46 +00:00
Fix Exception
``` [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: Bad state: Cannot use "ref" after the widget was disposed. #0 ConsumerStatefulElement._assertNotDisposed (package:flutter_riverpod/src/consumer.dart:550:7) consumer.dart:550 #1 ConsumerStatefulElement.read (package:flutter_riverpod/src/consumer.dart:619:5) consumer.dart:619 #2 _MainScreenState.initState.<anonymous closure>.<anonymous closure> (package:mangayomi/modules/main_view/main_screen.dart:70:13) main_screen.dart:70 #3 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:410:19) timer_impl.dart:410 #4 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:441:5) timer_impl.dart:441 #5 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:194:12) isolate_patch.dart:194 ```
This commit is contained in:
parent
6d99d9a690
commit
b5d65168fb
1 changed files with 42 additions and 17 deletions
|
|
@ -38,6 +38,8 @@ class MainScreen extends ConsumerStatefulWidget {
|
|||
}
|
||||
|
||||
class _MainScreenState extends ConsumerState<MainScreen> {
|
||||
Timer? _backupTimer;
|
||||
Timer? _syncTimer;
|
||||
String getHyphenatedUpdatesLabel(String languageCode, String defaultLabel) {
|
||||
switch (languageCode) {
|
||||
case 'de':
|
||||
|
|
@ -63,26 +65,19 @@ class _MainScreenState extends ConsumerState<MainScreen> {
|
|||
late String defaultLocation = navigationOrder.first;
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.go(defaultLocation);
|
||||
|
||||
Timer.periodic(Duration(minutes: 5), (timer) {
|
||||
ref.read(checkAndBackupProvider);
|
||||
});
|
||||
_backupTimer = Timer.periodic(
|
||||
const Duration(minutes: 5),
|
||||
_onBackupTimerTick,
|
||||
);
|
||||
if (autoSyncFrequency != 0) {
|
||||
final l10n = l10nLocalizations(context)!;
|
||||
Timer.periodic(Duration(seconds: autoSyncFrequency), (timer) {
|
||||
try {
|
||||
ref
|
||||
.read(syncServerProvider(syncId: 1).notifier)
|
||||
.startSync(l10n, true);
|
||||
} catch (e) {
|
||||
botToast(
|
||||
"Failed to sync! Maybe the sync server is down. Restart the app to resume auto sync.",
|
||||
);
|
||||
timer.cancel();
|
||||
}
|
||||
});
|
||||
_syncTimer = Timer.periodic(
|
||||
Duration(seconds: autoSyncFrequency),
|
||||
_onSyncTimerTick,
|
||||
);
|
||||
}
|
||||
|
||||
ref.watch(checkForUpdateProvider(context: context));
|
||||
|
|
@ -90,8 +85,38 @@ class _MainScreenState extends ConsumerState<MainScreen> {
|
|||
ref.watch(fetchAnimeSourcesListProvider(id: null, reFresh: false));
|
||||
ref.watch(fetchNovelSourcesListProvider(id: null, reFresh: false));
|
||||
});
|
||||
}
|
||||
|
||||
super.initState();
|
||||
void _onBackupTimerTick(Timer timer) {
|
||||
if (!mounted) {
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
ref.read(checkAndBackupProvider);
|
||||
}
|
||||
|
||||
void _onSyncTimerTick(Timer timer) {
|
||||
if (!mounted) {
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final l10n = l10nLocalizations(context)!;
|
||||
ref.read(syncServerProvider(syncId: 1).notifier).startSync(l10n, true);
|
||||
} catch (e) {
|
||||
botToast(
|
||||
"Failed to sync! Maybe the sync server is down. "
|
||||
"Restart the app to resume auto sync.",
|
||||
);
|
||||
timer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_backupTimer?.cancel();
|
||||
_syncTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
Loading…
Reference in a new issue