|
|
@ -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), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|