ix_app_bar.dart 2.1 KB

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