123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import 'package:flutter/material.dart';
- import 'package:o2oa_all_platform/common/index.dart';
- typedef MindMapTextEditDone = Function(String text);
- class MindMapTextEdit extends StatefulWidget {
- final double inputLeft;
- final double inputTop;
- final double inputWidth;
- final double inputHeight;
- final Color inputFillColor;
- final bool autoFocus;
- final TextSpan? textSpan;
- final MindMapTextEditDone textEditDone;
- const MindMapTextEdit(
- {Key? key,
- required this.inputLeft,
- required this.inputTop,
- required this.inputWidth,
- required this.inputHeight,
- required this.inputFillColor,
- required this.autoFocus,
- required this.textSpan,
- required this.textEditDone})
- : super(key: key);
- @override
- MindMapState createState() {
- return MindMapState();
- }
- }
- class MindMapState extends State<MindMapTextEdit> {
- late TextEditingController _controller;
- late FocusNode _textNode;
- @override
- void initState() {
- super.initState();
- _controller = TextEditingController();
- _textNode = FocusNode();
- }
- @override
- Widget build(BuildContext context) {
- final text = widget.textSpan?.text ?? ' ';
- _controller.text = text;
- _controller.selection = TextSelection(baseOffset: text.length, extentOffset: text.length);
- if (widget.autoFocus) {
- FocusScope.of(context).requestFocus(_textNode);
- }else {
- FocusScope.of(context).requestFocus(FocusNode());
- }
- return Positioned(
- left: widget.inputLeft,
- top: widget.inputTop,
- width: widget.inputWidth,
- height: widget.inputHeight,
- child: widget.autoFocus ? TextField(
- focusNode: _textNode,
- style: widget.textSpan?.style,
- decoration: InputDecoration.collapsed(
- hintText: '',
- filled: true,
- fillColor: widget.inputFillColor), //去除边框
- controller: _controller,
- textInputAction: TextInputAction.done,
- onEditingComplete: () {
- OLogger.d('onEditing complete.....${_controller.text}');
- done();
- },
- ) : Container()
- ,
- );
- }
- @override
- void dispose() {
- _controller.dispose();
- _textNode.dispose();
- super.dispose();
- }
- void done(){
- widget.textEditDone(_controller.text);
- }
- }
|