auto_router_extensions.dart 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import 'package:auto_route/auto_route.dart';
  2. import 'package:flutter/material.dart';
  3. import '../componentRouter/component_service_manager.dart';
  4. // 扩展 RootStackRouter 类
  5. extension RootStackRouterExtensions on RootStackRouter {
  6. // SlideFadeTransition 动画效果 (平移渐变动画)
  7. Widget applySlideFadeTransition(
  8. BuildContext context,
  9. Animation<double> animation,
  10. Animation<double> secondaryAnimation,
  11. Widget child,
  12. ) {
  13. return SlideTransition(
  14. position: Tween<Offset>(
  15. begin: const Offset(1.0, 0.0),
  16. end: Offset.zero,
  17. ).animate(animation),
  18. child: FadeTransition(
  19. opacity: animation,
  20. child: child,
  21. ),
  22. );
  23. }
  24. // SlideTransition 动画效果 (平移动画)
  25. Widget applySlideTransition(
  26. BuildContext context,
  27. Animation<double> animation,
  28. Animation<double> secondaryAnimation,
  29. Widget child,
  30. ) {
  31. return SlideTransition(
  32. position: Tween<Offset>(
  33. begin: const Offset(1.0, 0.0),
  34. end: Offset.zero,
  35. ).animate(animation),
  36. child: child,
  37. );
  38. }
  39. }
  40. //获取宿主的全局 AppRouter 对象,用于任意地方使用
  41. extension AppRouterExtension on Object {
  42. RootStackRouter get appRouter => ComponentServiceManager().appService.getAppRouter();
  43. }
  44. //定义一个全局函数来获取 appRouter
  45. RootStackRouter get appRouter => ComponentServiceManager().appService.getAppRouter();