sam*_*ous 6 custom-painting dart flutter
我正在尝试在 Flutter 中的画布上添加一个可编辑的文本框,一旦选择就会弹出键盘。
我正在使用自定义画家将文本打印到画布上(如下面的代码所示)。是否可以使该文本可编辑,或者在画布上以特定偏移量添加文本输入元素?
import 'package:flutter/material.dart' as Material;
class CanvasPainter extends Material.ChangeNotifier implements Material.CustomPainter {
..
void paint(Canvas canvas, Size size) {
Material.TextSpan textSpan = new Material.TextSpan(style: new material.TextStyle(color: new Maaterial.Color.fromRGBO(r, g, b, 1.0), fontSize: font.fontSize.toDouble(), fontFamily: 'Roboto'),text: "Hello there");
Material.TextPainter tp = new Material.TextPainter( text: textSpan, textAlign: TextAlign.left, textDirection: TextDirection.ltr, textScaleFactor: ratio);
tp.layout();
tp.paint(canvas, new Offset(50.0,50.0));
}
}
Run Code Online (Sandbox Code Playgroud)
不是最好的解决方案,但我可以使用 OverlayEntry 解决类似的问题。
脚步: