小编sam*_*ous的帖子

在画布上颤动可编辑文本

我正在尝试在 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)

custom-painting dart flutter

6
推荐指数
1
解决办法
1491
查看次数

标签 统计

custom-painting ×1

dart ×1

flutter ×1