All settings of the letters above and below are the same.
However, as the contents of the letters change, the two sizes do not match each other.
Is there a way to solve this?
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(height: 9,),
Text(
' 24.07.23 16:31',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 23,
fontFamily: "Interop",
),
),
Text(
' 24.10.15 16:01',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 23,
fontFamily: "Interop",
),
),
],
),
I tried to use a code like textScaleFactor to match the font size, but I couldn’t solve it.
3
Answers
Your texts do have the same font size:
The issue here is that the individual letters have different sizes – for example a
1
takes less horizontal space than a0
.What you want to do is use the
textAlign
-property of theText()
-widget and set it tojustify
, like so:Also remove the leading whitespace from your text, as this has no impact.
This will yield a result similar to this:
For more information, see: How to justify text in a flutter column widget?
See also: https://api.flutter.dev/flutter/dart-ui/TextAlign.html
An alternative approach would be to have each element of your string as a separate
Text()
-widget with an absolute width.The screenshot you have provided contains different texts they are not same. Each letter has own width for example
M
is wider thanI
so.In normal fonts, as said in @rintu-banerjee answer, different letters has different widths and you can’t have same width for all possible texts with same character count.
You need to use monospace fonts, monospaced fonts are some type of fonts which have same width for all characters and they used in IDEs, Command lines, …
So you can find some monospaced fonts here in google fonts
You can use google fonts in flutter by these steps:
flutter pub add google_fonts
style: GoogleFonts.robotoMono()
to your text widget.Example use:
Result: