Is it possible to make characters in Flutter to have the same width?

泄露秘密 提交于 2019-12-22 09:40:29

问题


As you can see in the picture below, the texts have the same amount of characters, but since the number "1" is slimmer than the "5" and "2", both texts get a different width.

How can I adjust that in Flutter?


回答1:


Use a monospaced font, also called a fixed-pitch, fixed-width, or non-proportional font, is a font whose letters and characters each occupy the same amount of horizontal space.

Wikipedia explains it well. https://en.wikipedia.org/wiki/Monospaced_font




回答2:


Hiepav suggestion, seems a good approach because you are not doing nothing wrong but each character in the font have different widths so it will have to adjust to give enough room.

However, as a workaround you can actually wrap your texts in a fixed width sized box that gives enough space for both widgets regarding its character widths variations , such as SizedBox, ConstrainedBox or even Container with width constraints and center align child. This way, with that font, you should at least have the : vertically aligned.



来源:https://stackoverflow.com/questions/54935487/is-it-possible-to-make-characters-in-flutter-to-have-the-same-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!