import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:keyboard/base/base_page.dart'; import 'package:keyboard/module/keyboard_setting/keyboard_setting_controller.dart'; import 'package:keyboard/resource/string.gen.dart'; import '../../resource/assets.gen.dart'; import '../../router/app_pages.dart'; class KeyboardSettingPage extends BasePage { const KeyboardSettingPage({super.key}); static start() { Get.toNamed(RoutePath.keyboardSetting); } @override Color backgroundColor() { return Color(0xFFF6F5FA); } @override bool immersive() => false; @override Widget buildBody(BuildContext context) { return Scaffold( backgroundColor: Colors.transparent, appBar: AppBar( backgroundColor: Colors.transparent, // 16.w间距+24.w图标宽度 leadingWidth: 40.w, leading: Padding( padding: EdgeInsets.only(left: 16.w), child: GestureDetector( onTap: () { controller.backClick(); }, child: Assets.images.iconMineBackArrow.image( width: 24.w, height: 24.h, ), ), ), centerTitle: true, title: Text( StringName.keyboardSetting, textAlign: TextAlign.center, style: TextStyle( color: Colors.black, fontSize: 17.sp, fontWeight: FontWeight.w500, height: 1.18.h, ), ), ), body: Container( color: Colors.white, margin: EdgeInsets.symmetric(horizontal: 16.w), padding: EdgeInsets.symmetric(horizontal: 16.w), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ _buildSwitchTile( title: StringName.directSend, desc: StringName.directSendDesc, value: controller.directSend, onChanged: (value) { controller.toggleDirectSend(value); }, ), _buildSwitchTile( title: StringName.openFloat, desc: StringName.openFloatDesc, value: controller.enableFloatingWindow, onChanged: (value) { controller.enableFloatingWindow.value = value; if (!value) { controller.autoOpenFloatingWindow.value = false; } }, ), Obx( () => _buildSwitchTile( title: StringName.autoOpenFloat, desc: StringName.autoOpenFloatDesc, value: controller.autoOpenFloatingWindow, enabled: controller.enableFloatingWindow.value, onChanged: (value) { controller.autoOpenFloatingWindow.value = value; }, ), ), ], ), ), ); } /// 构建带有开关的列表项 Widget _buildSwitchTile({ required String title, required String desc, required RxBool value, required Function(bool) onChanged, // 切换事件 bool enabled = true, // 是否可用 }) { return Obx( () => Opacity( opacity: enabled ? 1.0 : 0.5, // 如果不可用,则降低透明度 child: ListTile( contentPadding: EdgeInsets.only(left: 16.w), // 左边距 title: Text(title), subtitle: Text(desc), trailing: Switch( value: value.value, onChanged: enabled ? onChanged : null, // 如果不可用,则禁用开关 ), ), ), ); } }