goto_helper.dart 992 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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.offNamed('/redirect', id: NavIds.HOME);
  33. }
  34. }