Flutter:如何制作自定义形状的文本字段

标签 flutter textfield

我对此很陌生。我如何设计以下内容:
a) 一个自定义文本框来输入带有图标的
enter image description here
PS:使用 InputBorder 时添加问题:
enter image description here

最佳答案

最后根据建议使用以下内容:

class DMTextBoxOutlineBorder extends OutlineInputBorder {

  @override
    void paint(
      Canvas canvas,
      Rect rect, {
        double gapStart,
        double gapExtent = 0.0,
        double gapPercentage = 0.0,
        TextDirection textDirection,
      }) {

    var paint = Paint();
    paint.color = Colors.black;
    paint.strokeWidth = 1.0;

    var startXPos = rect.bottomLeft.dx;
    var startYPos = rect.bottomLeft.dy;
    var height =  rect.bottomLeft.dy - rect.topLeft.dy;
    var width = (rect.bottomRight.dx - rect.bottomLeft.dx);

    var textBox = Path();
    textBox.moveTo(startXPos, startYPos);
    textBox.lineTo(startXPos + width, startYPos);
    ......rest of the code to complete the required shape

    canvas.drawPath(textBox, paint);
  }

  bool shouldRepaint(CustomPainter oldDelegate) {
    return true;
  }
 }

关于Flutter:如何制作自定义形状的文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63526152/

相关文章:

php - 如何在 Yii 中用数据库值填充文本字段?

ios - 无法在 Swift 的 UITextFieldDelegate 类初始值设定项中使用 TextField

flutter - flutter JSON解析映射

firebase - 使用 Mockito 为 Firebase 用户身份验证设置单元测试

Flutter - 如何在 TextField 中获取光标的坐标?

android-studio - 解决Flutter错误:无法加载 Assets

当类用作值而不是字符串时, flutter 下拉失败

ios - 自定义单元格文本字段不可编辑

ruby-on-rails - 如何获取text_field Rails的值

ios - 如何调整 TextField 占位符颜色 : SwiftUI