Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How to make custom shape textfields

Am new to this. How do I design the below: a) a custom textbox to take inputs with icon

enter image description here

PS: Added issue when using InputBorder:

enter image description here

like image 534
Abhishek Lahiri Avatar asked Dec 18 '25 08:12

Abhishek Lahiri


1 Answers

Finally as per the suggestions used the below:

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;
  }
 }
like image 126
Abhishek Lahiri Avatar answered Dec 21 '25 02:12

Abhishek Lahiri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!