routes.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. selIndex: 0,
  14. ),
  15. };
  16. Routes.pushNamed(BuildContext context, String url, dynamic params) {
  17. _getPage(context, url, params: params);
  18. }
  19. Routes.pushNamedNoParams(BuildContext context, String url) {
  20. _getPage(context, url);
  21. }
  22. /// 比如splashPage跳转
  23. Routes.popAndPushNamed(BuildContext context, String url) {
  24. Navigator.of(context).popAndPushNamed(url);
  25. }
  26. _getPage(BuildContext context, String url, {dynamic params}) {
  27. if (url.startsWith('https://') || url.startsWith('http://')) {
  28. // return WebViewPage(url, params: params);
  29. } else {
  30. if (params == null) {
  31. Navigator.pushNamed(context, url);
  32. } else {
  33. Navigator.pushNamed(context, url, arguments: params);
  34. }
  35. }
  36. }
  37. }