ix_app_bar.dart 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:get/get.dart';
  4. import 'package:nomo/utils/misc.dart';
  5. import '../../config/translations/localization_service.dart';
  6. import '../../config/theme/theme_extensions/theme_extension.dart';
  7. import 'dart:math';
  8. import '../constants/iconfont/iconfont.dart';
  9. import 'click_opacity.dart';
  10. class IXAppBar extends StatelessWidget implements PreferredSizeWidget {
  11. final String title;
  12. final bool showBackButton;
  13. final VoidCallback? onBackPressed;
  14. final List<Widget>? actions;
  15. final Color? backgroundColor;
  16. final Color? titleColor;
  17. final Color? backIconColor;
  18. final double? titleSize;
  19. final IconData? backIcon;
  20. final FontWeight? titleWeight;
  21. const IXAppBar({
  22. super.key,
  23. required this.title,
  24. this.showBackButton = true,
  25. this.onBackPressed,
  26. this.actions,
  27. this.backgroundColor,
  28. this.titleColor,
  29. this.backIconColor,
  30. this.titleSize = 20,
  31. this.titleWeight = FontWeight.w600,
  32. this.backIcon,
  33. });
  34. @override
  35. Widget build(BuildContext context) {
  36. // 使用 Obx 包装 AppBar 以响应主题变化
  37. return AppBar(
  38. backgroundColor:
  39. backgroundColor ?? Get.reactiveTheme.scaffoldBackgroundColor,
  40. elevation: 0,
  41. centerTitle: true,
  42. toolbarHeight: isDesktop ? 40 : 60, // 配置桌面版本的AppBar高度
  43. scrolledUnderElevation: 0,
  44. leading: showBackButton
  45. ? ClickOpacity(
  46. onTap: onBackPressed ?? () => Get.back(),
  47. child: Transform.rotate(
  48. angle: LocalizationService.isRTL() ? pi : 0, // 180度 = π 弧度
  49. child: Icon(
  50. backIcon ?? IconFont.icon01,
  51. color: Get.reactiveTheme.textTheme.bodyLarge!.color,
  52. size: 24.w,
  53. ),
  54. ),
  55. )
  56. : null,
  57. title: Text(
  58. title,
  59. style: TextStyle(
  60. color: Get.reactiveTheme.textTheme.bodyLarge!.color,
  61. fontSize: isDesktop ? 16 : titleSize,
  62. fontWeight: titleWeight,
  63. ),
  64. ),
  65. actions: actions,
  66. );
  67. }
  68. @override
  69. Size get preferredSize => Size.fromHeight(isDesktop ? 40 : 60); // 配置桌面版本的AppBar高度
  70. }