Skip to content

Instantly share code, notes, and snippets.

@imaNNeo
Created November 13, 2020 07:02
Show Gist options
  • Save imaNNeo/f143b4c0ff9b535eb64ba7ca31f04425 to your computer and use it in GitHub Desktop.
Save imaNNeo/f143b4c0ff9b535eb64ba7ca31f04425 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'dart:math' as math;
void main() {
runApp(MyApp());
}
// Degree / Radians converter
const double degrees2Radians = math.pi / 180.0;
const double radians2Degrees = 180.0 / math.pi;
double degrees(double radians) => radians * radians2Degrees;
double radians(double degrees) => degrees * degrees2Radians;
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter 4 Fun',
home: MainPage(),
);
}
}
class MainPage extends StatefulWidget {
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
double rotationY = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xffFF6958),
body: Column(
children: [
Expanded(
child: Container(
child: Center(
child: Text(
'Flutter4Fun.com',
style: TextStyle(
color: Colors.white,
),
),
),
)),
Transform(
alignment: FractionalOffset.center,
transform: Matrix4.identity()
..setEntry(3, 2, 0.01)
..rotateY(radians(rotationY)),
child: Container(
height: 180,
color: Colors.white.withOpacity(0.4),
margin: EdgeInsets.symmetric(horizontal: 40),
),
),
Expanded(child: Container()),
Text(
'${rotationY.toInt()} degrees',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
Slider(
value: rotationY,
onChanged: (value) {
setState(() {
rotationY = value;
});
},
min: 0,
max: 180,
)
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment