I want to reproduce this effect
I have tried multiple solutions :
-
A borderRadius can only be given for uniform borders -> this one doesn’t suits me because whenever you resize the widget, the area gets bigger
-
https://stackoverflow.com/a/72155716/21357698 -> this one is my last solution if there are no other solution because I would like to use native flutter without any package to do that.
-
I’ve seen that flutter have added this recently but from my understanding it only works when the color is uniform between each side which is not my case : https://github.com/flutter/flutter/pull/121921
-
I have tried to add a BoxDecoration with a border only on left side that I wanted to round but i got the following error :
A borderRadius can only be given on borders with uniform colors and styles.
Linked code :
decoration: const BoxDecoration(
border: Border(
left: BorderSide(width: 6, color: Colors.red),
),
// borderRadius: BorderRadius.all(Radius.circular(4)),
),
child: pfTextField,
- I have tried to create my custom OutlineInputBorder so that i paint what i want but it just blink each time the view is rebuilt (if you have a solution to this it will suits me)
Here is the code i’ve done for this custom OutlineInputBorder :
import 'package:flutter/material.dart';
class CustomInputBorder extends OutlineInputBorder {
final Color? leftBorderSideColor;
/// Constructeur
const CustomInputBorder ({
this.leftBorderSideColor,
super.borderRadius,
super.borderSide,
super.gapPadding,
});
@override
void paint(
Canvas canvas,
Rect rect, {
double? gapStart,
double gapExtent = 0.0,
double gapPercentage = 0.0,
TextDirection? textDirection,
}) {
RRect newRect = RRect.fromLTRBAndCorners(
rect.left,
rect.top,
rect.left + 4,
rect.bottom,
topLeft: const Radius.circular(4),
bottomLeft: const Radius.circular(4),
);
canvas.drawRRect(
newRect,
borderSide.toPaint()
..color = leftBorderSideColor ?? Colors.transparent
..style = PaintingStyle.fill,
);
super.paint(
canvas,
rect,
gapStart: gapStart,
gapExtent: gapExtent,
gapPercentage: gapPercentage,
textDirection: textDirection,
);
}
}
I feel like i’m missing something, it must be a way to do it simply. Have you an idea on how i can achieve that or on what is my error on the last solution ?
2
Answers
If you want to do this without any package, I have solution and I think you have not tried that yet!
add a prefix Icon in decoration, I have not found a icon just like that but you can use an asset icon. I’ve rotated the most similar icon to help you out
),
),
this image will the first.
second make every thing custom
this is 3rd and last most similar answer I got in my mind
if you have any question do a comment I will help you
You can combine Container and TextField in Row to get the same effect.
Here is a sample you can refer to:
Result