The TextDirection docs say:
Flutter is designed to address the needs of applications written in any of the world's currently-used languages, whether they use a right-to-left or left-to-right writing direction. Flutter does not support other writing modes, such as vertical text or boustrophedon text, as these are rarely used in computer programs. (emphasis added)
Not only does Flutter not support vertical text, it won't be officially supported in the future. This was an early design decision (see here and here).
Even so, there is a real use for vertical script support today. In addition to certain Chinese and Japanese uses, the traditional Mongolian script requires it. This script is very commonly used in computer programs in Inner Mongolia (example, example, example, example, example, example).
It is written top to bottom, and lines wrap left to right:
Additionally, emoji and CJK characters retain the their orientation when displayed vertically (not absolutely necessary, but preferred). In the image below, the top paragraph shows the current implementation and the bottom paragraph shows the correct vertical rendering:
// sample text
ᠨᠢᠭᠡ ᠬᠣᠶᠠᠷ ᠭᠣᠷᠪᠠ ᠳᠥᠷᠪᠡ ᠲᠠᠪᠤ ᠵᠢᠷᠭᠤᠭᠠ ᠳᠣᠯᠣᠭᠠ ᠨᠠᠢᠮᠠ ᠶᠢᠰᠦ ᠠᠷᠪᠠ one two three four five six seven eight nine ten 😃🐐汉字 한국어 モンゴル語 English? ᠮᠣᠩᠭᠣᠯ︖
Since Flutter doesn't support vertical script, it must be implemented from scratch. All of the actual text layout and painting is done in the Flutter engine with LibTxt, so I can't change that.
What would it involve to create a top to bottom vertical Text widget?
I'm still looking for an answer. Rémi's answer is good for single line text but doesn't work for multi-line text.
I'm currently researching three different possible solutions:
All of those would involve measuring the text, laying it out, and getting an list of lines.
I'm currently leaning toward making a custom widget and render object that will mimic RichText and RenderParagraph. Under the hood RenderParagraph uses a TextPainter to layout and paint the text. My problem now is that TextPainter is tightly coupled to the underlying Skia LibTxt library. That is where all the actual layout and painting happens. Laying out the text in anything besides the default ltr and rtl is proving to be a big problem.
The accepted answer meets the criteria I put forth in this question. I think it will meet short term needs. I have some reservations for things like applying text style, but I will need to do more tests. Long term I may still try to do custom text layout and painting.
How to Write Vertical Text In Flutter? To create vertical Text in flutter flex-box layout. It converts the string to a list of words and puts them in vertically rotated Text Widgets. These are laid out with a Wrap widget set to Axis.
How to Write Vertical Text In Flutter? To create vertical Text in flutter flex-box layout. It converts the string to a list of words and puts them in vertically rotated Text Widgets. These are laid out with a Wrap widget set to Axis.vertical. So the Wrap widget automatically handles words that need to wrap by putting them in the next column.
So in this tutorial we would Set Text Widget Vertically Horizontally Center in Flutter iOS Android App Example. 1. Import material.dart package in your app’s main.dart file. 2. Create void main runApp () method and call our MyApp class here. 3. Create our main class named as MyApp extends with State less widget. 4.
We can make the text scrollable in flutter using these 2 widgets: Expanded Class: A widget that expands a child of a Row, Column, or Flex so that the child fills the available space. SingleChildScrollView Class: A box in which a single widget can be scrolled.
In flutter we cannot directly put text widget at the center of a View layout. We have to use Center widget with Center text align property of Text and combination of both of them makes our Text at middle of View. In this tutorial for full explanation i am first creating a Container View with fixed height and set border around view.
Sideway text is possible using RotatedBox
, which is enough for the text to correctly wrap as you'd expect.
Row(
children: <Widget>[
RotatedBox(
quarterTurns: 1,
child: Text(sample),
),
Expanded(child: Text(sample)),
RotatedBox(
quarterTurns: -1,
child: Text(sample),
),
],
),
Similarly, Flutter now supports inline widgets inside text. This can be used to rotate smileys inside a text.
RotatedBox(
quarterTurns: 1,
child: RichText(
text: TextSpan(
text: 'Hello World',
style: DefaultTextStyle.of(context).style,
children: [
WidgetSpan(
child: RotatedBox(quarterTurns: -1, child: Text('😃')),
)
],
),
),
),
This solution is based on a flex-box layout. It converts the string to a list of words and puts them in vertically rotated Text widgets. These are laid out with a Wrap
widget set to Axis.vertical
. The Wrap widget automatically handles words that need to wrap by putting them in the next column.
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Wrap(
direction: Axis.vertical,
children: _getWords(),
),
),
);
}
List<Widget> _getWords() {
const text =
"That's all 😉🐐 12345 One Two Three Four Five ᠸᠢᠺᠢᠫᠧᠳᠢᠶᠠ᠂ ᠴᠢᠯᠦᠭᠡᠲᠦ ᠨᠡᠪᠲᠡᠷᠬᠡᠢ ᠲᠣᠯᠢ ᠪᠢᠴᠢᠭ ᠪᠣᠯᠠᠢ᠃";
var emoji = RegExp(r"([\u2200-\u3300]|[\uD83C-\uD83E].)");
List<Widget> res = [];
var words = text.split(" ");
for (var word in words) {
var matches = emoji.allMatches(word);
if (matches.isEmpty) {
res.add(RotatedBox(quarterTurns: 1, child: Text(word + ' ')));
} else {
var parts = word.split(emoji);
int i = 0;
for (Match m in matches) {
res.add(RotatedBox(quarterTurns: 1, child: Text(parts[i++])));
res.add(Text(m.group(0)));
}
res.add(RotatedBox(quarterTurns: 1, child: Text(parts[i] + ' ')));
}
}
return res;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With