Browse Source

都改成单选

master
hejl 4 weeks ago
parent
commit
ecde205e00
  1. 116
      win_text_editor/lib/modules/call_function/widgets/call_function_right_side.dart
  2. 118
      win_text_editor/lib/modules/memory_table/widgets/memory_table_right_side.dart
  3. 114
      win_text_editor/lib/modules/uft_component/widgets/uft_component_right_side.dart

116
win_text_editor/lib/modules/call_function/widgets/call_function_right_side.dart

@ -1,20 +1,24 @@
// call_function_right_side.dart
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:win_text_editor/modules/call_function/controllers/call_function_controller.dart'; import 'package:win_text_editor/modules/call_function/controllers/call_function_controller.dart';
import 'package:win_text_editor/shared/components/my_checkbox.dart'; import 'package:win_text_editor/shared/components/code_generation_components.dart';
class CallFunctionRightSide extends StatefulWidget { class CallFunctionRightSide extends StatefulWidget {
final CallFunctionController controller; final CallFunctionController controller;
final TextEditingController codeController; final TextEditingController codeController;
const CallFunctionRightSide({super.key, required this.controller, required this.codeController}); const CallFunctionRightSide({
super.key,
required this.controller,
required this.codeController,
});
@override @override
State<CallFunctionRightSide> createState() => _CallFunctionRightSideState(); State<CallFunctionRightSide> createState() => _CallFunctionRightSideState();
} }
class _CallFunctionRightSideState extends State<CallFunctionRightSide> { class _CallFunctionRightSideState extends State<CallFunctionRightSide> {
final List<String> _selectedOperations = []; String? _selectedOperation;
@override @override
void initState() { void initState() {
@ -30,100 +34,32 @@ class _CallFunctionRightSideState extends State<CallFunctionRightSide> {
} }
void _updateDisplay() { void _updateDisplay() {
widget.codeController.text = widget.controller.genCodeString(_selectedOperations)!; if (_selectedOperation != null) {
} widget.codeController.text =
widget.controller.genCodeString([_selectedOperation!]) ?? '';
@override } else {
Widget build(BuildContext context) { widget.codeController.text = '';
return Column(
children: [
_buildCheckboxSection(),
Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('生成代码:', style: TextStyle(fontWeight: FontWeight.bold)),
IconButton(
icon: const Icon(Icons.content_copy, size: 20),
tooltip: '复制代码',
onPressed: () {
if (widget.codeController.text.isNotEmpty) {
Clipboard.setData(ClipboardData(text: widget.codeController.text));
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('已复制到剪贴板')));
} }
},
),
],
),
),
Flexible(child: _buildCodeEditor()),
],
);
}
Widget _buildCheckboxSection() {
final operations = ['普通调用', '事务调用'];
return SizedBox(
width: double.infinity,
child: Card(
child: Padding(
padding: const EdgeInsets.only(left: 8, top: 4, bottom: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Wrap(
spacing: 8,
runSpacing: 8,
children: operations.map((op) => _buildCheckbox(op)).toList(),
),
],
),
),
),
);
} }
Widget _buildCheckbox(String label) => MyCheckbox( void _selectOperation(String? operation) {
title: label,
value: _selectedOperations.contains(label),
onChanged: (bool? value) => _toggleOperation(label, value),
);
void _toggleOperation(String operation, bool? value) {
setState(() { setState(() {
if (value == true) { _selectedOperation = operation;
_selectedOperations.add(operation);
} else {
_selectedOperations.remove(operation);
}
_updateDisplay(); _updateDisplay();
}); });
} }
Widget _buildCodeEditor() { @override
return Card( Widget build(BuildContext context) {
child: Padding( final operations = ['普通调用', '事务调用'];
padding: const EdgeInsets.all(8),
child: Container( return CodeGenerationSection(
decoration: BoxDecoration( title: '生成代码',
border: Border.all(color: Colors.grey), codeController: widget.codeController,
borderRadius: BorderRadius.circular(4), child: OperationRadioSection(
), operations: operations,
child: TextField( selectedOperation: _selectedOperation,
controller: widget.codeController, onOperationSelected: _selectOperation,
maxLines: null,
expands: true,
decoration: const InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.all(8),
),
style: const TextStyle(fontFamily: 'monospace', color: Colors.blueAccent),
),
),
), ),
); );
} }

118
win_text_editor/lib/modules/memory_table/widgets/memory_table_right_side.dart

@ -1,19 +1,25 @@
// memory_table_right_side.dart
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:win_text_editor/modules/memory_table/controllers/memory_table_controller.dart'; import 'package:win_text_editor/modules/memory_table/controllers/memory_table_controller.dart';
import 'package:win_text_editor/shared/components/code_generation_components.dart';
class MemoryTableRightSide extends StatefulWidget { class MemoryTableRightSide extends StatefulWidget {
final MemoryTableController controller; final MemoryTableController controller;
final TextEditingController codeController; final TextEditingController codeController;
const MemoryTableRightSide({super.key, required this.controller, required this.codeController}); const MemoryTableRightSide({
super.key,
required this.controller,
required this.codeController,
});
@override @override
State<MemoryTableRightSide> createState() => _MemoryTableRightSideState(); State<MemoryTableRightSide> createState() => _MemoryTableRightSideState();
} }
class _MemoryTableRightSideState extends State<MemoryTableRightSide> { class _MemoryTableRightSideState extends State<MemoryTableRightSide> {
String? _selectedOperation; // String? _selectedOperation;
@override @override
void initState() { void initState() {
@ -30,13 +36,14 @@ class _MemoryTableRightSideState extends State<MemoryTableRightSide> {
void _updateDisplay() { void _updateDisplay() {
if (_selectedOperation != null) { if (_selectedOperation != null) {
widget.codeController.text = widget.controller.genCodeString([_selectedOperation!]) ?? ''; widget.codeController.text =
widget.controller.genCodeString([_selectedOperation!]) ?? '';
} else { } else {
widget.codeController.text = ''; widget.codeController.text = '';
} }
} }
void _selectOperation(String operation) { void _selectOperation(String? operation) {
setState(() { setState(() {
_selectedOperation = operation; _selectedOperation = operation;
_updateDisplay(); _updateDisplay();
@ -45,100 +52,17 @@ class _MemoryTableRightSideState extends State<MemoryTableRightSide> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( final operations = [
children: [ '获取记录', '获取记录数', '插入记录', '修改记录', '删除记录', '遍历记录'
_buildRadioSection(), ];
Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('生成代码:', style: TextStyle(fontWeight: FontWeight.bold)),
IconButton(
icon: const Icon(Icons.content_copy, size: 20),
tooltip: '复制代码',
onPressed: () {
if (widget.codeController.text.isNotEmpty) {
Clipboard.setData(ClipboardData(text: widget.codeController.text));
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('已复制到剪贴板')));
}
},
),
],
),
),
Flexible(child: _buildCodeEditor()),
],
);
}
Widget _buildRadioSection() {
final operations = ['获取记录', '获取记录数', '插入记录', '修改记录', '删除记录', '遍历记录'];
return SizedBox(
width: double.infinity,
child: Card(
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Wrap(
spacing: 16, //
runSpacing: 8, //
children: operations.map((op) => _buildRadioItem(op)).toList(),
),
],
),
),
),
);
}
Widget _buildRadioItem(String label) {
return Row(
mainAxisSize: MainAxisSize.min, // 使Row只占用必要宽度
children: [
Transform.scale(
scale: 0.75,
child: Radio<String>(
value: label,
groupValue: _selectedOperation,
onChanged: (String? value) {
if (value != null) {
_selectOperation(value);
}
},
),
),
const SizedBox(width: 4),
Text(label, style: const TextStyle(fontSize: 14)),
],
);
}
Widget _buildCodeEditor() { return CodeGenerationSection(
return Card( title: '生成代码',
child: Padding( codeController: widget.codeController,
padding: const EdgeInsets.all(8), child: OperationRadioSection(
child: Container( operations: operations,
decoration: BoxDecoration( selectedOperation: _selectedOperation,
border: Border.all(color: Colors.grey), onOperationSelected: _selectOperation,
borderRadius: BorderRadius.circular(4),
),
child: TextField(
controller: widget.codeController,
maxLines: null,
expands: true,
decoration: const InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.all(8),
),
style: const TextStyle(fontFamily: 'monospace', color: Colors.blueAccent),
),
),
), ),
); );
} }

114
win_text_editor/lib/modules/uft_component/widgets/uft_component_right_side.dart

@ -1,20 +1,24 @@
// uft_component_right_side.dart
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:win_text_editor/modules/uft_component/controllers/uft_component_controller.dart'; import 'package:win_text_editor/modules/uft_component/controllers/uft_component_controller.dart';
import 'package:win_text_editor/shared/components/my_checkbox.dart'; import 'package:win_text_editor/shared/components/code_generation_components.dart';
class UftComponentRightSide extends StatefulWidget { class UftComponentRightSide extends StatefulWidget {
final UftComponentController controller; final UftComponentController controller;
final TextEditingController codeController; final TextEditingController codeController;
const UftComponentRightSide({super.key, required this.controller, required this.codeController}); const UftComponentRightSide({
super.key,
required this.controller,
required this.codeController,
});
@override @override
State<UftComponentRightSide> createState() => _UftComponentRightSideState(); State<UftComponentRightSide> createState() => _UftComponentRightSideState();
} }
class _UftComponentRightSideState extends State<UftComponentRightSide> { class _UftComponentRightSideState extends State<UftComponentRightSide> {
final List<String> _selectedOperations = []; String? _selectedOperation;
@override @override
void initState() { void initState() {
@ -30,100 +34,34 @@ class _UftComponentRightSideState extends State<UftComponentRightSide> {
} }
void _updateDisplay() { void _updateDisplay() {
widget.codeController.text = widget.controller.genCodeString(_selectedOperations)!; if (_selectedOperation != null) {
widget.codeController.text =
widget.controller.genCodeString([_selectedOperation!]) ?? '';
} else {
widget.codeController.text = '';
}
} }
void _toggleOperation(String operation, bool? value) { void _selectOperation(String? operation) {
setState(() { setState(() {
if (value == true) { _selectedOperation = operation;
_selectedOperations.add(operation);
} else {
_selectedOperations.remove(operation);
}
_updateDisplay(); _updateDisplay();
}); });
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( final operations = [
children: [ '插入组件', '修改组件', '获取组件', '遍历组件', '组件大小', '尾部插入组件'
_buildCheckboxSection(), ];
Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('生成代码:', style: TextStyle(fontWeight: FontWeight.bold)),
IconButton(
icon: const Icon(Icons.content_copy, size: 20),
tooltip: '复制代码',
onPressed: () {
if (widget.codeController.text.isNotEmpty) {
Clipboard.setData(ClipboardData(text: widget.codeController.text));
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('已复制到剪贴板')));
}
},
),
],
),
),
Flexible(child: _buildCodeEditor()),
],
);
}
Widget _buildCheckboxSection() {
final operations = ['插入组件', '修改组件', '获取组件', '遍历组件', '组件大小', '尾部插入组件'];
return SizedBox(
width: double.infinity,
child: Card(
child: Padding(
padding: const EdgeInsets.only(left: 8, top: 4, bottom: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Wrap(
spacing: 8,
runSpacing: 8,
children: operations.map((op) => _buildCheckbox(op)).toList(),
),
],
),
),
),
);
}
Widget _buildCheckbox(String label) => MyCheckbox(
title: label,
value: _selectedOperations.contains(label),
onChanged: (bool? value) => _toggleOperation(label, value),
);
Widget _buildCodeEditor() { return CodeGenerationSection(
return Card( title: '生成代码',
child: Padding( codeController: widget.codeController,
padding: const EdgeInsets.all(8), child: OperationRadioSection(
child: Container( operations: operations,
decoration: BoxDecoration( selectedOperation: _selectedOperation,
border: Border.all(color: Colors.grey), onOperationSelected: _selectOperation,
borderRadius: BorderRadius.circular(4),
),
child: TextField(
controller: widget.codeController,
maxLines: null,
expands: true,
decoration: const InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.all(8),
),
style: const TextStyle(fontFamily: 'monospace', color: Colors.blueAccent),
),
),
), ),
); );
} }

Loading…
Cancel
Save