keyboard_setting_page.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:get/get.dart';
  4. import 'package:keyboard/base/base_page.dart';
  5. import 'package:keyboard/module/keyboard_setting/keyboard_setting_controller.dart';
  6. import 'package:keyboard/resource/string.gen.dart';
  7. import '../../resource/assets.gen.dart';
  8. import '../../router/app_pages.dart';
  9. class KeyboardSettingPage extends BasePage<KeyboardSettingController> {
  10. const KeyboardSettingPage({super.key});
  11. static start() {
  12. Get.toNamed(RoutePath.keyboardSetting);
  13. }
  14. @override
  15. Color backgroundColor() {
  16. return Color(0xFFF6F5FA);
  17. }
  18. @override
  19. bool immersive() => false;
  20. @override
  21. Widget buildBody(BuildContext context) {
  22. return Scaffold(
  23. backgroundColor: Colors.transparent,
  24. appBar: AppBar(
  25. backgroundColor: Colors.transparent,
  26. // 16.w间距+24.w图标宽度
  27. leadingWidth: 40.w,
  28. leading: Padding(
  29. padding: EdgeInsets.only(left: 16.w),
  30. child: GestureDetector(
  31. onTap: () {
  32. controller.backClick();
  33. },
  34. child: Assets.images.iconMineBackArrow.image(
  35. width: 24.w,
  36. height: 24.h,
  37. ),
  38. ),
  39. ),
  40. centerTitle: true,
  41. title: Text(
  42. StringName.keyboardSetting,
  43. textAlign: TextAlign.center,
  44. style: TextStyle(
  45. color: Colors.black,
  46. fontSize: 17.sp,
  47. fontWeight: FontWeight.w500,
  48. height: 1.18.h,
  49. ),
  50. ),
  51. ),
  52. body: Container(
  53. color: Colors.white,
  54. margin: EdgeInsets.symmetric(horizontal: 16.w),
  55. padding: EdgeInsets.symmetric(horizontal: 16.w),
  56. child: Column(
  57. crossAxisAlignment: CrossAxisAlignment.start,
  58. children: [
  59. _buildSwitchTile(
  60. title: StringName.directSend,
  61. desc: StringName.directSendDesc,
  62. value: controller.directSend,
  63. onChanged: (value) {
  64. controller.toggleDirectSend(value);
  65. },
  66. ),
  67. _buildSwitchTile(
  68. title: StringName.openFloat,
  69. desc: StringName.openFloatDesc,
  70. value: controller.enableFloatingWindow,
  71. onChanged: (value) {
  72. controller.enableFloatingWindow.value = value;
  73. if (!value) {
  74. controller.autoOpenFloatingWindow.value = false;
  75. }
  76. },
  77. ),
  78. Obx(
  79. () => _buildSwitchTile(
  80. title: StringName.autoOpenFloat,
  81. desc: StringName.autoOpenFloatDesc,
  82. value: controller.autoOpenFloatingWindow,
  83. enabled: controller.enableFloatingWindow.value,
  84. onChanged: (value) {
  85. controller.autoOpenFloatingWindow.value = value;
  86. },
  87. ),
  88. ),
  89. ],
  90. ),
  91. ),
  92. );
  93. }
  94. /// 构建带有开关的列表项
  95. Widget _buildSwitchTile({
  96. required String title,
  97. required String desc,
  98. required RxBool value,
  99. required Function(bool) onChanged, // 切换事件
  100. bool enabled = true, // 是否可用
  101. }) {
  102. return Obx(
  103. () => Opacity(
  104. opacity: enabled ? 1.0 : 0.5, // 如果不可用,则降低透明度
  105. child: ListTile(
  106. contentPadding: EdgeInsets.only(left: 16.w), // 左边距
  107. title: Text(title),
  108. subtitle: Text(desc),
  109. trailing: Switch(
  110. value: value.value,
  111. onChanged: enabled ? onChanged : null, // 如果不可用,则禁用开关
  112. ),
  113. ),
  114. ),
  115. );
  116. }
  117. }