Skip to content

Instantly share code, notes, and snippets.

@mewben
Created October 30, 2019 07:03
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mewben/f84ba2e3037f0af202d3aa2df96aa6dc to your computer and use it in GitHub Desktop.
Save mewben/f84ba2e3037f0af202d3aa2df96aa6dc to your computer and use it in GitHub Desktop.
Flutter: Rotate Icon by 90 degrees
import 'package:flutter/material.dart';
import 'dart:math';
class RotatedIcon extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Transform.rotate(
angle: 90 * pi/180,
child: Icon(Icons.flight),
);
}
}
@Karmalakas
Copy link

Karmalakas commented Feb 13, 2023

Great! What's the deal with such angle? What's the unit here in Flutter? I was expecting 90 to just work, but obviously it didn't and I ended up here 🙂

And this is the widget I ended up with:

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

class Rotate extends StatelessWidget {
  final double? angle;
  final Widget child;

  const Rotate({
    required this.child,
    this.angle = 0,
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) => Transform.rotate(
        angle: angle! * pi / 180,
        child: child,
      );
}
const Rotate(
  angle: 90,
  child: Icon(Icons.flight),
);

@diegoalex
Copy link

You can also use the RotationTransition widget.No need to import math and you only divide the angle by 360.

RotationTransition(
        turns: AlwaysStoppedAnimation(90 / 360),
        child: Icon(Icons.arrow_drop_down),
      ),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment