refactor: improvements

This commit is contained in:
cogwheel0
2025-09-24 10:52:15 +05:30
parent f6a1b6123b
commit b8c024d0b0
13 changed files with 294 additions and 132 deletions

View File

@@ -63,7 +63,19 @@ class TaskQueueNotifier extends Notifier<List<OutboundTask>> {
Future<void> _save() async {
try {
final prefs = ref.read(sharedPreferencesProvider);
final raw = state.map((t) => t.toJson()).toList(growable: false);
final retained = [
for (final task in state)
if (task.status == TaskStatus.queued ||
task.status == TaskStatus.running)
task,
];
if (retained.length != state.length) {
// Remove completed entries from state to keep the in-memory queue lean.
state = retained;
}
final raw = retained.map((t) => t.toJson()).toList(growable: false);
await prefs.setString(_prefsKey, jsonEncode(raw));
} catch (e) {
debugPrint('DEBUG: Failed to persist task queue: $e');

View File

@@ -51,15 +51,14 @@ class _ImprovedLoadingStateState extends State<ImprovedLoadingState>
);
_animationController.forward();
// Announce loading state for screen readers
if (widget.message != null) {
WidgetsBinding.instance.addPostFrameCallback((_) {
SemanticsService.announce(
'Loading: ${widget.message}',
TextDirection.ltr,
);
});
}
// Announce loading state for screen readers using localized messaging.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
final l10n = AppLocalizations.of(context);
final announcement = widget.message ?? l10n?.loadingContent ?? 'Loading';
final direction = Directionality.maybeOf(context) ?? TextDirection.ltr;
SemanticsService.announce(announcement, direction);
});
}
@override

View File

@@ -68,7 +68,7 @@ class _WasOfflineNotifier extends Notifier<bool> {
}
},
loading: () {},
error: (_, __) {},
error: (error, stackTrace) {},
);
});
return false;