import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
// Set the app's primary theme color
primarySwatch: Colors.green,
),
debugShowCheckedModeBanner: false,
home: TransformExample(),
);
}
}
class TransformExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// AppBar with a title
title: Text('Transform Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
// Rotation
Transform.rotate(
angle: 0.785, // 0.785 radians = 45 degrees
child: Container(
width: 100,
height: 100,
color: Colors.blue, // Blue container
child: Center(
child: Text(
'Rotation', // Text label
style: TextStyle(
color: Colors.white, // Text color
fontWeight: FontWeight.bold, // Bold text
),
),
),
),
),
// Translation (Positioning)
Transform.translate(
// Move 50 pixels to the right
offset: Offset(50.0, 0.0),
child: Container(
width: 100,
height: 100,
color: Colors.red, // Red container
child: Center(
child: Text(
'Translation', // Text label
style: TextStyle(
color: Colors.white, // Text color
fontWeight: FontWeight.bold, // Bold text
),
),
),
),
),
// Scaling
Transform.scale(
scale: 1.5, // Scale to 1.5 times the default size
child: Container(
width: 100,
height: 100,
color: Colors.green, // Green container
child: Center(
child: Text(
'Scaling', // Text label
style: TextStyle(
color: Colors.white, // Text color
fontWeight: FontWeight.bold, // Bold text
),
),
),
),
),
// Skewing
Transform(
transform: Matrix4.skew(0.2, 0.0), // Apply horizontal skew
child: Container(
width: 100,
height: 100,
color: Colors.orange, // Orange container
child: Center(
child: Text(
'Skewing', // Text label
style: TextStyle(
color: Colors.white, // Text color
fontWeight: FontWeight.bold, // Bold text
),
),
),
),
),
],
),
),
);
}
}