goto_helper.dart 996 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'package:get/get.dart';
  4. import 'package:vitalapp/pages/redirect/redirect.dart';
  5. import 'package:vitalapp/routes/nav_ids.dart';
  6. import 'package:vitalapp/routes/routes.dart';
  7. abstract class NavGotoHelper {
  8. static Timer? _timer;
  9. static void goto(String name, [Map? patientInfo]) {
  10. print("❤goto: $name");
  11. if (_timer != null) {
  12. _timer!.cancel();
  13. _timer = null;
  14. }
  15. _timer = Timer.periodic(const Duration(milliseconds: 100), (timer) {
  16. _check(name, patientInfo);
  17. });
  18. }
  19. static void _check(String name, [Map? patientInfo]) {
  20. if (RedirectPage.isBusy) {
  21. return;
  22. }
  23. _timer!.cancel();
  24. _timer = null;
  25. print("GOTO $name");
  26. Routes.parameters["name"] = name;
  27. if (patientInfo != null) {
  28. Routes.parameters["patientInfo"] = jsonEncode(patientInfo);
  29. } else {
  30. Routes.parameters["patientInfo"] = null;
  31. }
  32. Get.offAllNamed('/redirect', id: NavIds.HOME);
  33. }
  34. }