nav_bar_config.dart 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. /// 页面覆盖导航栏返回按钮的 Provider。
  4. /// 页面在 build 中设置:`ref.read(pageBackProvider.notifier).state = () => _doPop();`
  5. final pageBackProvider = StateProvider<VoidCallback?>((ref) => null);
  6. /// NavBar 配置——纯数据类,由路由层在 AppScaffold.navConfig 中声明式传入。
  7. ///
  8. /// 不再需要 Provider 中转:AppScaffold 直接消费,同步渲染,无延迟。
  9. class NavBarConfig {
  10. final String title;
  11. final bool showBack;
  12. final bool showRight;
  13. final Widget? rightWidget;
  14. final VoidCallback? onBack;
  15. final IconData? leadingIcon;
  16. const NavBarConfig({
  17. this.title = '',
  18. this.showBack = false,
  19. this.showRight = false,
  20. this.rightWidget,
  21. this.onBack,
  22. this.leadingIcon,
  23. });
  24. /// 根页面默认配置(无返回按钮)
  25. static const home = NavBarConfig(title: '', showBack: false);
  26. static const messages = NavBarConfig(title: '', showBack: false);
  27. static const profile = NavBarConfig(title: '', showBack: false);
  28. }