app_shell.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import 'package:flutter/material.dart';
  2. import 'package:go_router/go_router.dart';
  3. import 'package:tdesign_flutter/tdesign_flutter.dart';
  4. class AppShell extends StatelessWidget {
  5. final Widget child;
  6. const AppShell({super.key, required this.child});
  7. @override
  8. Widget build(BuildContext context) {
  9. final location = GoRouterState.of(context).uri.toString();
  10. return Scaffold(
  11. body: child,
  12. bottomNavigationBar: TDBottomTabBar(
  13. TDBottomTabBarBasicType.iconText,
  14. currentIndex: _currentIndex(location),
  15. navigationTabs: [
  16. TDBottomTabBarTabConfig(
  17. selectedIcon:
  18. const Icon(Icons.notifications, color: Color(0xFF00ABF3)),
  19. unselectedIcon:
  20. const Icon(Icons.notifications_outlined, color: Color(0xFF999999)),
  21. tabText: '消息',
  22. onTap: () => context.go('/messages'),
  23. ),
  24. TDBottomTabBarTabConfig(
  25. selectedIcon:
  26. const Icon(Icons.dashboard, color: Color(0xFF00ABF3)),
  27. unselectedIcon:
  28. const Icon(Icons.dashboard_outlined, color: Color(0xFF999999)),
  29. tabText: '工作台',
  30. onTap: () => context.go('/'),
  31. ),
  32. TDBottomTabBarTabConfig(
  33. selectedIcon:
  34. const Icon(Icons.person, color: Color(0xFF00ABF3)),
  35. unselectedIcon:
  36. const Icon(Icons.person_outline, color: Color(0xFF999999)),
  37. tabText: '我的',
  38. onTap: () => context.go('/profile'),
  39. ),
  40. ],
  41. ),
  42. );
  43. }
  44. int _currentIndex(String location) {
  45. if (location.startsWith('/messages')) return 0;
  46. if (location.startsWith('/profile')) return 2;
  47. return 1;
  48. }
  49. }