o7planning

Flutter RotatedBox Tutorial with Examples

  1. RotatedBox
  2. quarterTurns
  3. child

1. RotatedBox

RotatedBox is a widget that rotates its child by an integral number of quarter turns. Each quarter is an angle of 90 degrees or -90 degrees.
RotatedBox Constructor:
RotatedBox Constructor
const RotatedBox(
    {Key key,
    @required int quarterTurns,
    Widget child}
)
Below is an example using RotatedBox to rotate a Text object 90 degrees clockwise (quarterTurns = 1).
main.dart (ex1)
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'o7planning.org',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold (
        appBar: AppBar(
          title: Text("Flutter RotatedBox Example"),
        ),
        body: Center (
            child: RotatedBox (
                quarterTurns: 1,
                child: Text(
                    "Flutter RotatedBox Tutorial",
                    style: TextStyle(fontSize: 25)
                )
            )
        )
    );
  }
}
Here is another example, rotate the Text object 90 degrees counterclockwise (quarterTurns = -1).
(ex2)
RotatedBox (
    quarterTurns: -1,
    child: Text(
        "Flutter RotatedBox Tutorial",
        style: TextStyle(fontSize: 25)
    )
)
LinearProgressIndicator is a horizontal progress bar which you can use the RotatedBox to rotate 90 degrees in order to get a vertical progress bar.
(ex3)
RotatedBox(
    quarterTurns: -1,
    child: SizedBox(
        width: 250,
        height: 25,
        child : LinearProgressIndicator(
          backgroundColor: Colors.cyan[100],
          valueColor: new AlwaysStoppedAnimation<Color>(Colors.green),
        )
    )
)
  • Flutter Transform

2. quarterTurns

quarterTurns is the number of times the child widget has to be rotated 90 degrees clockwise. The value of quarterTurns can be a negative integer.
@required int quarterTurns

3. child

Widget child

Flutter Programming Tutorials

Show More