I want to vertically centre align all contents of Text.rich()
but I am not able to do that. Here you can see the red and green boxes are not centre aligned.
Below is my code.
@override
Widget build(BuildContext context) {
const textStyle = TextStyle(color: Colors.black, fontSize: 30);
final testWidgetSpan1 = WidgetSpan(alignment: PlaceholderAlignment.middle, child: Container(height: 10, width: 10, color: Colors.red,));
final testWidgetSpan2 = WidgetSpan(alignment: PlaceholderAlignment.middle, child: Container(height: 40, width: 40, color: Colors.green,));
return Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Text.rich(
TextSpan(children: <InlineSpan>[
testWidgetSpan1,
const TextSpan(text: ' ', style: textStyle),
const TextSpan(text: 'Dummy Text To test rich text in app', style: textStyle),
const TextSpan(text: ' ', style: textStyle),
testWidgetSpan2,
]),
overflow: TextOverflow.ellipsis,
maxLines: 2,
softWrap: true,
),
),
),
);
}
Note – I have to use TextSpan
as I need maxLines
and ellipsis
behaviour as well.
2
Answers
If I don’t misunderstand your meanings, you may want the effect like this img:
For this, just pass
textAlign
param to yourText.rich()
widget:Hope this will help you,