From f7c5a509a35cd21d771420adb933cbb81e0da90f Mon Sep 17 00:00:00 2001 From: tanlongsheng <252620078@qq.com> Date: Tue, 18 Nov 2025 16:34:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=BE=E5=A4=87=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/eq_settings_controller.dart | 14 +- .../views/widgets/row_radio_widget.dart | 187 ++++++++++++++++++ 2 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 lib/modules/eq_settings/views/widgets/row_radio_widget.dart diff --git a/lib/modules/eq_settings/controllers/eq_settings_controller.dart b/lib/modules/eq_settings/controllers/eq_settings_controller.dart index a0857a5a1..66fef8720 100644 --- a/lib/modules/eq_settings/controllers/eq_settings_controller.dart +++ b/lib/modules/eq_settings/controllers/eq_settings_controller.dart @@ -5,6 +5,7 @@ import '../../../core/utils/logger.dart'; import '../../../routes/app_routes.dart'; import '../views/widgets/row_confirm_widget.dart'; import '../views/widgets/row_input_widget.dart'; +import '../views/widgets/row_radio_widget.dart'; class EqSettingsController extends GetxController { final RxList uiList = [ @@ -28,10 +29,16 @@ class EqSettingsController extends GetxController { }, }, { - 'type': 'input', + 'type': 'radio', 'name': '工作模式', - 'value': '', - 'onCallback': () {}, + 'value': '1', + 'options': [ + {'label': '游戏模式', 'value': '1'}, + {'label': '娱乐模式', 'value': '2'}, + ], + 'onCallback': (String value) { + Logger.d('radio', '工作模式:$value'); + }, }, { 'type': 'switch', @@ -78,6 +85,7 @@ class EqSettingsController extends GetxController { Widget getTemplate(Map data) { return switch (data['type']) { 'input' => RowInputWidget(data), + 'radio' => RowRadioWidget(data), 'confirm' => RowConfirmWidget(data), _ => const SizedBox.shrink(), }; diff --git a/lib/modules/eq_settings/views/widgets/row_radio_widget.dart b/lib/modules/eq_settings/views/widgets/row_radio_widget.dart new file mode 100644 index 000000000..6dbfd46f1 --- /dev/null +++ b/lib/modules/eq_settings/views/widgets/row_radio_widget.dart @@ -0,0 +1,187 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; + +class RowRadioWidget extends StatefulWidget { + final Map templateData; + + const RowRadioWidget(this.templateData, {super.key}); + + @override + State createState() => _RowRadioWidgetState(); +} + +class _RowRadioWidgetState extends State { + Map get _templateData => widget.templateData; + + String _label = ''; + + @override + void initState() { + super.initState(); + _label = _templateData['options'].firstWhere( + (option) => option['value'] == _templateData['value'], + orElse: () => {'label': ''}, + )['label']; + } + + @override + Widget build(BuildContext context) { + final isDarkMode = Theme.of(context).brightness == Brightness.dark; + + return GestureDetector( + onTap: () => _radioDialog(isDarkMode), + behavior: HitTestBehavior.translucent, + child: Padding( + padding: EdgeInsets.fromLTRB(10.w, 10.w, 0, 10.w), + child: Row( + children: [ + Expanded( + child: Text( + _templateData['name'], + style: TextStyle( + fontSize: 14.sp, + color: isDarkMode ? Colors.white : Colors.black, + ), + ), + ), + Text( + _label, + style: TextStyle( + fontSize: 12.sp, + color: isDarkMode ? Colors.white : Colors.grey, + ), + ), + Icon( + Icons.chevron_right, + size: 26.w, + color: Colors.blue, + ), + ], + ), + ), + ); + } + + void _radioDialog(bool isDarkMode) { + Get.dialog( + Dialog( + backgroundColor: isDarkMode ? Colors.grey[900] : Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16.r), + ), + child: Padding( + padding: EdgeInsets.all(12.w), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + _templateData['name'], + style: TextStyle( + fontSize: 18.sp, + fontWeight: FontWeight.w600, + color: isDarkMode ? Colors.white : Colors.black87, + ), + ), + SizedBox(height: 16.h), + Container( + constraints: BoxConstraints(maxHeight: 0.5.sh), + child: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + children: _templateData['options'] + .map((option) => _item(isDarkMode, option)) + .toList(), + ), + ), + ), + SizedBox(height: 16.h), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + TextButton( + onPressed: () => Get.back(), + child: Text( + 'cancel'.tr, // 取消 + style: TextStyle( + color: isDarkMode ? Colors.white70 : Colors.black54, + ), + ), + ), + ], + ), + ], + ), + ), + ), + ); + } + + Widget _item(bool isDarkMode, Map option) { + return GestureDetector( + onTap: () { + setState(() { + _label = option['label']; + }); + _templateData['value'] = option['value']; + _templateData['onCallback'](option['value']); + Get.back(); + }, + child: Container( + margin: EdgeInsets.only(bottom: 10.h), + padding: EdgeInsets.all(10.w), + decoration: BoxDecoration( + color: _templateData['value'] == option['value'] + ? (isDarkMode + ? Colors.teal[900]!.withValues(alpha: 0.3) + : Colors.teal[50]!) + : (isDarkMode + ? Colors.white.withValues(alpha: 0.05) + : Colors.grey[100]!), + borderRadius: BorderRadius.circular(12.r), + border: Border.all( + color: _templateData['value'] == option['value'] + ? (isDarkMode ? Colors.teal[300]! : Colors.teal[600]!) + : Colors.transparent, + width: 1, + ), + ), + child: Row( + children: [ + Expanded( + child: Text( + option['label'], + style: TextStyle( + fontSize: 16.sp, + fontWeight: FontWeight.w500, + color: isDarkMode ? Colors.white : Colors.black87, + ), + overflow: TextOverflow.ellipsis, + ), + ), + Container( + width: 24.w, + height: 24.w, + decoration: BoxDecoration( + color: _templateData['value'] == option['value'] + ? (isDarkMode ? Colors.teal[300] : Colors.teal[600]) + : (isDarkMode + ? Colors.white.withValues(alpha: 0.1) + : Colors.grey[300]), + shape: BoxShape.circle, + ), + child: _templateData['value'] == option['value'] + ? Icon( + Icons.check, + size: 16.w, + color: Colors.white, + ) + : null, + ), + ], + ), + ), + ); + } +}