ios_debug_info_tile.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import 'package:flutter/material.dart';
  2. import 'package:hooks_riverpod/hooks_riverpod.dart';
  3. import 'package:immich_mobile/extensions/build_context_extensions.dart';
  4. import 'package:immich_mobile/modules/backup/providers/ios_background_settings.provider.dart';
  5. import 'package:intl/intl.dart';
  6. /// This is a simple debug widget which should be removed later on when we are
  7. /// more confident about background sync
  8. class IosDebugInfoTile extends HookConsumerWidget {
  9. final IOSBackgroundSettings settings;
  10. const IosDebugInfoTile({
  11. super.key,
  12. required this.settings,
  13. });
  14. @override
  15. Widget build(BuildContext context, WidgetRef ref) {
  16. final fetch = settings.timeOfLastFetch;
  17. final processing = settings.timeOfLastProcessing;
  18. final processes = settings.numberOfBackgroundTasksQueued;
  19. final processOrProcesses = processes == 1 ? 'process' : 'processes';
  20. final numberOrZero = processes == 0 ? 'No' : processes.toString();
  21. final title = '$numberOrZero background $processOrProcesses queued';
  22. final df = DateFormat.yMd().add_jm();
  23. final String subtitle;
  24. if (fetch == null && processing == null) {
  25. subtitle = 'No background sync job has run yet';
  26. } else if (fetch != null && processing == null) {
  27. subtitle = 'Fetch ran ${df.format(fetch)}';
  28. } else if (processing != null && fetch == null) {
  29. subtitle = 'Processing ran ${df.format(processing)}';
  30. } else {
  31. final fetchOrProcessing =
  32. fetch!.isAfter(processing!) ? fetch : processing;
  33. subtitle = 'Last sync ${df.format(fetchOrProcessing)}';
  34. }
  35. return ListTile(
  36. key: ValueKey(title),
  37. title: Text(
  38. title,
  39. style: TextStyle(
  40. fontWeight: FontWeight.bold,
  41. fontSize: 14,
  42. color: context.primaryColor,
  43. ),
  44. ),
  45. subtitle: Text(
  46. subtitle,
  47. style: const TextStyle(
  48. fontSize: 14,
  49. ),
  50. ),
  51. leading: Icon(
  52. Icons.bug_report,
  53. color: context.primaryColor,
  54. ),
  55. );
  56. }
  57. }