Это необходимый виджет
Я пытался использовать стек. Но не получил правильного решения
Нет, я хочу создать такой виджет. В основном я застрял, я хочу расширить это подчеркивание, а также толщину до текстовой области.
Вы можете попробовать использовать границу контейнера только снизу или подчеркнуть текстовое оформление
Вы можете добиться этого, сначала вам нужно рассчитать виджет «Текст», чтобы нарисовать это синее подчеркивание с той же шириной текста, используя TextPainter и LayoutBuilder:
class TextPainterWidget extends StatelessWidget {
final TextPainter textPainter;
const TextPainterWidget({
Key? key,
required this.textPainter,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return CustomPaint(
painter: _TextPainterWidget(textPainter),
);
}
}
class _TextPainterWidget extends CustomPainter {
final TextPainter textPainter;
_TextPainterWidget(this.textPainter);
@override
void paint(Canvas canvas, Size size) {
textPainter.layout();
textPainter.paint(canvas, Offset.zero);
}
@override
bool shouldRepaint(_TextPainterWidget oldDelegate) {
return oldDelegate.textPainter.text != textPainter.text ||
oldDelegate.textPainter.text?.style != textPainter.text?.style;
}
}
Тогда ваш основной виджет должен быть таким:
LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final TextPainter textPainter = TextPainter(
text: const TextSpan(
text: 'Grab The Best Deal On ',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
children: <TextSpan>[
TextSpan(
text: 'Smartphones',
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
),
),
],
),
textDirection: TextDirection.ltr,
)..layout(maxWidth: constraints.maxWidth);
final double textWidth = textPainter.width;
return Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
TextPainterWidget(textPainter: textPainter),
Row(
children: <Widget>[
const Text('View All'),
const SizedBox(width: 8),
InkWell(
onTap: () {},
child: const Icon(
Icons.arrow_forward_ios,
size: 15,
color: Colors.blue,
),
),
],
),
],
),
Row(
children: <Widget>[
SizedBox(
width: textWidth,
child: const Divider(
color: Colors.blue,
thickness: 2,
),
),
const Expanded(
child: Divider(
color: Colors.grey,
thickness: 1,
),
),
],
),
],
);
},
),
Вот код на Zapp
Большое спасибо дорогой брат! Проблема решена
Вы имеете в виду другой цвет текста?