7.4 C
New York
Monday, December 11, 2023

Flutter Vertical Text Direction: An Example

In Flutter, you can set the orientation of the text characters in a line to vertical by wrapping a Text widget inside a RotatedBox widget, like this:

RotatedBox(
              quarterTurns: 1,
              child: Text(
                'Just Some Vertical Text',
                style: TextStyle(fontSize: 50),
              ),
            ),

A Complete Example

Screenshot:Advertisements

The full code:Advertisements

// main.dart
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        // Remove the debug banner
        debugShowCheckedModeBanner: false,
        title: 'Kindacode.com',
        theme: ThemeData(
          primarySwatch: Colors.amber,
        ),
        home: HomePage());
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Kindacode.com'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(30),
        child: Row(
          children: [
            RotatedBox(
              quarterTurns: 1,
              child: Text(
                'Just Some Vertical Text',
                style: TextStyle(fontSize: 50),
              ),
            ),
            SizedBox(
              width: 30,
            ),
            RotatedBox(
              quarterTurns: 3,
              child: Text(
                'Just Some Vertical Text',
                style: TextStyle(fontSize: 50),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Continue learning Flutter:

You can also check out our Flutter category page, or Dart category page for the latest tutorials and examples.

Advertisements

Related Articles

Latest Articles