refactor: improvements
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -68,7 +68,7 @@ class _WasOfflineNotifier extends Notifier<bool> {
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (_, __) {},
|
||||
error: (error, stackTrace) {},
|
||||
);
|
||||
});
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user