routes.dart 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'package:get/get.dart';
  2. import 'package:get_demo/pages/home/home_binding.dart';
  3. import 'package:get_demo/pages/home/home_view.dart';
  4. import 'package:get_demo/pages/second/second_binding.dart';
  5. import 'package:get_demo/pages/second/second_view.dart';
  6. /// Description: routes
  7. /// Time : 05/06/2023 Saturday
  8. /// Author : liuyuqi.gov@msn.cn
  9. class Routes {
  10. static const String home = "/home";
  11. static const String second = "/second";
  12. static final routes = [
  13. GetPage(name: home, page: () => const HomeView(), binding: HomeBinding()),
  14. GetPage(
  15. name: second, page: () => const SecondView(), binding: SecondBinding())
  16. ];
  17. static Future<T> push<T>(String routeName, {params}) async {
  18. Map<String, dynamic> map = {};
  19. map.putIfAbsent("obj", () => params);
  20. return await Get.toNamed(routeName, arguments: map);
  21. }
  22. static Future<T> replacePush<T>(String routeName, {params}) async {
  23. Map<String, dynamic> map = {};
  24. map.putIfAbsent("obj", () => params);
  25. return await Get.offNamed(routeName, arguments: map);
  26. }
  27. static Future<T> off<T>(String routeName, {params}) async {
  28. Map<String, dynamic> map = {};
  29. map.putIfAbsent("obj", () => params);
  30. return await Get.off(routeName, arguments: map);
  31. }
  32. static Future<T> replaceAllPush<T>(String routeName, {params}) async {
  33. Map<String, dynamic> map = {};
  34. map.putIfAbsent("obj", () => params);
  35. return await Get.offAllNamed(routeName, arguments: map);
  36. }
  37. static pop<T>({result}) {
  38. return Get.back(result: result);
  39. }
  40. static getParams<T>() {
  41. return Get.arguments == null ? null : Get.arguments['obj'];
  42. }
  43. }