What is RotatedBox in flutter?

Hey, what’s up, guys. In this post, we are going to learn about RotatedBox in flutter. We will see what it is and how you can use it in your flutter project.

What is RotatedBox in flutter?

RotatedBox is a widget in flutter that rotates its child in turns of 90 degrees. We define how many 90-degree turns to take by passing the quarterTurns parameter to the RoatatedBox widget. 1 quarter-turn equals 90 degrees. The rotation is clockwise. Let’s make it more clear with an example.

In the example code, I have set the quarterTurns to 3, but, to give you a clearer understanding, I have shared the screenshot with qurterTurns set to 2 and quarterTurns set to 1 as well.

import 'package:flutter/material.dart';
void main()
{
runApp(MyApp());
}
class MyApp extends StatelessWidget
{
@override
Widget build(BuildContext context)
{
return MaterialApp(
home: MyHomePage()
);
}
}
class MyHomePage extends StatelessWidget
{
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('RotatedBox Example '),
backgroundColor: Colors.purple,
),
body: Center(
child: RotatedBox(
quarterTurns: 3,
child: const Text('DeveloperXon',
style: TextStyle(fontSize: 50)),
)
),
);
}
}

In the example code above, I have set the qurterTurns to 3. So, the number of clockwise 90 degrees turns will be three i.e; our text will rotate at 270 degrees(90+90+90) clockwise.

Let’s see the output.

Setting the qurterTurns to 2 (90+90=180 degrees) will give the output like this(Screenshot below).

Setting the quraterTurns to 1 (90 degrees) will give the output like this(Screenshot below).

That’s all about the RotatedBox widget in flutter.

Goodbye.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: