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 @@ @@ -1,20 +1,24 @@
// call_function_right_side.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/shared/components/my_checkbox.dart';
import 'package:win_text_editor/shared/components/code_generation_components.dart';
class CallFunctionRightSide extends StatefulWidget {
final CallFunctionController controller;
final TextEditingController codeController;
const CallFunctionRightSide({super.key, required this.controller, required this.codeController});
const CallFunctionRightSide({
super.key,
required this.controller,
required this.codeController,
});
@override
State<CallFunctionRightSide> createState() => _CallFunctionRightSideState();
}
class _CallFunctionRightSideState extends State<CallFunctionRightSide> {
final List<String> _selectedOperations = [];
String? _selectedOperation;
@override
void initState() {
@ -30,100 +34,32 @@ class _CallFunctionRightSideState extends State<CallFunctionRightSide> { @@ -30,100 +34,32 @@ class _CallFunctionRightSideState extends State<CallFunctionRightSide> {
}
void _updateDisplay() {
widget.codeController.text = widget.controller.genCodeString(_selectedOperations)!;
}
@override
Widget build(BuildContext context) {
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('已复制到剪贴板')));
if (_selectedOperation != null) {
widget.codeController.text =
widget.controller.genCodeString([_selectedOperation!]) ?? '';
} else {
widget.codeController.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),
);
void _toggleOperation(String operation, bool? value) {
void _selectOperation(String? operation) {
setState(() {
if (value == true) {
_selectedOperations.add(operation);
} else {
_selectedOperations.remove(operation);
}
_selectedOperation = operation;
_updateDisplay();
});
}
Widget _buildCodeEditor() {
return Card(
child: Padding(
padding: const EdgeInsets.all(8),
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
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),
),
),
@override
Widget build(BuildContext context) {
final operations = ['普通调用', '事务调用'];
return CodeGenerationSection(
title: '生成代码',
codeController: widget.codeController,
child: OperationRadioSection(
operations: operations,
selectedOperation: _selectedOperation,
onOperationSelected: _selectOperation,
),
);
}

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

@ -1,19 +1,25 @@ @@ -1,19 +1,25 @@
// memory_table_right_side.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.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 {
final MemoryTableController controller;
final TextEditingController codeController;
const MemoryTableRightSide({super.key, required this.controller, required this.codeController});
const MemoryTableRightSide({
super.key,
required this.controller,
required this.codeController,
});
@override
State<MemoryTableRightSide> createState() => _MemoryTableRightSideState();
}
class _MemoryTableRightSideState extends State<MemoryTableRightSide> {
String? _selectedOperation; //
String? _selectedOperation;
@override
void initState() {
@ -30,13 +36,14 @@ class _MemoryTableRightSideState extends State<MemoryTableRightSide> { @@ -30,13 +36,14 @@ class _MemoryTableRightSideState extends State<MemoryTableRightSide> {
void _updateDisplay() {
if (_selectedOperation != null) {
widget.codeController.text = widget.controller.genCodeString([_selectedOperation!]) ?? '';
widget.codeController.text =
widget.controller.genCodeString([_selectedOperation!]) ?? '';
} else {
widget.codeController.text = '';
}
}
void _selectOperation(String operation) {
void _selectOperation(String? operation) {
setState(() {
_selectedOperation = operation;
_updateDisplay();
@ -45,100 +52,17 @@ class _MemoryTableRightSideState extends State<MemoryTableRightSide> { @@ -45,100 +52,17 @@ class _MemoryTableRightSideState extends State<MemoryTableRightSide> {
@override
Widget build(BuildContext context) {
return Column(
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()),
],
);
}
final operations = [
'获取记录', '获取记录数', '插入记录', '修改记录', '删除记录', '遍历记录'
];
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 Card(
child: Padding(
padding: const EdgeInsets.all(8),
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
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),
),
),
return CodeGenerationSection(
title: '生成代码',
codeController: widget.codeController,
child: OperationRadioSection(
operations: operations,
selectedOperation: _selectedOperation,
onOperationSelected: _selectOperation,
),
);
}

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

@ -1,20 +1,24 @@ @@ -1,20 +1,24 @@
// uft_component_right_side.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/shared/components/my_checkbox.dart';
import 'package:win_text_editor/shared/components/code_generation_components.dart';
class UftComponentRightSide extends StatefulWidget {
final UftComponentController controller;
final TextEditingController codeController;
const UftComponentRightSide({super.key, required this.controller, required this.codeController});
const UftComponentRightSide({
super.key,
required this.controller,
required this.codeController,
});
@override
State<UftComponentRightSide> createState() => _UftComponentRightSideState();
}
class _UftComponentRightSideState extends State<UftComponentRightSide> {
final List<String> _selectedOperations = [];
String? _selectedOperation;
@override
void initState() {
@ -30,100 +34,34 @@ class _UftComponentRightSideState extends State<UftComponentRightSide> { @@ -30,100 +34,34 @@ class _UftComponentRightSideState extends State<UftComponentRightSide> {
}
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(() {
if (value == true) {
_selectedOperations.add(operation);
} else {
_selectedOperations.remove(operation);
}
_selectedOperation = operation;
_updateDisplay();
});
}
@override
Widget build(BuildContext context) {
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 = ['插入组件', '修改组件', '获取组件', '遍历组件', '组件大小', '尾部插入组件'];
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 Card(
child: Padding(
padding: const EdgeInsets.all(8),
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
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),
),
),
return CodeGenerationSection(
title: '生成代码',
codeController: widget.codeController,
child: OperationRadioSection(
operations: operations,
selectedOperation: _selectedOperation,
onOperationSelected: _selectOperation,
),
);
}

Loading…
Cancel
Save