ix_app_bar.dart 2.2 KB

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