routes.dart 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import 'package:douyin_demo/pages/home_page.dart';
  2. import 'package:douyin_demo/pages/recommend_page.dart';
  3. import 'package:douyin_demo/pages/splash_page.dart';
  4. import 'package:flutter/material.dart';
  5. class Routes {
  6. static const home = 'app://';
  7. static const splash = 'app://splash';
  8. static const recommend = "app://recommend";
  9. static define() => {
  10. home: (context) => const HomePage(),
  11. splash: (context) => const SplashPage(),
  12. recommend: (context) => const RecommendPage(),
  13. };
  14. Routes.pushNamed(BuildContext context, String url, dynamic params) {
  15. _getPage(context, url, params: params);
  16. }
  17. Routes.pushNamedNoParams(BuildContext context, String url) {
  18. _getPage(context, url);
  19. }
  20. /// 比如splashPage跳转
  21. Routes.popAndPushNamed(BuildContext context, String url) {
  22. Navigator.of(context).popAndPushNamed(url);
  23. }
  24. _getPage(BuildContext context, String url, {dynamic params}) {
  25. if (url.startsWith('https://') || url.startsWith('http://')) {
  26. // return WebViewPage(url, params: params);
  27. } else {
  28. if (params == null) {
  29. Navigator.pushNamed(context, url);
  30. } else {
  31. Navigator.pushNamed(context, url, arguments: params);
  32. }
  33. }
  34. }
  35. }