ix_app_bar.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 AppBar(
  35. backgroundColor:
  36. backgroundColor ?? Get.reactiveTheme.scaffoldBackgroundColor,
  37. elevation: 0,
  38. centerTitle: true,
  39. toolbarHeight: 60,
  40. scrolledUnderElevation: 0,
  41. leading: showBackButton
  42. ? ClickOpacity(
  43. onTap: onBackPressed ?? () => Get.back(),
  44. child: Transform.rotate(
  45. angle: LocalizationService.isRTL() ? pi : 0, // 180度 = π 弧度
  46. child: Icon(
  47. backIcon ?? Icons.arrow_back,
  48. color: Get.reactiveTheme.textTheme.bodyLarge!.color,
  49. size: 24,
  50. ),
  51. ),
  52. )
  53. : null,
  54. title: Text(
  55. title,
  56. style: TextStyle(
  57. color: Get.reactiveTheme.textTheme.bodyLarge!.color,
  58. fontSize: titleSize,
  59. fontWeight: titleWeight,
  60. ),
  61. ),
  62. actions: actions,
  63. );
  64. }
  65. @override
  66. Size get preferredSize => const Size.fromHeight(60);
  67. }